PluginProbe ʕ •ᴥ•ʔ
Wordfence Security – Firewall, Malware Scan, and Login Security / 3.2.4
Wordfence Security – Firewall, Malware Scan, and Login Security v3.2.4
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 / wfscan.php
wordfence Last commit date
css 13 years ago images 13 years ago js 13 years ago lib 13 years ago tmp 13 years ago .htaccess 14 years ago readme.txt 13 years ago screenshot-1.png 14 years ago screenshot-2.png 14 years ago screenshot-3.png 14 years ago screenshot-4.png 14 years ago screenshot-5.png 14 years ago visitor.php 13 years ago wfscan.php 13 years ago wordfence.php 13 years ago
wfscan.php
218 lines
1 <?php
2 /* Don't remove this line. WFSOURCEVISIBLE */
3 define('WORDFENCE_VERSIONONLY_MODE', true); //So that we can include wordfence.php and get the version constant
4 ignore_user_abort(true);
5 $wordfence_wp_version = false;
6 if ( !defined('ABSPATH') ) {
7 /** Set up WordPress environment */
8 if($_SERVER['SCRIPT_FILENAME']){
9 $wfBaseDir = preg_replace('/[^\/]+\/[^\/]+\/[^\/]+\/wfscan\.php$/', '', $_SERVER['SCRIPT_FILENAME']);
10 require_once($wfBaseDir . 'wp-load.php');
11 global $wp_version;
12 global $wordfence_wp_version;
13 require($wfBaseDir . 'wp-includes/version.php');
14 $wordfence_wp_version = $wp_version;
15 } else {
16 require_once('../../../wp-load.php');
17 require_once('../../../wp-includes/version.php');
18 }
19 }
20 require_once('wordfence.php');
21 require_once('lib/wordfenceConstants.php');
22 require_once('lib/wfScanEngine.php');
23
24 class wfScan {
25 public static $debugMode = false;
26 public static $errorHandlingOn = true;
27 private static $peakMemAtStart = 0;
28 public static function wfScanMain(){
29 self::$peakMemAtStart = memory_get_peak_usage();
30 $db = new wfDB();
31 if($db->errorMsg){
32 self::errorExit("Could not connect to database to start scan: " . $db->errorMsg);
33 }
34 if(! wordfence::wfSchemaExists()){
35 self::errorExit("Looks like the Wordfence database tables have been deleted. You can fix this by de-activating and re-activating the Wordfence plugin from your Plugins menu.");
36 }
37 if($_GET['test'] == '1'){
38 echo "WFCRONTESTOK:" . wfConfig::get('cronTestID');
39 self::status(4, 'info', "Cron test received and message printed");
40 exit();
41 }
42 /* ----------Starting cronkey check -------- */
43 self::status(4, 'info', "Scan engine received request.");
44 self::status(4, 'info', "Checking cronkey");
45 if(! $_GET['cronKey']){
46 self::status(4, 'error', "Wordfence wfscan.php accessed directly, or WF did not receive a cronkey.");
47 echo "If you see this message it means Wordfence is working correctly. You should not access this URL directly. It is part of the Wordfence security plugin and is designed for internal use only.";
48 exit();
49 }
50 self::status(4, 'info', "Fetching stored cronkey for comparison.");
51 $currentCronKey = wfConfig::get('currentCronKey', false);
52 wfConfig::set('currentCronKey', '');
53 if(! $currentCronKey){
54 wordfence::status(4, 'error', "Wordfence could not find a saved cron key to start the scan so assuming it started and exiting.");
55 exit();
56 }
57 self::status(4, 'info', "Exploding stored cronkey");
58 $savedKey = explode(',',$currentCronKey);
59 if(time() - $savedKey[0] > 86400){
60 self::errorExit("The key used to start a scan expired. The value is: " . $savedKey[0] . " and split is: " . $currentCronKey . " and time is: " . time());
61 } //keys only last 60 seconds and are used within milliseconds of creation
62 self::status(4, 'info', "Checking saved cronkey against cronkey param");
63 if($savedKey[1] != $_GET['cronKey']){
64 self::errorExit("Wordfence could not start a scan because the cron key does not match the saved key.");
65 }
66 /* --------- end cronkey check ---------- */
67
68 ini_set('max_execution_time', 1800); //30 mins
69 self::status(4, 'info', "Becoming admin for scan");
70 self::becomeAdmin();
71 self::status(4, 'info', "Done become admin");
72
73 $isFork = ($_GET['isFork'] == '1' ? true : false);
74
75 if(! $isFork){
76 self::status(4, 'info', "Checking if scan is already running");
77 if(! wfUtils::getScanLock()){
78 self::errorExit("There is already a scan running.");
79 }
80 }
81 self::status(4, 'info', "Requesting max memory");
82 wfUtils::requestMaxMemory();
83 self::status(4, 'info', "Setting up error handling environment");
84 set_error_handler('wfScan::error_handler', E_ALL);
85 register_shutdown_function('wfScan::shutdown');
86 if(! self::$debugMode){
87 ob_start('wfScan::obHandler');
88 }
89 @error_reporting(E_ALL);
90 @ini_set('display_errors','On');
91 self::status(4, 'info', "Setting up scanRunning and starting scan");
92 $scan = false;
93 if($isFork){
94 $scan = wfConfig::get_ser('wfsd_engine', false, true);
95 if($scan){
96 self::status(4, 'info', "Got a true deserialized value back from 'wfsd_engine' with type: " . gettype($scan));
97 wfConfig::set('wfsd_engine', '', true);
98 } else {
99 self::status(2, 'error', "Scan can't continue - stored data not found after a fork. Got type: " . gettype($scan));
100 wfConfig::set('wfsd_engine', '', true);
101 exit();
102 }
103 } else {
104 wordfence::statusPrep(); //Re-initializes all status counters
105 $scan = new wfScanEngine();
106 }
107 try {
108 $scan->go();
109 } catch (Exception $e){
110 wfUtils::clearScanLock();
111 self::status(2, 'error', "Scan terminated with error: " . $e->getMessage());
112 self::status(10, 'info', "SUM_KILLED:Previous scan terminated with an error. See below.");
113 exit();
114 }
115 wfUtils::clearScanLock();
116 self::logPeakMemory();
117 self::status(2, 'info', "Wordfence used " . sprintf('%.2f', (wfConfig::get('wfPeakMemory') - self::$peakMemAtStart) / 1024 / 1024) . "MB of memory for scan. Server peak memory usage was: " . sprintf('%.2f', wfConfig::get('wfPeakMemory') / 1024 / 1024) . "MB");
118 }
119 private static function logPeakMemory(){
120 $oldPeak = wfConfig::get('wfPeakMemory', 0);
121 $peak = memory_get_peak_usage();
122 if($peak > $oldPeak){
123 wfConfig::set('wfPeakMemory', $peak);
124 }
125 }
126 public static function obHandler($buf){
127 if(strlen($buf) > 1000){
128 $buf = substr($buf, 0, 255);
129 }
130 if(empty($buf) === false && preg_match('/[a-zA-Z0-9]+/', $buf)){
131 self::status(1, 'error', $buf);
132 }
133 }
134 public static function error_handler($errno, $errstr, $errfile, $errline){
135 if(self::$errorHandlingOn){
136 if(preg_match('/wordfence\//', $errfile)){
137 $level = 1; //It's one of our files, so level 1
138 } else {
139 $level = 4; //It's someone elses plugin so only show if debug is enabled
140 }
141 self::status($level, 'error', "$errstr ($errno) File: $errfile Line: $errline");
142 }
143 }
144 public static function shutdown(){
145 self::logPeakMemory();
146 }
147 private static function errorExit($msg){
148 wordfence::status(1, 'error', "Scan Engine Error: $msg");
149 exit();
150 }
151 public static function becomeAdmin(){
152 $db = new wfDB();
153 global $wpdb;
154 $adminUserID = false;
155 $userSource = '';
156 if(is_multisite()){
157 $users = get_users('role=super&fields=ID');
158 if(sizeof($users) < 1){
159 $supers = get_super_admins();
160 if(sizeof($supers) > 0){
161 foreach($supers as $superLogin){
162 $superDat = get_user_by('login', $superLogin);
163 if($superDat){
164 $users = array($superDat->ID);
165 $userSource = 'multisite get_super_admins() function';
166 break;
167 }
168 }
169 }
170 } else {
171 $userSource = 'multisite get_users() function';
172 }
173 } else {
174 $users = get_users('role=administrator&fields=ID');
175 if(sizeof($users) < 1){
176 $supers = get_super_admins();
177 if(sizeof($supers) > 0){
178 foreach($supers as $superLogin){
179 $superDat = get_user_by('login', $superLogin);
180 if($superDat){
181 $users = array($superDat->ID);
182 $userSource = 'singlesite get_super_admins() function';
183 break;
184 }
185 }
186 }
187 } else {
188 $userSource = 'singlesite get_users() function';
189 }
190 }
191 if(sizeof($users) > 0){
192 sort($users, SORT_NUMERIC);
193 $adminUserID = $users[0];
194 } else {
195 //Last ditch attempt
196 $adminUserID = $db->querySingle("select user_id from " . $wpdb->usermeta . " where meta_key='" . $wpdb->base_prefix . "user_level' order by meta_value desc, user_id asc limit 1");
197 if(! $adminUserID){
198 self::status(1, 'error', "Could not get the administrator's user ID. Scan can't continue.");
199 exit();
200 }
201 $userSource = 'manual DB query';
202 }
203 $adminUsername = $db->querySingle("select user_login from " . $wpdb->users . " where ID=%d", $adminUserID);
204 self::status(4, 'info', "Scan will run as admin user '$adminUsername' with ID '$adminUserID' sourced from: $userSource");
205 wp_set_current_user($adminUserID);
206 if(! is_user_logged_in()){
207 self::status(1, 'error', "Scan could not sign in as user '$adminUsername' with ID '$adminUserID' from source '$userSource'. Scan can't continue.");
208 exit();
209 }
210 self::status(4, 'info', "Scan authentication complete.");
211 }
212 private static function status($level, $type, $msg){
213 wordfence::status($level, $type, $msg);
214 }
215 }
216 wfScan::wfScanMain();
217 ?>
218