PHP 8.2.31
Preview: wfCrawl.php Size: 6.92 KB
//proc/self/root/home/nshryvcy/blissfulnepal.com/wp-content/plugins/wordfence/lib/wfCrawl.php

<?php
require_once(dirname(__FILE__) . '/wfUtils.php');
class wfCrawl {
	const GOOGLE_BOT_VERIFIED = 'verified';
	const GOOGLE_BOT_FAKE = 'fakeBot';
	const GOOGLE_BOT_UNDETERMINED = 'undetermined';
	
	public static function isCrawler($UA){
		$browscap = new wfBrowscap();
		$b = $browscap->getBrowser($UA);
		if (!$b || $b['Parent'] == 'DefaultProperties') {
			$IP = wfUtils::getIP(); 
			return !wfLog::isHumanRequest($IP, $UA);
		}
		else if (isset($b['Crawler']) && $b['Crawler']) {
			return true;
		}
		
		return false;
	}
	public static function verifyCrawlerPTR($hostPattern, $IP){
		$table = wfDB::networkTable('wfCrawlers');
		$db = new wfDB();
		$IPn = wfUtils::inet_pton($IP);
		$ipHex = wfDB::binaryValueToSQLHex($IPn);
		$status = $db->querySingle("select status from $table where IP={$ipHex} and patternSig=UNHEX(MD5('%s')) and lastUpdate > unix_timestamp() - %d", $hostPattern, WORDFENCE_CRAWLER_VERIFY_CACHE_TIME);
		if($status){
			if($status == 'verified'){
				return true;
			} else {
				return false;
			}
		}
		$host = wfUtils::reverseLookup($IP);
		if(! $host){ 
			$db->queryWrite("insert into $table (IP, patternSig, status, lastUpdate, PTR) values ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $hostPattern, 'noPTR', '', 'noPTR', '');
			return false; 
		}
		if(preg_match($hostPattern, $host)){
			$resultIPs = wfUtils::resolveDomainName($host);
			$addrsMatch = false;
			foreach($resultIPs as $resultIP){
				if($resultIP == $IP){
					$addrsMatch = true;
					break;
				}
			}
			if($addrsMatch){
				$db->queryWrite("insert into $table (IP, patternSig, status, lastUpdate, PTR) values ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $hostPattern, 'verified', $host, 'verified', $host);
				return true;
			} else {
				$db->queryWrite("insert into $table (IP, patternSig, status, lastUpdate, PTR) values ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $hostPattern, 'fwdFail', $host, 'fwdFail', $host);
				return false;
			}
		} else {
			$db->queryWrite("insert into $table (IP, patternSig, status, lastUpdate, PTR) values ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $hostPattern, 'badPTR', $host, 'badPTR', $host);
			return false;
		}
	}
	public static function isGooglebot($userAgent = null){
		if ($userAgent === null) {
			$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
		}
		return (bool) preg_match('/Googlebot\/\d\.\d/', $userAgent);
	}
	public static function isGoogleCrawler($userAgent = null){
		if ($userAgent === null) {
			$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
		}
		foreach (self::$googPat as $pat) {
			if (preg_match($pat . 'i', $userAgent)) {
				return true;
			}
		}
		return false;
	}
	private static $googPat = array(
'@^Mozilla/5\\.0 \\(.*Google Keyword Tool.*\\)$@',
'@^Mozilla/5\\.0 \\(.*Feedfetcher\\-Google.*\\)$@',
'@^Feedfetcher\\-Google\\-iGoogleGadgets.*$@',
'@^searchbot admin\\@google\\.com$@',
'@^Google\\-Site\\-Verification.*$@',
'@^Google OpenSocial agent.*$@',
'@^.*Googlebot\\-Mobile/2\\..*$@',
'@^AdsBot\\-Google\\-Mobile.*$@',
'@^google \\(.*Enterprise.*\\)$@',
'@^Mediapartners\\-Google.*$@',
'@^GoogleFriendConnect.*$@',
'@^googlebot\\-urlconsole$@',
'@^.*Google Web Preview.*$@',
'@^Feedfetcher\\-Google.*$@',
'@^AppEngine\\-Google.*$@',
'@^Googlebot\\-Video.*$@',
'@^Googlebot\\-Image.*$@',
'@^Google\\-Sitemaps.*$@',
'@^Googlebot/Test.*$@',
'@^Googlebot\\-News.*$@',
'@^.*Googlebot/2\\.1.*$@',
'@^AdsBot\\-Google.*$@',
'@^Google$@'
	);


	/**
	 * Has correct user agent and PTR record points to .googlebot.com domain.
	 *
	 * @param string|null $ip
	 * @param string|null $ua
	 * @return bool
	 */
	public static function isVerifiedGoogleCrawler($ip = null, $ua = null) {
		static $verified;
		if (!isset($verified)) {
			$verified = array();
		}
		if ($ip === null) {
			$ip = wfUtils::getIP();
		}
		
		if ($ip === null || $ip === false) { //Likely a CLI execution
			return false;
		}
		
		if (array_key_exists($ip, $verified)) {
			return $verified[$ip];
		}
		if (self::isGoogleCrawler($ua)) {
			$services = wfUtils::whitelistPresets();
			if (array_key_exists('google', $services)) {
				$ranges = $services['google']['r'];
				foreach ($ranges as $r) {
					if (wfUtils::subnetContainsIP($r, $ip)) {
						$verified[$ip] = true;
						return $verified[$ip];
					}
				}
			}
			
			if (self::verifyCrawlerPTR(wordfence::getLog()->getGooglePattern(), $ip)) {
				$verified[$ip] = true;
				return $verified[$ip];
			}
			
			$noc1Status = self::verifyGooglebotViaNOC1($ip);
			if ($noc1Status == self::GOOGLE_BOT_VERIFIED) {
				$verified[$ip] = true;
				return $verified[$ip];
			}
			else if ($noc1Status == self::GOOGLE_BOT_FAKE) {
				$verified[$ip] = false;
				return $verified[$ip];
			}
			
			if (!array_key_exists('google', $services)) {
				return true; //We were unable to successfully validate Googlebot status so default to being permissive if the service IP list is missing
			}
		}
		$verified[$ip] = false;
		return $verified[$ip];
	}

	/**
	 * Attempts to verify whether an IP claiming to be Googlebot is actually Googlebot.
	 * 
	 * @param string|null $ip
	 * @return string
	 */
	public static function verifyGooglebotViaNOC1($ip = null) {
		$table = wfDB::networkTable('wfCrawlers');
		if ($ip === null) {
			$ip = wfUtils::getIP();
		}
		$db = new wfDB();
		$IPn = wfUtils::inet_pton($ip);
		$ipHex = wfDB::binaryValueToSQLHex($IPn);
		$patternSig = 'googlenoc1';
		$status = $db->querySingle("select status from $table
				where IP={$ipHex}
				and patternSig=UNHEX(MD5('%s'))
				and lastUpdate > unix_timestamp() - %d",
				$patternSig,
				WORDFENCE_CRAWLER_VERIFY_CACHE_TIME);
		if ($status === 'verified') {
			return self::GOOGLE_BOT_VERIFIED;
		} else if ($status === 'fakeBot') {
			return self::GOOGLE_BOT_FAKE;
		}

		$api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion());
		try {
			$data = $api->call('verify_googlebot', array(
				'ip' => $ip,
			));
			if (is_array($data) && !empty($data['verified'])) {
				// Cache results
				$db->queryWrite("INSERT INTO {$table} (IP, patternSig, status, lastUpdate) VALUES ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp()) ON DUPLICATE KEY UPDATE status = VALUES(status), lastUpdate = VALUES(lastUpdate)", $patternSig, 'verified');
				return self::GOOGLE_BOT_VERIFIED;
			} else {
				$db->queryWrite("INSERT INTO {$table} (IP, patternSig, status, lastUpdate) VALUES ({$ipHex}, UNHEX(MD5('%s')), '%s', unix_timestamp()) ON DUPLICATE KEY UPDATE status = VALUES(status), lastUpdate = VALUES(lastUpdate)", $patternSig, 'fakeBot');
				self::GOOGLE_BOT_FAKE;
			}
		} catch (Exception $e) {
			// Do nothing, bail
		}
		return self::GOOGLE_BOT_UNDETERMINED;
	}
}

Directory Contents

Dirs: 4 × Files: 109

Name Size Perms Modified Actions
audit-log DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
dashboard DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
Diff DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
rest-api DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
354 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
425 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.63 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.85 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.39 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.82 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.34 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.62 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.86 MB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.17 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
580 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.46 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.94 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
317 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.01 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.05 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.15 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.86 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.87 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.68 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
12.49 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
38.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
408 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
991 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.30 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.80 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.64 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
185 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.51 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.72 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
20.55 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.38 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.19 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.10 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
47.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.90 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
256.83 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.77 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
25.94 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.25 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
127.17 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.92 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.29 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.05 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.25 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
352.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
11.49 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
66.92 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.89 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.72 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.97 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
878 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.23 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
303 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
266 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.80 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.70 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.56 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
29.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
199.14 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.95 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.81 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
58.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.27 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.20 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
754 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.70 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.93 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.40 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
377 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
15.98 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
127.73 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.04 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.01 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
403 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
408 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.09 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.77 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
11.93 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.21 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
24.95 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.14 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
27.23 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
131.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
15.59 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
535 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.22 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.75 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
392.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.35 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
42.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
28.19 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
18.35 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).