我在 aws elastic beanstalk 平台上的 nginx 上运行了一个 Rails 应用程序。我检查了 nginx/access.log,发现了许多可疑的 GET 请求,如下所示:
SUSPICIOUS_URL == '#m. #face #book #.com'
172.31.17.148 - - [24/Jul/2016:04:02:37 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:37 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:37 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:37 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:38 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:38 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http://SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
172.31.17.148 - - [24/Jul/2016:04:02:38 +0000] "GET /bisnis/read/2439204/beredar-di-medsos-bi-bantah-keluarkan-uang-pecahan-rp-200-ribu HTTP/1.1" 301 5
"http:/SUSPICIOUS_URL/" "Mozilla/5.0 (Linux; Android 5.1.1; SM-E700H Build/LMY47X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/51.0.2
704.81 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/86.0.0.19.69;]" "175.141.68.34"
我确信这些都是机器人,我该如何使用 nginx 阻止这些可疑请求?
编辑:
显然,这是一种称为引荐垃圾邮件的做法。点击此处了解更多信息。https://www.wikiwand.com/en/Referer_spam
答案1
看起来三星 Galaxy 正在使用过时的 dns-entry 作为 m.facebook.com ;-)
嗯,如果你看一下你的 access.log,你会发现很多请求,例如/pma
,,,,等等。似乎有几个机器人正在检查知名开源软件(如 phpmyadmin、wordpress 或其他软件)的旧版本/易受攻击的/webadmin
版本/admin/config.php
。/w00tw00t
/vtigercrm
因为我们不太喜欢这样,所以我们试图将它们拒之门外。第一次,我们只在 nginx-config 中添加了几个位置,在与手动填写的列表中的条目匹配的请求上发送错误 404。这很能迷惑他们,但并没有真正减少“坏请求”的数量。后来,我们将列表移至“fail2ban”。每当 access.log 上出现带有我们预定义 URI 之一的 GET 请求时,iptables 就会阻止客户端 IP 48 小时。由于他们无法再访问我们的服务器,这非常有帮助。您只需安装 fail2ban,添加一个带有简单正则表达式值列表的过滤器(在 debian 上为 /etc/fil2an/filter.d/xxx.conf),然后将过滤器添加到 jail.conf。
例如,/etc/fail2ban/filter.d/nginx-bots.conf:
[INCLUDES]
[Definition]
failregex = ^<HOST> - .* "GET /?/phpmyadmin/
^<HOST> - .* "GET /?/phpMyAdmin/
^<HOST> - .* "GET /?/pma/
^<HOST> - .* "GET /?/PMA/
^<HOST> - .* "GET /?/sqlmanager/
^<HOST> - .* "GET /?/phpmyadmin-?2/
^<HOST> - .* "GET /?/phpMyAdmin-?2/
^<HOST> - .* "GET /?/mysqlmanager/
^<HOST> - .* "GET /?/webadmin/
^<HOST> - .* "GET /?/php-my-admin/
^<HOST> - .* "GET /?/myadmin
^<HOST> - .* "GET /?/MyAdmin
^<HOST> - .* "GET /?/cgi-bin/
^<HOST> - .* "POST /?/%%
^<HOST> - .* "GET /admin/config.php
^<HOST> - .* "GET /idssvc/iesvc
^<HOST> - .* "GET /vtigercrm/
^<HOST> - .* "GET /wstats/wstats
^<HOST> - .* "GET /CluJaNul/
^<HOST> - .* "GET /bynazi/
^<HOST> - .* "GET /invoker/
^<HOST> - .* "GET \\x
^<HOST> - .* "GET /jmx-console/
^<HOST> - .* "GET /zecmd/
^<HOST> - .* "GET /?/manager/html/upload
^<HOST> - .* "GET /w00tw00t
^<HOST> - .* "GET /muieblackcat
ignoreregex =
添加于/etc/fail2ban/jail.conf
:
[nginx-bots]
enable = true
port = http,https
filter = nginx-bots
logpath = /var/log/nginx/access.log*
maxretry = 1
bantime = 172800
findtime = 86400
您还可以考虑另一种方法来过滤掉这些机器人。如果您将状态代码添加到 nginx 访问日志格式,则可以设置 fail2ban/filter.conf 来阻止每分钟出现超过 10 个 404 错误的用户 - 或类似的东西。
但是您必须记住,如果您的 fail2ban 配置不够好,它可能会阻止“好”用户。