WordPress禁止HTTP_USER_AGENT恶意采集与攻击

作者: 时间:
浏览 : 729

很多采集程序和SQL注入工具都是利用空USER_AGENT来获取信息,屏蔽恶意HTTP_USER_AGENT既可以防采集还可以在一定程度防攻击。

直接复制以下代码,粘贴到你当前主题模板的functions.php里:

$ua = $_SERVER['HTTP_USER_AGENT'];
$now_ua = array('FeedDemon ','ZmEu','Indy Library','oBot','jaunty'); //将恶意USER_AGENT存入数组
if(!$ua) { //禁止空USER_AGENT,dedecms等主流采集程序都是空USER_AGENT,部分sql注入工具也是空USER_AGENT
header("Content-type: text/html; charset=utf-8");
wp_die('请勿采集本站!');
}else{
    foreach($now_ua as $value )
    if(eregi($value,$ua)) {
    header("Content-type: text/html; charset=utf-8");
    wp_die('请勿采集本站!');
    }
}

$now_ua里面的数组是一些恶意采集软件的HTTP_USER_AGENT标识,下面还有更多:

FeedDemon 内容采集
BOT/0.1 (BOT for JCE) sql注入
CrawlDaddy sql注入
Java 内容采集
Jullo 内容采集
Feedly 内容采集
UniversalFeedParser 内容采集
ApacheBench cc攻击器
Swiftbot 爬虫
YandexBot 爬虫
AhrefsBot 爬虫
YisouSpider 爬虫
jikeSpider 爬虫
MJ12bot 爬虫
ZmEu phpmyadmin漏洞扫描
WinHttp 采集cc攻击
EasouSpider 爬虫
HttpClient tcp攻击
Microsoft URL Control 扫描
YYSpider 爬虫
jaunty wordpress爆破扫描器
oBot 爬虫
Python-urllib 内容采集
Indy Library 扫描
FlightDeckReports Bot 爬虫

上面是一些已知的恶意工具和爬虫的User Agent值列表,可以根据需要加入到代码里进行屏蔽!

Tag标签:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注