user_agent(用户代理):是指浏览器(搜索引擎)的信息包括硬件平台、系统软件、应用软件和用户个人偏好。
有时候网站受到CC攻击,其原理是:攻击者借助代理服务器(肉机)生成指向受害主机的合法请求,实现DDOS和伪装。CC攻击的一个特点就是其useragent是一致的,所以,可以通过限制攻击者useragent的方法来阻断其攻击。
步骤如下
1,编辑虚拟主机配置文件
[root@dl-001 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
。。。。。。。。。。。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
RewriteRule .* - [F]
</IfModule>
。。。。。。。。。。
说明: NC表示忽略大小写,OR选项表示或者(不加任何选项表并且)连接下一个条件,F=forbidden禁止。
2,重载
[root@dl-001 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@dl-001 111.com]# /usr/local/apache2.4/bin/apachectl graceful
3,测试
[root@dl-001 111.com]# curl -x192.168.11.128:80 'http://111.com/index.php' -I
HTTP/1.1 403 Forbidden
Date: Tue, 26 Dec 2017 14:04:25 GMT
Server: Apache/2.2.34 (Unix) DAV/2 PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[root@dl-001 111.com]# curl -A "aminglinux aminglinux" -x192.168.11.128:80 'http://111.com/index.php' -I
HTTP/1.1 200 OK
Date: Tue, 26 Dec 2017 14:05:16 GMT
Server: Apache/2.2.34 (Unix) DAV/2 PHP/5.6.30
X-Powered-By: PHP/5.6.30
Content-Type: text/html; charset=UTF-8
说明: curl -A 指定useragent。