PluginProbe
The WP Remote WordPress Plugin / 4.79
The WP Remote WordPress Plugin v4.79
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
← All changes | callback/request.php +49 -149 6.694.79 View file →
@@ -1,21 +1,18 @@
1 1 <?php
2 2
3 3 if (!defined('ABSPATH')) exit;
4 -if (!class_exists('WPRCallbackRequest')) :
5 - class WPRCallbackRequest {
4 +if (!class_exists('BVCallbackRequest')) :
5 + class BVCallbackRequest {
6 6 public $params;
7 7 public $method;
8 8 public $wing;
9 9 public $is_afterload;
10 - public $is_aftershutdown;
11 - public $keep_page_output;
12 10 public $is_admin_ajax;
13 11 public $is_debug;
14 12 public $account;
15 - public $settings;
13 + public $calculated_mac;
16 14 public $sig;
17 - public $sighshalgo;
18 15 public $time;
19 16 public $version;
20 17 public $is_sha1;
21 18 public $bvb64stream;
@@ -20,32 +17,18 @@
20 17 public $is_sha1;
21 18 public $bvb64stream;
22 19 public $bvb64cksize;
23 20 public $checksum;
24 - public $error = array();
25 - public $pubkey_name;
26 - public $bvprmsmac;
27 - public $bvboundry;
28 21
29 - private static $SIG_HASH_ALGO_MAP = array(
30 - '1' => OPENSSL_ALGO_SHA1,
31 - '7' => OPENSSL_ALGO_SHA256
32 - );
33 -
34 - public function __construct($account, $in_params, $settings) {
22 + public function __construct($account, $in_params) {
35 23 $this->params = array();
36 24 $this->account = $account;
37 - $this->settings = $settings;
38 25 $this->wing = $in_params['wing'];
39 26 $this->method = $in_params['bvMethod'];
40 27 $this->is_afterload = array_key_exists('afterload', $in_params);
41 - $this->is_aftershutdown = array_key_exists('aftershutdown', $in_params);
42 - $this->keep_page_output = $this->is_aftershutdown &&
43 - array_key_exists('keeppageoutput', $in_params);
44 28 $this->is_admin_ajax = array_key_exists('adajx', $in_params);
45 29 $this->is_debug = array_key_exists('bvdbg', $in_params);
46 30 $this->sig = $in_params['sig'];
47 - $this->sighshalgo = !empty($in_params['sighshalgo']) ? $in_params['sighshalgo'] : '1';
48 31 $this->time = intval($in_params['bvTime']);
49 32 $this->version = $in_params['bvVersion'];
50 33 $this->is_sha1 = array_key_exists('sha1', $in_params);
51 34 $this->bvb64stream = isset($in_params['bvb64stream']);
@@ -50,12 +33,8 @@
50 33 $this->is_sha1 = array_key_exists('sha1', $in_params);
51 34 $this->bvb64stream = isset($in_params['bvb64stream']);
52 35 $this->bvb64cksize = array_key_exists('bvb64cksize', $in_params) ? intval($in_params['bvb64cksize']) : false;
53 36 $this->checksum = array_key_exists('checksum', $in_params) ? $in_params['checksum'] : false;
54 - $this->pubkey_name = !empty($in_params['pubkeyname']) ?
55 - WPRAccount::sanitizeKey($in_params['pubkeyname']) : 'm_public';
56 - $this->bvprmsmac = !empty($in_params['bvprmsmac']) ? WPRAccount::sanitizeKey($in_params['bvprmsmac']) : "";
57 - $this->bvboundry = !empty($in_params['bvboundry']) ? $in_params['bvboundry'] : "";
58 37 }
59 38
60 39 public function isAPICall() {
61 40 return array_key_exists('apicall', $this->params);
@@ -60,25 +39,38 @@
60 39 public function isAPICall() {
61 40 return array_key_exists('apicall', $this->params);
62 41 }
63 42
64 - public function http_request($url, $body) {
65 - $body = http_build_query($body);
66 - $response = wp_remote_post($url, array(
67 - 'body' => $body,
68 - 'timeout' => 15,
69 - 'headers' => array(
70 - 'Content-Type' => 'application/x-www-form-urlencoded',
71 - ),
72 - ));
43 + public function curlRequest($url, $body) {
44 + $ch = curl_init($url);
45 + curl_setopt($ch, CURLOPT_POST, 1);
46 + curl_setopt($ch, CURLOPT_TIMEOUT, 15);
47 + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
48 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
49 + return curl_exec($ch);
50 + }
73 51
74 - if (is_wp_error($response)) {
75 - return false;
76 - }
52 + public function fileGetContentRequest($url, $body) {
53 + $options = array(
54 + 'http' => array(
55 + 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
56 + 'method' => 'POST',
57 + 'content' => http_build_query($body)
58 + )
59 + );
77 60
78 - return wp_remote_retrieve_body($response);
61 + $context = stream_context_create($options);
62 + return file_get_contents($url, false, $context);
79 63 }
80 64
65 + public function http_request($url, $body) {
66 + if (in_array('curl', get_loaded_extensions())) {
67 + return $this->curlRequest($url, $body);
68 + } else {
69 + return $this->fileGetContentRequest($url, $body);
70 + }
71 + }
72 +
81 73 public function get_params_via_api($params_key, $apiurl) {
82 74 $res = $this->http_request($apiurl, array('bvkey' => $params_key));
83 75
84 76 if ($res === FALSE) {
@@ -91,10 +83,9 @@
91 83 public function info() {
92 84 $info = array(
93 85 "requestedsig" => $this->sig,
94 86 "requestedtime" => $this->time,
95 - "requestedversion" => $this->version,
96 - "error" => $this->error
87 + "requestedversion" => $this->version
97 88 );
98 89 if ($this->is_debug) {
99 90 $info["inreq"] = $this->params;
100 91 }
@@ -103,14 +94,11 @@
103 94 }
104 95 if ($this->is_afterload) {
105 96 $info["afterload"] = true;
106 97 }
107 - if ($this->is_aftershutdown) {
108 - $info["aftershutdown"] = true;
98 + if ($this->calculated_mac) {
99 + $info["calculated_mac"] = $this->calculated_mac;
109 100 }
110 - if ($this->keep_page_output) {
111 - $info["keeppageoutput"] = true;
112 - }
113 101 return $info;
114 102 }
115 103
116 104 public function processParams($in_params) {
@@ -139,17 +127,22 @@
139 127 $in_params["bvprms"] = $pdata;
140 128 }
141 129 }
142 130
143 - if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
144 - if (!empty($in_params['bvprmshshalgo']) && $in_params['bvprmshshalgo'] === 'sha256') {
145 - $calculated_mac = hash_hmac('SHA256', $in_params['bvprms'], $this->account->secret);
146 - } else {
147 - $calculated_mac = hash_hmac('SHA1', $in_params['bvprms'], $this->account->secret);
131 + if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms']) &&
132 + array_key_exists('bvprmsmac', $in_params) && isset($in_params['bvprmsmac'])) {
133 + $digest_algo = 'SHA1';
134 + $sent_mac = WPRAccount::sanitizeKey($in_params['bvprmsmac']);
135 +
136 + if (array_key_exists('bvprmshshalgo', $in_params) && isset($in_params['bvprmshshalgo'])) {
137 + $digest_algo = $in_params['bvprmshshalgo'];
148 138 }
149 139
150 - if ($this->compare_mac($this->bvprmsmac, $calculated_mac) === true) {
140 + $calculated_mac = hash_hmac($digest_algo, $in_params['bvprms'], $this->account->secret);
141 + $this->calculated_mac = substr($calculated_mac, 0, 6);
151 142
143 + if ($this->compare_mac($sent_mac, $calculated_mac) === true) {
144 +
152 145 if (array_key_exists('b64', $in_params)) {
153 146 foreach ($in_params['b64'] as $key) {
154 147 if (is_array($in_params[$key])) {
155 148 $in_params[$key] = array_map('base64_decode', $in_params[$key]);
@@ -166,9 +159,9 @@
166 159 }
167 160
168 161 if (array_key_exists('sersafe', $in_params)) {
169 162 $key = $in_params['sersafe'];
170 - $in_params[$key] = WPRCallbackRequest::serialization_safe_decode($in_params[$key]);
163 + $in_params[$key] = BVCallbackRequest::serialization_safe_decode($in_params[$key]);
171 164 }
172 165
173 166 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
174 167 $params = $in_params['bvprms'];
@@ -187,10 +180,9 @@
187 180 }
188 181 }
189 182
190 183 if (array_key_exists('memset', $in_params)) {
191 - $val = intval($in_params['memset']);
192 - // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Required for memory limit adjustment
184 + $val = intval(urldecode($in_params['memset']));
193 185 @ini_set('memory_limit', $val.'M');
194 186 }
195 187
196 188 return $params;
@@ -195,8 +187,9 @@
195 187
196 188 return $params;
197 189 }
198 190 }
191 +
199 192 return false;
200 193 }
201 194
202 195 private function compare_mac($l_hash, $r_hash) {
@@ -216,9 +209,9 @@
216 209 }
217 210
218 211 public static function serialization_safe_decode($data) {
219 212 if (is_array($data)) {
220 - $data = array_map(array('WPRCallbackRequest', 'serialization_safe_decode'), $data);
213 + $data = array_map(array('BVCallbackRequest', 'serialization_safe_decode'), $data);
221 214 } elseif (is_string($data)) {
222 215 $data = base64_decode($data);
223 216 }
224 217
@@ -223,99 +216,6 @@
223 216 }
224 217
225 218 return $data;
226 219 }
227 -
228 - public function authenticate() {
229 - if (!$this->account) {
230 - $this->error["message"] = "ACCOUNT_NOT_FOUND";
231 - return false;
232 - }
233 -
234 - $bv_last_recv_time = $this->settings->getOption('bvLastRecvTime');
235 - if ($this->time < intval($bv_last_recv_time) - 300) {
236 - return false;
237 - }
238 -
239 - $data = $this->method.$this->account->secret.$this->time.$this->version.$this->bvprmsmac;
240 - if (!$this->verify($data, base64_decode($this->sig), $this->sighshalgo)) {
241 - return false;
242 - }
243 - $this->settings->updateOption('bvLastRecvTime', $this->time);
244 -
245 - return 1;
246 - }
247 -
248 - public function verify($data, $sig, $sighshalgo) {
249 - if (!function_exists('openssl_verify') || !function_exists('openssl_pkey_get_public')) {
250 - $this->error["message"] = "OPENSSL_FUNCS_NOT_FOUND";
251 - return false;
252 - }
253 -
254 - $openssl_algo = array_key_exists($sighshalgo, self::$SIG_HASH_ALGO_MAP) ? self::$SIG_HASH_ALGO_MAP[$sighshalgo] : null;
255 - if ($openssl_algo === null) {
256 - $this->error["message"] = "UNSUPPORTED_HASH_ALGORITHM: " . $sighshalgo;
257 - return false;
258 - }
259 -
260 - $key_file = dirname( __DIR__ ) . '/public_keys/' . $this->pubkey_name . '.pub';
261 - if (!file_exists($key_file)) {
262 - $this->error["message"] = "PUBLIC_KEY_NOT_FOUND";
263 - return false;
264 - }
265 -
266 - $public_key_str = WPRWPFileSystem::getInstance()->getContents($key_file);
267 -
268 - $public_key = openssl_pkey_get_public($public_key_str);
269 - if (!$public_key) {
270 - $this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY";
271 - return false;
272 - }
273 -
274 - $verify = openssl_verify($data, $sig, $public_key, $openssl_algo);
275 - if ($verify === 1) {
276 - return true;
277 - } elseif ($verify === 0) {
278 - $this->error["message"] = "INCORRECT_SIGNATURE";
279 - $this->error["pubkey_sig"] = substr(hash('md5', $public_key_str), 0, 8);
280 - } else {
281 - $this->error["message"] = "OPENSSL_VERIFY_FAILED";
282 - }
283 - return false;
284 - }
285 -
286 - public function corruptedParamsResp() {
287 - $bvinfo = new WPRInfo($this->settings);
288 -
289 - return array(
290 - "account_info" => $this->account->info(),
291 - "request_info" => $this->info(),
292 - "bvinfo" => $bvinfo->info(),
293 - "statusmsg" => "BVPRMS_CORRUPTED"
294 - );
295 - }
296 -
297 - public function authFailedResp() {
298 - $api_public_key = WPRAccount::getApiPublicKey($this->settings);
299 - $default_account_pubkey = WPRAccount::getDefaultPublicKey();
300 - $bvinfo = new WPRInfo($this->settings);
301 - $resp = array(
302 - "request_info" => $this->info(),
303 - "bvinfo" => $bvinfo->info(),
304 - "statusmsg" => "FAILED_AUTH",
305 - "api_pubkey" => substr($api_public_key, 0, 8)
306 - );
307 -
308 - if (is_string($default_account_pubkey) && strlen($default_account_pubkey) >= 32) {
309 - $resp["default_account_pubkey"] = substr($default_account_pubkey, 0, 8);
310 - }
311 -
312 - if ($this->account) {
313 - $resp["account_info"] = $this->account->info();
314 - } else {
315 - $resp["account_info"] = array("error" => "ACCOUNT_NOT_FOUND");
316 - }
317 -
318 - return $resp;
319 - }
320 220 }
321 -endif;
221 +endif;