我在我的网站的.conf文件中试图阻止2个用户代理不断探查我的服务器。
## Block http user agent - morpheus fucking scanner ## if ($http_user_agent ~* "morfeus fucking scanner|ZmEu") { return 403; }
我也尝试了以下,没有运气:
if ($http_user_agent ~* ("morfeus fucking scanner|ZmEu")) if ($http_user_agent ~* (morfeus fucking scanner|ZmEu)) if ($http_user_agent ~* ("morfeus fucking scanner"|"ZmEu")) if ($http_user_agent ~* "morfeus fucking scanner|ZmEu") if ($http_user_agent ~* morfeus fucking scanner|ZmEu)
当我只有一个用户代理时,它运行良好,但是为了添加第二个用户代理,这些用户代理仍然能够探测服务器。
111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /phpMyAdmin/scripts/setup.php HTTP/1.1" 404 118 "-" "ZmEu" "-" 111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /MyAdmin/scripts/setup.php HTTP/1.1" 404 118 "-" "ZmEu" "-" 111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /pma/scripts/setup.php HTTP/1.1" 404 118 "-" "ZmEu" "-" 111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /w00tw00t.at.blackhats.romanian.anti-sec:) HTTP/1.1" 403 118 "-" "ZmEu" "-" 111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /myadmin/scripts/setup.php HTTP/1.1" 404 118 "-" "ZmEu" "-" 111.90.172.235 - - [17/Feb/2013:23:05:22 -0700] "GET /phpmyadmin/scripts/setup.php HTTP/1.1" 404 118 "-" "ZmEu" "-"
根据这两个职位#12:我如何拒绝某些用户代理? ,如何:Nginx的阻止用户代理 ,我认为我安装正确,但似乎并没有工作。
编辑
这里是nginx版本和整个conf文件
nginx version: nginx/1.2.7 server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/XXXXXX/access.log main; error_log /var/log/nginx/XXXXXX/error.log; root /srv/www/XXXXXX; location / { index index.html index.htm index.php; #5/22/2012 - Turn on Server Side Includes ssi on; ## Block http user agent - morpheus fucking scanner ## if ($http_user_agent ~* "morfeus fucking scanner|ZmEu") { return 403; } ## Only allow GET and HEAD request methods. By default Nginx blocks ## all requests type other then GET and HEAD for static content. if ($request_method !~ ^(GET|HEAD)$ ) { return 405; } } location ~ \.php { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/XXXXXX/$fastcgi_script_name; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # Redirect server error pages to the static page error_page 403 404 /error403.html; location = /error403.html { root /usr/share/nginx/html; }
nginx只在configuration的每个级别应用一个位置块。 所有404ing的文件都是.php文件,它们碰到\.php位置块,因此不使用包含用户代理块的/位置块。 要解决此问题,您的用户代理将阻止位置块到根级别,以便将其应用于所有请求。
if ($http_user_agent ~* "morfeus fucking scanner|ZmEu") { return 403; } location / { ... } location \.php { ... }
编辑:你可以用curl这样的东西来testing它,让你设置任意的头文件:
% curl -I localhost/sf645/blah HTTP/1.1 404 Not Found % curl -I -H 'User-agent: ZmEu' localhost/sf645/blah HTTP/1.1 403 Forbidden % curl -I -H 'User-agent: morfeus fucking scanner' localhost/sf645/blah HTTP/1.1 403 Forbidden
尝试只使用模式(morfeus) 。 这个pipe道字符很可能会搞砸正则expression式模式匹配。
尝试这个
if ($http_user_agent ~* (morfeus|ZmEu) ) { return 403; }