: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
require_once(dirname(__FILE__) . '/wfUtils.php');
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') {
return !wfLog::isHumanRequest($IP, $UA);
else if (isset($b['Crawler']) && $b['Crawler']) {
public static function verifyCrawlerPTR($hostPattern, $IP){
$table = wfDB::networkTable('wfCrawlers');
$IPn = wfUtils::inet_pton($IP);
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($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 == 'verified'){
$host = wfUtils::reverseLookup($IP);
$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', '');
if(preg_match($hostPattern, $host)){
$resultIPs = wfUtils::resolveDomainName($host);
foreach($resultIPs as $resultIP){
$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);
$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);
$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);
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)) {
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\\-News.*$@',
'@^.*Googlebot/2\\.1.*$@',
* Has correct user agent and PTR record points to .googlebot.com domain.
public static function isVerifiedGoogleCrawler($ip = null, $ua = null) {
if ($ip === null || $ip === false) { //Likely a CLI execution
if (array_key_exists($ip, $verified)) {
if (self::isGoogleCrawler($ua)) {
if (self::verifyCrawlerPTR(wordfence::getLog()->getGooglePattern(), $ip)) {
$noc1Status = self::verifyGooglebotViaNOC1($ip);
if ($noc1Status == self::GOOGLE_BOT_VERIFIED) {
else if ($noc1Status == self::GOOGLE_BOT_FAKE) {
return true; //We were unable to successfully validate Googlebot status so default to being permissive
* Attempts to verify whether an IP claiming to be Googlebot is actually Googlebot.
public static function verifyGooglebotViaNOC1($ip = null) {
$table = wfDB::networkTable('wfCrawlers');
$IPn = wfUtils::inet_pton($ip);
$ipHex = wfDB::binaryValueToSQLHex($IPn);
$patternSig = 'googlenoc1';
$status = $db->querySingle("select status from $table
and patternSig=UNHEX(MD5('%s'))
and lastUpdate > unix_timestamp() - %d",
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());
$data = $api->call('verify_googlebot', array(
if (is_array($data) && !empty($data['verified'])) {
$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;
$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');
return self::GOOGLE_BOT_UNDETERMINED;