PluginProbe ʕ •ᴥ•ʔ
Wordfence Security – Firewall, Malware Scan, and Login Security / 2.0.6
Wordfence Security – Firewall, Malware Scan, and Login Security v2.0.6
8.2.2 8.2.1 8.2.0 3.7.1 3.7.2 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.9.1 4.0.1 4.0.2 4.0.3 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.1 5.1.2 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.1 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.1 5.3.10 5.3.11 5.3.12 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.3.8 5.3.9 6.0.1 6.0.10 6.0.11 6.0.12 6.0.14 6.0.15 6.0.16 6.0.17 6.0.18 6.0.19 6.0.2 6.0.20 6.0.21 6.0.22 6.0.23 6.0.24 6.0.25 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.1 6.1.10 6.1.11 6.1.12 6.1.14 6.1.15 6.1.16 6.1.17 6.1.2 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.1.9 6.2.0 6.2.1 6.2.10 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.2.8 6.2.9 6.3.0 6.3.1 6.3.10 6.3.11 6.3.12 6.3.14 6.3.15 6.3.16 6.3.17 6.3.18 6.3.19 6.3.2 6.3.20 6.3.21 6.3.22 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.3.8 6.3.9 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.14 7.1.15 7.1.16 7.1.17 7.1.18 7.1.19 7.1.2 7.1.20 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.10.0 7.10.1 7.10.2 7.10.3 7.10.4 7.10.5 7.10.6 7.10.7 7.11.0 7.11.1 7.11.2 7.11.3 7.11.4 7.11.5 7.11.6 7.11.7 7.2.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.4.0 7.4.1 7.4.10 7.4.11 7.4.12 7.4.14 7.4.2 7.4.3 trunk 7.4.4 1.1 7.4.5 1.2 7.4.6 1.3 7.4.7 1.3.1 7.4.8 1.3.2 7.4.9 1.3.3 7.5.0 1.4.2 7.5.1 1.4.3 7.5.10 1.4.4 7.5.11 1.4.5 7.5.2 1.4.6 7.5.3 1.4.7 7.5.4 1.4.8 7.5.5 1.5.1 7.5.6 1.5.2 7.5.7 1.5.3 7.5.8 1.5.4 7.5.9 1.5.5 7.6.0 1.5.6 7.6.1 2.0.1 7.6.2 2.0.2 7.7.0 2.0.3 7.7.1 2.0.5 7.8.0 2.0.6 7.8.1 2.0.7 7.8.2 2.1.0 7.9.0 2.1.1 7.9.1 2.1.2 7.9.2 2.1.3 7.9.3 2.1.4 8.0.0 2.1.5 8.0.1 3.0.2 8.0.2 3.0.3 8.0.3 3.0.4 8.0.4 3.0.5 8.0.5 3.0.6 8.1.0 3.0.7 8.1.1 3.0.8 8.1.2 3.0.9 8.1.3 3.1.0 8.1.4 3.1.1 v1.4.1 3.1.2 3.1.4 3.1.6 3.2.1 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.1 3.4.4 3.4.5 3.5.1 3.5.2 3.6.1 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9
wordfence / lib / wordfenceURLHoover.php
wordfence / lib Last commit date
Diff 14 years ago .htaccess 14 years ago Diff.php 14 years ago IPTraf.php 14 years ago diffResult.php 14 years ago dropAll.php 14 years ago email_genericAlert.php 14 years ago email_newIssues.php 14 years ago email_unlockRequest.php 14 years ago menu_activity.php 14 years ago menu_blockedIPs.php 14 years ago menu_config.php 14 years ago menu_options.php 14 years ago menu_scan.php 14 years ago sysinfo.php 14 years ago viewFullActivityLog.php 14 years ago wf503.php 14 years ago wfAPI.php 14 years ago wfAction.php 14 years ago wfBrowscap.php 14 years ago wfBrowscapCache.php 14 years ago wfConfig.php 14 years ago wfCrawl.php 14 years ago wfDB.php 14 years ago wfDict.php 14 years ago wfIssues.php 14 years ago wfLockedOut.php 14 years ago wfLog.php 14 years ago wfModTracker.php 14 years ago wfRate.php 14 years ago wfScanEngine.php 14 years ago wfSchema.php 14 years ago wfUnlockMsg.php 14 years ago wfUtils.php 14 years ago wfViewResult.php 14 years ago wordfenceClass.php 14 years ago wordfenceConstants.php 14 years ago wordfenceHash.php 14 years ago wordfenceScanner.php 14 years ago wordfenceURLHoover.php 14 years ago
wordfenceURLHoover.php
179 lines
1 <?php
2 require_once('wfAPI.php');
3 class wordfenceURLHoover {
4 private $debug = false;
5 private $URLsByID = array();
6 public $errorMsg = false;
7 private $hostKeyCache = array();
8 private $api = false;
9 private $table = '';
10 private $dRegex = 'aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw|xn--lgbbat1ad8j|xn--fiqs8s|xn--fiqz9s|xn--wgbh1c|xn--j6w193g|xn--h2brj9c|xn--mgbbh1a71e|xn--fpcrj9c3d|xn--gecrj9c|xn--s9brj9c|xn--xkc2dl3a5ee0h|xn--45brj9c|xn--mgba3a4f16a|xn--mgbayh7gpa|xn--mgbc0a9azcg|xn--ygbi2ammx|xn--wgbl6a|xn--p1ai|xn--mgberp4a5d4ar|xn--90a3ac|xn--yfro4i67o|xn--clchc0ea0b2g2a9gcd|xn--3e0b707e|xn--fzc2c9e2c|xn--xkc2al3hye2a|xn--mgbtf8fl|xn--kprw13d|xn--kpry57d|xn--o3cw4h|xn--pgbs0dh|xn--mgbaam7a8h|xn--54b7fta0cc|xn--90ae|xn--node|xn--4dbrk0ce|xn--80ao21a|xn--mgb9awbf|xn--mgbai9azgqp6j|xn--j1amh|xn--mgb2ddes|xn--kgbechtv|xn--hgbk6aj7f53bba|xn--0zwm56d|xn--g6w251d|xn--80akhbyknj4f|xn--11b5bs3a9aj6g|xn--jxalpdlp|xn--9t4b11yi5a|xn--deba0ad|xn--zckzah|xn--hlcj6aya9esc7a';
11 public function __construct($apiKey, $wordpressVersion){
12 $this->api = new wfAPI($apiKey, $wordpressVersion);
13 $this->db = new wfDB();
14 global $wpdb;
15 $this->table = $wpdb->base_prefix . 'wfHoover';
16 $this->db->query("truncate table $this->table");
17 }
18 public function hoover($id, $data){
19 if(strpos($data, '.') === false){
20 return;
21 }
22 if(! preg_match('/[a-zA-Z0-9\-]+\.(?:' . $this->dRegex . ')/i', $data)){
23 return;
24 }
25 try {
26 @preg_replace("/(?<=^|[^a-zA-Z0-9\-])((?:[a-zA-Z0-9\-]+\.)+)(" . $this->dRegex . ")((?:$|[^a-zA-Z0-9\-\.\'\"])[^\r\n\s\t\"\'\$\{\}<>]*)/ie", "\$this->" . "addHost(\$id, '$1$2', '$3')", $data);
27 } catch(Exception $e){ error_log("Regex error 1: $e"); }
28 preg_replace("/(?<=[^\d]|^)(\d{8,10}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})([^\d\'\"][^\r\n\s\t\"\'\$\{\}<>]*)/e", "\$this->" . "addIP(\$id, \"$1\",\"$2\")", $data);
29 }
30 private function dbg($msg){ if($this->debug){ error_log("DEBUG: $msg\n"); } }
31 public function addHost($id, $host, $path){
32 $path = preg_replace_callback('/([^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,;\=]+)/', 'wordfenceURLHoover::urlenc', $path);
33 $host = strtolower($host);
34 $this->intAddHost($id, $host, $path);
35 }
36 public function addIP($id, $ipdata, $path){
37 $path = preg_replace_callback('/([^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,;\=]+)/', 'wordfenceURLHoover::urlenc', $path);
38 if(strstr($ipdata, '.') === false && $ipdata >= 16777216 && $ipdata <= 4026531840){
39 $ipdata = long2ip($ipdata);
40 }
41 $parts = explode('.', $ipdata);
42 $isValid = true;
43 if($parts[0] >= 240 || $parts[0] == '10' || $parts[0] == '172' || $parts[0] == '192' || $parts[0] == '127'){
44 $isValid = false;
45 }
46 if($isValid){
47 foreach($parts as $part){
48 if($part < 1 || $part > 255){
49 $isValid = false;
50 }
51 }
52 }
53 if($isValid && $ipdata){
54 $this->intAddHost($id, $ipdata, $path);
55 }
56 }
57 public static function urlenc($m){
58 return urlencode($m[1]);
59 }
60 private function intAddHost($id, $host, $path){
61 if(strpos($path, '/') !== 0){
62 $path = '/';
63 }
64 $this->db->query("insert into $this->table (owner, host, path, hostKey) values ('%s', '%s', '%s', '%s')", $id, $host, $path, $this->makeHostKey($host));
65 return true;
66 }
67 private function makeHostKey($host){
68 if(isset($this->hostKeyCache[$host])){
69 return $this->hostKeyCache[$host];
70 }
71 $hostParts = explode('.', $host);
72 $hostKey = '';
73 if(sizeof($hostParts) == 2){
74 $hostKey = substr(hash('sha256', $hostParts[0] . '.' . $hostParts[1] . '/', true), 0, 4);
75 } else if(sizeof($hostParts) > 2){
76 $hostKey = substr(hash('sha256', $hostParts[sizeof($hostParts) - 3] . '.' . $hostParts[sizeof($hostParts) - 2] . '.' . $hostParts[sizeof($hostParts) - 1] . '/', true), 0, 4);
77 }
78 $this->hostKeyCache[$host] = $hostKey;
79 return $hostKey;
80 }
81 public function getBaddies(){
82 $allHostKeys = array();
83 $stime = microtime(true);
84 $allHostKeys = array();
85 $q1 = $this->db->query("select distinct hostKey as hostKey from $this->table");
86 while($hRec = mysql_fetch_assoc($q1)){
87 array_push($allHostKeys, $hRec['hostKey']);
88 }
89 //Now call API and check if any hostkeys are bad.
90 //This is a shortcut, because if no hostkeys are bad it saves us having to check URLs
91 if(sizeof($allHostKeys) > 0){ //If we don't have any hostkeys, then we won't have any URL's to check either.
92 //Hostkeys are 4 byte sha256 prefixes
93 //Returned value is 2 byte shorts which are array indexes for bad keys that were passed in the original list
94 $this->dbg("Checking " . sizeof($allHostKeys) . " hostkeys");
95 $resp = $this->api->binCall('check_host_keys', implode('', $allHostKeys));
96 $this->dbg("Done hostkey check");
97 if($this->api->errorMsg){
98 $this->errorMsg = $this->api->errorMsg;
99 return false;
100 }
101
102 $badHostKeys = array();
103 if($resp['code'] == 200){
104 if(strlen($resp['data']) > 0){
105 $dataLen = strlen($resp['data']);
106 if($dataLen % 2 != 0){
107 $this->errorMsg = "Invalid data length received from Wordfence server: " . $dataLen;
108 return false;
109 }
110 for($i = 0; $i < $dataLen; $i += 2){
111 $idxArr = unpack('n', substr($resp['data'], $i, 2));
112 $idx = $idxArr[1];
113 if(isset($allHostKeys[$idx]) ){
114 array_push($badHostKeys, $allHostKeys[$idx]);
115 } else {
116 $this->errorMsg = "Bad allHostKeys index: $idx";
117 return false;
118 }
119 }
120 }
121 } else {
122 $this->errorMsg = "Wordfence server responded with an error. HTTP code " . $resp['code'] . " and data: " . $resp['data'];
123 return false;
124 }
125 if(sizeof($badHostKeys) > 0){
126 $urlsToCheck = array();
127 //need to figure out which id's have bad hostkeys
128 //need to feed in all URL's from those id's where the hostkey matches a URL
129 foreach($badHostKeys as $badHostKey){
130 $q1 = $this->db->query("select owner, host, path from $this->table where hostKey='%s'", $badHostKey);
131 while($rec = mysql_fetch_assoc($q1)){
132 $url = 'http://' . $rec['host'] . $rec['path'];
133 if(! isset($urlsToCheck[$rec['owner']])){
134 $urlsToCheck[$rec['owner']] = array();
135 }
136 if(! in_array($url, $urlsToCheck[$rec['owner']])){
137 $urlsToCheck[$rec['owner']][] = $url;
138 }
139 }
140 }
141
142 if(sizeof($urlsToCheck) > 0){
143 $this->dbg("Checking " . sizeof($urlsToCheck) . " URLs");
144 $badURLs = $this->api->call('check_bad_urls', array(), array( 'toCheck' => json_encode($urlsToCheck)) );
145 $this->dbg("Done URL check");
146 if($this->api->errorMsg){
147 $this->errorMsg = $this->api->errorMsg;
148 return false;
149 }
150 if(is_array($badURLs) && sizeof($badURLs) > 0){
151 $finalResults = array();
152 foreach($badURLs as $file => $badSiteList){
153 if(! isset($finalResults[$file])){
154 $finalResults[$file] = array();
155 }
156 foreach($badSiteList as $badSite){
157 array_push($finalResults[$file], array(
158 'URL' => $badSite[0],
159 'badList' => $badSite[1]
160 ));
161 }
162 }
163 return $finalResults;
164 } else {
165 return array();
166 }
167 } else {
168 return array();
169 }
170 } else {
171 return array();
172 }
173 } else {
174 return array();
175 }
176 }
177 }
178 ?>
179