限定user_agent -apache

限定user_agent

當服務器被***,而且查看到***的user_agent有規律,這時就須要限制user_agentphp

user_agent配置以下html

[root@chy 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>
(增長如上配置,配置詳解以下: <IfModule mod_rewrite.c> (這裏須要用到rewrite模塊)
        RewriteEngine on
        RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR] (OR是或者的意思,或者匹配curl,或者匹配baidu.com)(NC忽略大小寫)
        RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC]
        RewriteRule  .*  -  [F](F的含義‘forbidden  F’ (force URL to be forbidden)重寫爲禁止訪問
    </IfModule>

測試user_agentlinux

[root@chy 111.com]# curl -A "chylinux chylinux" -x192.168.212.10:80 'http://www.111.com/123.php' -I
HTTP/1.1 200 OK
Date: Thu, 03 Aug 2017 22:43:50 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Content-Type: text/html; charset=UTF-8
(curl -A 指定user_agent)
[root@chy 111.com]# curl  -x192.168.212.10:80 'http://www.111.com/123.php' -I
HTTP/1.1 403 Forbidden
Date: Thu, 03 Aug 2017 22:53:09 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
(這個若是不指定user_agent的結果)
curl -e "http//" (指定)
相關文章
相關標籤/搜索