PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.7
Patchstack – WordPress & Plugins Security v2.2.7
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/upload.php +55 -27 2.1.212.2.7 View file →
@@ -25,18 +25,18 @@
25 25 $this->upload_software();
26 26 }
27 27
28 28 // Register the actions.
29 - add_action( 'patchstack_send_software_data', array( $this, 'upload_software' ) );
30 - add_action( 'patchstack_send_hacker_logs', array( $this, 'upload_firewall_logs' ) );
31 - add_action( 'patchstack_send_event_logs', array( $this, 'upload_activity_logs' ) );
29 + add_action( 'patchstack_send_software_data', [ $this, 'upload_software' ] );
30 + add_action( 'patchstack_send_hacker_logs', [ $this, 'upload_firewall_logs' ] );
31 + add_action( 'patchstack_send_event_logs', [ $this, 'upload_activity_logs' ] );
32 32
33 33 // In case a plugin or upgrade has been performed, re-synchronize with the app.
34 - add_action( 'activated_plugin', array( $this, 'upload_software' ) );
35 - add_action( 'deactivated_plugin', array( $this, 'upload_software' ) );
36 - add_action( 'deleted_plugin', array( $this, 'upload_software' ) );
37 - add_action( 'upgrader_process_complete', array( $this, 'upload_software' ) );
38 - add_action( '_core_updated_successfully', array( &$this, 'upload_software' ) );
34 + add_action( 'activated_plugin', [ $this, 'upload_software' ] );
35 + add_action( 'deactivated_plugin', [ $this, 'upload_software' ] );
36 + add_action( 'deleted_plugin', [ $this, 'upload_software' ] );
37 + add_action( 'upgrader_process_complete', [ $this, 'upload_software' ] );
38 + add_action( '_core_updated_successfully', [ &$this, 'upload_software' ] );
39 39 }
40 40
41 41 /**
42 42 * Synchronize the software data with our API.
@@ -47,14 +47,16 @@
47 47 public function upload_software() {
48 48 // Get the software data and hash.
49 49 $data = $this->get_software_data();
50 50 $hash = sha1( json_encode( $data ) );
51 +
52 + // Do not sync for no reason.
51 53 if ( ! defined( 'DOING_CRON' ) && ! isset( $_POST['webarx_secret'] ) && get_option( 'patchstack_software_data_hash', false ) === $hash && ! is_admin() ) {
52 54 return;
53 55 }
54 56
55 57 // Synchronize the software list with the API.
56 - $results = $this->plugin->api->upload_software( array( 'software' => json_encode( $data ) ) );
58 + $results = $this->plugin->api->upload_software( [ 'software' => json_encode( $data ) ] );
57 59 if ( isset( $results['success'] ) ) {
58 60 update_option( 'patchstack_software_data_hash', $hash );
59 61
60 62 // The result will also contain a list of all vulnerable plugins on the site that is returned by the API.
@@ -59,13 +61,28 @@
59 61
60 62 // The result will also contain a list of all vulnerable plugins on the site that is returned by the API.
61 63 // If the auto update setting is enabled for vulnerable plugins, perform the update once the 15 minute
62 64 // scheduled task "patchstack_update_plugins" is executed.
63 - $update = get_site_option( 'patchstack_auto_update', array() );
65 + $update = get_site_option( 'patchstack_auto_update', [] );
64 66 if ( isset( $results['vulnerable'] ) && is_array( $update ) && in_array( 'vulnerable', $update ) ) {
65 67 update_site_option( 'patchstack_vulnerable_plugins', $results['vulnerable'] );
66 68 }
67 69
70 + // If we have vulnerable plugins, determine if we had them before and if not, pull latest firewall rules.
71 + if ( isset( $results['vulnerable'] ) && count( $results['vulnerable'] ) > 0 ) {
72 + $prev = get_site_option( 'patchstack_latest_vulnerable', [] );
73 + foreach ( $results['vulnerable'] as $vuln ) {
74 + if ( ! in_array ( $vuln, $prev ) ) {
75 + do_action( 'patchstack_post_dynamic_firewall_rules' );
76 + break;
77 + }
78 + }
79 +
80 + update_site_option( 'patchstack_latest_vulnerable', $results['vulnerable'] );
81 + } else {
82 + update_site_option( 'patchstack_latest_vulnerable', [] );
83 + }
84 +
68 85 return $results;
69 86 }
70 87
71 88 return;
@@ -86,9 +103,9 @@
86 103 return;
87 104 }
88 105
89 106 // Construct the array to be uploaded to our API.
90 - $logs = array();
107 + $logs = [];
91 108 foreach ( $items as $item ) {
92 109
93 110 // Entries that we don't want to store on the API side.
94 111 if ( stripos( $item->request_uri, 'wp-comments-post' ) !== false ) {
@@ -95,9 +112,9 @@
95 112 continue;
96 113 }
97 114
98 115 // Push to entries to be uploaded.
99 - $logs[] = array(
116 + $logs[] = [
100 117 'ip' => $item->ip,
101 118 'fid' => $item->fid,
102 119 'request_uri' => $item->request_uri,
103 120 'user_agent' => $item->user_agent,
@@ -103,18 +120,18 @@
103 120 'user_agent' => $item->user_agent,
104 121 'method' => $item->method,
105 122 'log_date' => $item->log_date,
106 123 'post_data' => $item->post_data,
107 - );
124 + ];
108 125 }
109 126
110 127 // JSON encode the logs and upload.
111 128 $logs = json_encode( $logs );
112 129 $results = $this->plugin->api->upload_firewall_logs(
113 - array(
130 + [
114 131 'logs' => $logs,
115 132 'type' => 'firewall',
116 - )
133 + ]
117 134 );
118 135 if ( isset( $results['errors'] ) ) {
119 136 return;
120 137 }
@@ -142,9 +159,9 @@
142 159 }
143 160
144 161 // Do we have data to upload?
145 162 $lastid = get_option( 'patchstack_eventlog_lastid', 0 );
146 - $items = $wpdb->get_results( $wpdb->prepare( 'SELECT author, ip, object, object_id, object_name, action, date FROM ' . $wpdb->prefix . 'patchstack_event_log WHERE id > %d' . $where . 'ORDER BY id', array( $lastid ) ) );
163 + $items = $wpdb->get_results( $wpdb->prepare( 'SELECT author, ip, object, object_id, object_name, action, date FROM ' . $wpdb->prefix . 'patchstack_event_log WHERE id > %d' . $where . 'ORDER BY id', [ $lastid ] ) );
147 164 if ( $wpdb->num_rows == 0 ) {
148 165 return;
149 166 }
150 167
@@ -149,9 +166,9 @@
149 166 }
150 167
151 168 // Send to the API.
152 169 $logs = json_encode( $items );
153 - $results = $this->plugin->api->upload_activity_logs( array( 'logs' => $logs ) );
170 + $results = $this->plugin->api->upload_activity_logs( [ 'logs' => $logs ] );
154 171 if ( isset( $results['errors'] ) ) {
155 172 return;
156 173 }
157 174
@@ -187,9 +204,9 @@
187 204 // Fetch list of plugins.
188 205 $all_plugin = get_plugins();
189 206 $installed_plugins = array_keys( $all_plugin );
190 207 $updatable_plugins = get_plugin_updates();
191 - $software_list = array();
208 + $software_list = [];
192 209
193 210 foreach ( $installed_plugins as $plugin ) {
194 211 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
195 212 continue;
@@ -208,9 +225,9 @@
208 225 } else {
209 226 $active = (int) is_plugin_active( $plugin );
210 227 }
211 228
212 - $software_list[] = array(
229 + $software_list[] = [
213 230 'sw_type' => 'plugin',
214 231 'sw_name' => $plugin_name,
215 232 'sw_cur_ver' => $plugin_version,
216 233 'sw_new_ver' => $new_version,
@@ -215,9 +232,9 @@
215 232 'sw_cur_ver' => $plugin_version,
216 233 'sw_new_ver' => $new_version,
217 234 'sw_key' => $plugin,
218 235 'sw_active' => $active
219 - );
236 + ];
220 237 }
221 238 }
222 239
223 240 // Fetch list of themes.
@@ -232,15 +249,15 @@
232 249 $theme_name = $themes_data->get( 'Name' );
233 250 $theme_version = $themes_data->get( 'Version' );
234 251
235 252 if ( ! empty( $theme_name ) && ! empty( $theme_version ) ) {
236 - $software_list[] = array(
253 + $software_list[] = [
237 254 'sw_type' => 'theme',
238 255 'sw_name' => $theme_name,
239 256 'sw_cur_ver' => $theme_version,
240 257 'sw_new_ver' => $theme_new_version,
241 258 'sw_key' => $theme_key,
242 - );
259 + ];
243 260 }
244 261 }
245 262
246 263 // Fetch WordPress version.
@@ -246,22 +263,33 @@
246 263 // Fetch WordPress version.
247 264 global $wp_version;
248 265 $core_updates = get_core_updates();
249 266 $new_wp_version = ( ! empty( $core_updates ) && $core_updates[0]->response == 'upgrade' ) ? $core_updates[0]->version : '';
250 - $software_list[] = array(
267 + $software_list[] = [
251 268 'sw_type' => 'wordpress',
252 269 'sw_name' => 'WordPress',
253 270 'sw_cur_ver' => $wp_version,
254 271 'sw_new_ver' => $new_wp_version,
255 - );
272 + ];
256 273
257 274 // Fetch PHP version.
258 - $software_list[] = array(
275 + $software_list[] = [
259 276 'sw_type' => 'php',
260 277 'sw_name' => 'PHP',
261 - 'sw_cur_ver' => substr( phpversion(), 0, 5 ),
278 + 'sw_cur_ver' => phpversion(),
262 279 'sw_new_ver' => '',
263 - );
280 + ];
281 +
282 + // Fetch database server version.
283 + global $wpdb;
284 + if ( ! is_null( $wpdb ) ) {
285 + $software_list[] = [
286 + 'sw_type' => 'database',
287 + 'sw_name' => 'Database',
288 + 'sw_cur_ver' => $wpdb->get_var( 'SELECT VERSION()' ),
289 + 'sw_new_ver' => ''
290 + ];
291 + }
264 292
265 293 return $software_list;
266 294 }
267 295 }