PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.3
Patchstack – WordPress & Plugins Security v2.2.3
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
patchstack / includes / migrations / base.php

base.php in Patchstack – WordPress & Plugins Security 2.2.3, at includes/migrations/base.php

243 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not allow the file to be called directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 // Create firewall log table.
9 $sql = 'CREATE TABLE IF NOT EXISTS `' . $prefix . "patchstack_firewall_log` (
10 id mediumint(9) NOT NULL AUTO_INCREMENT,
11 ip tinytext NOT NULL,
12 flag tinytext NOT NULL,
13 fid mediumint(4),
14 request_uri tinytext,
15 user_agent tinytext,
16 method tinytext,
17 post_data LONGTEXT,
18 log_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
19 apply_ban INT NOT NULL DEFAULT '1',
20 block_type VARCHAR(255) NOT NULL DEFAULT '',
21 block_params VARCHAR(255) NOT NULL DEFAULT '',
22 PRIMARY KEY (id),
23 UNIQUE KEY id (id)
24 ) $charset_collate;";
25 dbDelta( $sql );
26
27 // Create logic table that will store the firewall rules descriptions.
28 $sql = 'CREATE TABLE IF NOT EXISTS `' . $prefix . "patchstack_logic` (
29 id mediumint(9) NOT NULL,
30 cname varchar(20),
31 description tinytext,
32 log_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
33 PRIMARY KEY (id),
34 UNIQUE KEY id (id)
35 ) $charset_collate;";
36 dbDelta( $sql );
37
38 // Create table that will store all events.
39 $sql = 'CREATE TABLE IF NOT EXISTS `' . $prefix . "patchstack_event_log` (
40 id mediumint(9) NOT NULL AUTO_INCREMENT,
41 author tinytext NULL,
42 ip tinytext NULL,
43 flag tinytext NULL,
44 object tinytext NULL,
45 object_id tinytext NULL,
46 object_name text NULL,
47 action tinytext NULL,
48 date datetime NULL,
49 PRIMARY KEY (id),
50 UNIQUE KEY id (id)
51 ) $charset_collate;";
52 dbDelta( $sql );
53
54 // Insert base firewall rules.
55 $result = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $prefix . 'patchstack_logic' );
56 if ( ! $result ) {
57 $logics = [
58 [
59 'id' => 400,
60 'cname' => 'Bad Request',
61 'description' => 'The server cannot or will not process the request due to an apparent client error',
62 ],
63 [
64 'id' => 401,
65 'cname' => 'Unauthorized',
66 'description' => 'Authentication is required and has failed or has not yet been provided.',
67 ],
68 [
69 'id' => 402,
70 'cname' => 'Invalid URL',
71 'description' => 'Payment Required. Reserved for future use.',
72 ],
73 [
74 'id' => 403,
75 'cname' => 'Forbidden',
76 'description' => 'The request was valid, but the server is refusing action.',
77 ],
78 [
79 'id' => 404,
80 'cname' => 'Not Found',
81 'description' => 'The requested resource could not be found but may be available in the future.',
82 ],
83 [
84 'id' => 405,
85 'cname' => 'Not Allowed',
86 'description' => 'A request method is not supported for the requested resource.',
87 ],
88 [
89 'id' => 410,
90 'cname' => 'Gone',
91 'description' => 'Indicates that the resource requested is no longer available and will not be available again.',
92 ],
93 [
94 'id' => 411,
95 'cname' => 'String Injection',
96 'description' => 'A request strings attack.',
97 ],
98 [
99 'id' => 501,
100 'cname' => 'Pingback',
101 'description' => 'Pingback protection.',
102 ],
103 [
104 'id' => 502,
105 'cname' => 'Unauthorized',
106 'description' => 'Blocked debug log access',
107 ],
108 [
109 'id' => 101,
110 'cname' => 'Restricted Files',
111 'description' => 'Trying to access readme file.',
112 ],
113 [
114 'id' => 102,
115 'cname' => 'Restricted Files',
116 'description' => 'Trying to access license file.',
117 ],
118 [
119 'id' => 103,
120 'cname' => 'Restricted Files',
121 'description' => 'Trying to access wp-config file.',
122 ],
123 [
124 'id' => 104,
125 'cname' => 'Restricted Files',
126 'description' => 'Trying to access robots_txt file.',
127 ],
128 [
129 'id' => 108,
130 'cname' => 'Bad Char',
131 'description' => 'Advanced character string filtered.',
132 ],
133 [
134 'id' => 109,
135 'cname' => 'Gone',
136 'description' => 'Trying to access readme files htaccess, htpasswd, errordocs or logs.',
137 ],
138 [
139 'id' => 2,
140 'cname' => 'Dir Exploit',
141 'description' => 'Blocked restricted wordpres file access.',
142 ],
143 [
144 'id' => 3,
145 'cname' => 'Dir Exploit',
146 'description' => 'Blacklist Bots detected.',
147 ],
148 [
149 'id' => 4,
150 'cname' => 'HTTP Ref Attack',
151 'description' => 'Abusive HTTP Referrer Blocking.',
152 ],
153 [
154 'id' => 5,
155 'cname' => 'Blacklist',
156 'description' => 'Known blacklist attacks.',
157 ],
158 [
159 'id' => 6,
160 'cname' => 'Trace',
161 'description' => 'Trace and track method detected.',
162 ],
163 [
164 'id' => 7,
165 'cname' => 'Proxy Commenting',
166 'description' => 'Forbid proxy comment posting.',
167 ],
168 [
169 'id' => 8,
170 'cname' => 'SQLI',
171 'description' => 'Deny bad query strings.',
172 ],
173 [
174 'id' => 10,
175 'cname' => 'SQLI',
176 'description' => 'Deny bad query strings.',
177 ],
178 [
179 'id' => 11,
180 'cname' => 'Request',
181 'description' => 'Deny bad query strings.',
182 ],
183 [
184 'id' => 12,
185 'cname' => 'Referrers',
186 'description' => 'Deny bad query strings.',
187 ],
188 [
189 'id' => 13,
190 'cname' => 'Request',
191 'description' => 'Deny bad query strings.',
192 ],
193 [
194 'id' => 16,
195 'cname' => 'RFI',
196 'description' => 'Forbid RFI.',
197 ],
198 [
199 'id' => 17,
200 'cname' => 'Spam',
201 'description' => 'Block spambot.',
202 ],
203 [
204 'id' => 18,
205 'cname' => 'Hotlinks',
206 'description' => 'Image hotlinking.',
207 ],
208 [
209 'id' => 19,
210 'cname' => 'readme',
211 'description' => 'Readme.txt Scan.',
212 ],
213 [
214 'id' => 22,
215 'cname' => 'Bots',
216 'description' => 'Deny bad bots.',
217 ],
218 [
219 'id' => 23,
220 'cname' => 'XSS',
221 'description' => 'Cross site scripting.',
222 ]
223 ];
224
225 foreach ( $logics as $logic ) {
226 $result = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM ' . $prefix . 'patchstack_logic WHERE id = %s', $logic['id'] ) );
227 if ( ! $result ) {
228 $wpdb->insert(
229 $prefix . 'patchstack_logic',
230 [
231 'id' => $logic['id'],
232 'cname' => $logic['cname'],
233 'description' => $logic['description'],
234 ]
235 );
236 }
237 }
238 }
239
240 update_option( 'patchstack_firewall_log_lastid', 0 );
241 update_option( 'patchstack_eventlog_lastid', 0 );
242 add_option( 'patchstack_db_version', $this->plugin->version );
243