PluginProbe
The WP Remote WordPress Plugin / 5.16
The WP Remote WordPress Plugin v5.16
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
wpremote / callback / request.php

request.php in The WP Remote WordPress Plugin 5.16, at callback/request.php

277 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVCallbackRequest')) :
5 class BVCallbackRequest {
6 public $params;
7 public $method;
8 public $wing;
9 public $is_afterload;
10 public $is_admin_ajax;
11 public $is_debug;
12 public $account;
13 public $settings;
14 public $sig;
15 public $time;
16 public $version;
17 public $is_sha1;
18 public $bvb64stream;
19 public $bvb64cksize;
20 public $checksum;
21 public $error = array();
22
23 public function __construct($account, $in_params, $settings) {
24 $this->params = array();
25 $this->account = $account;
26 $this->settings = $settings;
27 $this->wing = $in_params['wing'];
28 $this->method = $in_params['bvMethod'];
29 $this->is_afterload = array_key_exists('afterload', $in_params);
30 $this->is_admin_ajax = array_key_exists('adajx', $in_params);
31 $this->is_debug = array_key_exists('bvdbg', $in_params);
32 $this->sig = $in_params['sig'];
33 $this->time = intval($in_params['bvTime']);
34 $this->version = $in_params['bvVersion'];
35 $this->is_sha1 = array_key_exists('sha1', $in_params);
36 $this->bvb64stream = isset($in_params['bvb64stream']);
37 $this->bvb64cksize = array_key_exists('bvb64cksize', $in_params) ? intval($in_params['bvb64cksize']) : false;
38 $this->checksum = array_key_exists('checksum', $in_params) ? $in_params['checksum'] : false;
39 }
40
41 public function isAPICall() {
42 return array_key_exists('apicall', $this->params);
43 }
44
45 public function curlRequest($url, $body) {
46 $ch = curl_init($url);
47 curl_setopt($ch, CURLOPT_POST, 1);
48 curl_setopt($ch, CURLOPT_TIMEOUT, 15);
49 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
50 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
51 return curl_exec($ch);
52 }
53
54 public function fileGetContentRequest($url, $body) {
55 $options = array(
56 'http' => array(
57 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
58 'method' => 'POST',
59 'content' => http_build_query($body)
60 )
61 );
62
63 $context = stream_context_create($options);
64 return file_get_contents($url, false, $context);
65 }
66
67 public function http_request($url, $body) {
68 if (in_array('curl', get_loaded_extensions())) {
69 return $this->curlRequest($url, $body);
70 } else {
71 return $this->fileGetContentRequest($url, $body);
72 }
73 }
74
75 public function get_params_via_api($params_key, $apiurl) {
76 $res = $this->http_request($apiurl, array('bvkey' => $params_key));
77
78 if ($res === FALSE) {
79 return false;
80 }
81
82 return $res;
83 }
84
85 public function info() {
86 $info = array(
87 "requestedsig" => $this->sig,
88 "requestedtime" => $this->time,
89 "requestedversion" => $this->version,
90 "error" => $this->error
91 );
92 if ($this->is_debug) {
93 $info["inreq"] = $this->params;
94 }
95 if ($this->is_admin_ajax) {
96 $info["adajx"] = true;
97 }
98 if ($this->is_afterload) {
99 $info["afterload"] = true;
100 }
101 return $info;
102 }
103
104 public function processParams($in_params) {
105 $params = array();
106
107 if (array_key_exists('obend', $in_params) && function_exists('ob_end_clean'))
108 @ob_end_clean();
109
110 if (array_key_exists('op_reset', $in_params) && function_exists('output_reset_rewrite_vars'))
111 @output_reset_rewrite_vars();
112
113 if (array_key_exists('concat', $in_params)) {
114 foreach ($in_params['concat'] as $key) {
115 $concated = '';
116 $count = intval($in_params[$key]);
117 for ($i = 1; $i <= $count; $i++) {
118 $concated .= $in_params[$key."_bv_".$i];
119 }
120 $in_params[$key] = $concated;
121 }
122 }
123
124 if (isset($in_params['bvpdataviaapi']) && isset($in_params['bvapiurl'])) {
125 $pdata = $this->get_params_via_api($in_params['bvpdataviaapi'], $in_params['bvapiurl']);
126 if ($pdata !== false) {
127 $in_params["bvprms"] = $pdata;
128 }
129 }
130
131 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms']) &&
132 array_key_exists('bvprmsmac', $in_params) && isset($in_params['bvprmsmac'])) {
133
134 if ($this->verify($in_params['bvprms'], base64_decode($in_params['bvprmsmac'])) === true) {
135
136 if (array_key_exists('b64', $in_params)) {
137 foreach ($in_params['b64'] as $key) {
138 if (is_array($in_params[$key])) {
139 $in_params[$key] = array_map('base64_decode', $in_params[$key]);
140 } else {
141 $in_params[$key] = base64_decode($in_params[$key]);
142 }
143 }
144 }
145
146 if (array_key_exists('unser', $in_params)) {
147 foreach ($in_params['unser'] as $key) {
148 $in_params[$key] = json_decode($in_params[$key], TRUE);
149 }
150 }
151
152 if (array_key_exists('sersafe', $in_params)) {
153 $key = $in_params['sersafe'];
154 $in_params[$key] = BVCallbackRequest::serialization_safe_decode($in_params[$key]);
155 }
156
157 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
158 $params = $in_params['bvprms'];
159 }
160
161 if (array_key_exists('clacts', $in_params)) {
162 foreach ($in_params['clacts'] as $action) {
163 remove_all_actions($action);
164 }
165 }
166
167 if (array_key_exists('clallacts', $in_params)) {
168 global $wp_filter;
169 foreach ( $wp_filter as $filter => $val ){
170 remove_all_actions($filter);
171 }
172 }
173
174 if (array_key_exists('memset', $in_params)) {
175 $val = intval($in_params['memset']);
176 @ini_set('memory_limit', $val.'M');
177 }
178
179 return $params;
180 }
181 }
182
183 return false;
184 }
185
186 public static function serialization_safe_decode($data) {
187 if (is_array($data)) {
188 $data = array_map(array('BVCallbackRequest', 'serialization_safe_decode'), $data);
189 } elseif (is_string($data)) {
190 $data = base64_decode($data);
191 }
192
193 return $data;
194 }
195
196 public function authenticate() {
197 if (!$this->account) {
198 array_push($this->error, "ACCOUNT_NOT_FOUND");
199 return false;
200 }
201
202 $bv_last_recv_time = $this->settings->getOption('bvLastRecvTime');
203 if ($this->time < intval($bv_last_recv_time) - 300) {
204 return false;
205 }
206
207 $data = $this->method.$this->account->secret.$this->time.$this->version;
208 if (!$this->verify($data, base64_decode($this->sig))) {
209 return false;
210 }
211 $this->settings->updateOption('bvLastRecvTime', $this->time);
212
213 return 1;
214 }
215
216 public function verify($data, $sig) {
217 if (!function_exists('openssl_verify')) {
218 array_push($this->error, "OPENSSL_VERIFY_FUNC_NOT_FOUND");
219 return false;
220 }
221
222 $key_file = dirname( __FILE__ ) . '/../public_keys/m_public.pub';
223 if (!file_exists($key_file)) {
224 array_push($this->error, "PUBLIC_KEY_NOT_FOUND");
225 return false;
226 }
227 $public_key = file_get_contents($key_file);
228 if (!$public_key) {
229 array_push($this->error, "UNABLE_TO_LOAD_PUBLIC_KEY");
230 return false;
231 }
232
233 $verify = openssl_verify($data, $sig, $public_key);
234 if ($verify === 1) {
235 return true;
236 } elseif ($verify === 0) {
237 array_push($this->error, "INCORRECT_SIGNATURE");
238 } else {
239 array_push($this->error, "OPENSSL_VERIFY_FAILED");
240 }
241 return false;
242 }
243
244 public function corruptedParamsResp() {
245 $bvinfo = new WPRInfo($this->settings);
246
247 return array(
248 "account_info" => $this->account->info(),
249 "request_info" => $this->info(),
250 "bvinfo" => $bvinfo->info(),
251 "statusmsg" => "BVPRMS_CORRUPTED"
252 );
253 }
254
255 public function authFailedResp() {
256 $api_public_key = WPRAccount::getApiPublicKey($this->settings);
257 $default_secret = WPRRecover::getDefaultSecret($this->settings);
258 $bvinfo = new WPRInfo($this->settings);
259 $resp = array(
260 "request_info" => $this->info(),
261 "bvinfo" => $bvinfo->info(),
262 "statusmsg" => "FAILED_AUTH",
263 "api_pubkey" => substr($api_public_key, 0, 8),
264 "def_sigmatch" => substr(hash('sha1', $this->method.$default_secret.$this->time.$this->version), 0, 8)
265 );
266
267 if ($this->account) {
268 $resp["account_info"] = $this->account->info();
269 $resp["sigmatch"] = substr(hash('sha1', $this->method.$this->account->secret.$this->time.$this->version), 0, 6);
270 } else {
271 $resp["account_info"] = array("error" => "ACCOUNT_NOT_FOUND");
272 }
273
274 return $resp;
275 }
276 }
277 endif;