PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.4
Patchstack – WordPress & Plugins Security v2.2.4
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 +53 -27 2.1.222.2.4 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.
@@ -52,9 +52,9 @@
52 52 return;
53 53 }
54 54
55 55 // Synchronize the software list with the API.
56 - $results = $this->plugin->api->upload_software( array( 'software' => json_encode( $data ) ) );
56 + $results = $this->plugin->api->upload_software( [ 'software' => json_encode( $data ) ] );
57 57 if ( isset( $results['success'] ) ) {
58 58 update_option( 'patchstack_software_data_hash', $hash );
59 59
60 60 // The result will also contain a list of all vulnerable plugins on the site that is returned by the API.
@@ -59,13 +59,28 @@
59 59
60 60 // The result will also contain a list of all vulnerable plugins on the site that is returned by the API.
61 61 // If the auto update setting is enabled for vulnerable plugins, perform the update once the 15 minute
62 62 // scheduled task "patchstack_update_plugins" is executed.
63 - $update = get_site_option( 'patchstack_auto_update', array() );
63 + $update = get_site_option( 'patchstack_auto_update', [] );
64 64 if ( isset( $results['vulnerable'] ) && is_array( $update ) && in_array( 'vulnerable', $update ) ) {
65 65 update_site_option( 'patchstack_vulnerable_plugins', $results['vulnerable'] );
66 66 }
67 67
68 + // If we have vulnerable plugins, determine if we had them before and if not, pull latest firewall rules.
69 + if ( isset( $results['vulnerable'] ) && count( $results['vulnerable'] ) > 0 ) {
70 + $prev = get_site_option( 'patchstack_latest_vulnerable', [] );
71 + foreach ( $results['vulnerable'] as $vuln ) {
72 + if ( ! in_array ( $vuln, $prev ) ) {
73 + do_action( 'patchstack_post_dynamic_firewall_rules' );
74 + break;
75 + }
76 + }
77 +
78 + update_site_option( 'patchstack_latest_vulnerable', $results['vulnerable'] );
79 + } else {
80 + update_site_option( 'patchstack_latest_vulnerable', [] );
81 + }
82 +
68 83 return $results;
69 84 }
70 85
71 86 return;
@@ -86,9 +101,9 @@
86 101 return;
87 102 }
88 103
89 104 // Construct the array to be uploaded to our API.
90 - $logs = array();
105 + $logs = [];
91 106 foreach ( $items as $item ) {
92 107
93 108 // Entries that we don't want to store on the API side.
94 109 if ( stripos( $item->request_uri, 'wp-comments-post' ) !== false ) {
@@ -95,9 +110,9 @@
95 110 continue;
96 111 }
97 112
98 113 // Push to entries to be uploaded.
99 - $logs[] = array(
114 + $logs[] = [
100 115 'ip' => $item->ip,
101 116 'fid' => $item->fid,
102 117 'request_uri' => $item->request_uri,
103 118 'user_agent' => $item->user_agent,
@@ -103,18 +118,18 @@
103 118 'user_agent' => $item->user_agent,
104 119 'method' => $item->method,
105 120 'log_date' => $item->log_date,
106 121 'post_data' => $item->post_data,
107 - );
122 + ];
108 123 }
109 124
110 125 // JSON encode the logs and upload.
111 126 $logs = json_encode( $logs );
112 127 $results = $this->plugin->api->upload_firewall_logs(
113 - array(
128 + [
114 129 'logs' => $logs,
115 130 'type' => 'firewall',
116 - )
131 + ]
117 132 );
118 133 if ( isset( $results['errors'] ) ) {
119 134 return;
120 135 }
@@ -142,9 +157,9 @@
142 157 }
143 158
144 159 // Do we have data to upload?
145 160 $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 ) ) );
161 + $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 162 if ( $wpdb->num_rows == 0 ) {
148 163 return;
149 164 }
150 165
@@ -149,9 +164,9 @@
149 164 }
150 165
151 166 // Send to the API.
152 167 $logs = json_encode( $items );
153 - $results = $this->plugin->api->upload_activity_logs( array( 'logs' => $logs ) );
168 + $results = $this->plugin->api->upload_activity_logs( [ 'logs' => $logs ] );
154 169 if ( isset( $results['errors'] ) ) {
155 170 return;
156 171 }
157 172
@@ -187,9 +202,9 @@
187 202 // Fetch list of plugins.
188 203 $all_plugin = get_plugins();
189 204 $installed_plugins = array_keys( $all_plugin );
190 205 $updatable_plugins = get_plugin_updates();
191 - $software_list = array();
206 + $software_list = [];
192 207
193 208 foreach ( $installed_plugins as $plugin ) {
194 209 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
195 210 continue;
@@ -208,9 +223,9 @@
208 223 } else {
209 224 $active = (int) is_plugin_active( $plugin );
210 225 }
211 226
212 - $software_list[] = array(
227 + $software_list[] = [
213 228 'sw_type' => 'plugin',
214 229 'sw_name' => $plugin_name,
215 230 'sw_cur_ver' => $plugin_version,
216 231 'sw_new_ver' => $new_version,
@@ -215,9 +230,9 @@
215 230 'sw_cur_ver' => $plugin_version,
216 231 'sw_new_ver' => $new_version,
217 232 'sw_key' => $plugin,
218 233 'sw_active' => $active
219 - );
234 + ];
220 235 }
221 236 }
222 237
223 238 // Fetch list of themes.
@@ -232,15 +247,15 @@
232 247 $theme_name = $themes_data->get( 'Name' );
233 248 $theme_version = $themes_data->get( 'Version' );
234 249
235 250 if ( ! empty( $theme_name ) && ! empty( $theme_version ) ) {
236 - $software_list[] = array(
251 + $software_list[] = [
237 252 'sw_type' => 'theme',
238 253 'sw_name' => $theme_name,
239 254 'sw_cur_ver' => $theme_version,
240 255 'sw_new_ver' => $theme_new_version,
241 256 'sw_key' => $theme_key,
242 - );
257 + ];
243 258 }
244 259 }
245 260
246 261 // Fetch WordPress version.
@@ -246,22 +261,33 @@
246 261 // Fetch WordPress version.
247 262 global $wp_version;
248 263 $core_updates = get_core_updates();
249 264 $new_wp_version = ( ! empty( $core_updates ) && $core_updates[0]->response == 'upgrade' ) ? $core_updates[0]->version : '';
250 - $software_list[] = array(
265 + $software_list[] = [
251 266 'sw_type' => 'wordpress',
252 267 'sw_name' => 'WordPress',
253 268 'sw_cur_ver' => $wp_version,
254 269 'sw_new_ver' => $new_wp_version,
255 - );
270 + ];
256 271
257 272 // Fetch PHP version.
258 - $software_list[] = array(
273 + $software_list[] = [
259 274 'sw_type' => 'php',
260 275 'sw_name' => 'PHP',
261 - 'sw_cur_ver' => substr( phpversion(), 0, 5 ),
276 + 'sw_cur_ver' => phpversion(),
262 277 'sw_new_ver' => '',
263 - );
278 + ];
279 +
280 + // Fetch database server version.
281 + global $wpdb;
282 + if ( ! is_null( $wpdb ) ) {
283 + $software_list[] = [
284 + 'sw_type' => 'database',
285 + 'sw_name' => 'Database',
286 + 'sw_cur_ver' => $wpdb->get_var( 'SELECT VERSION()' ),
287 + 'sw_new_ver' => ''
288 + ];
289 + }
264 290
265 291 return $software_list;
266 292 }
267 293 }