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