我一直一次从一个IP地址获得垃圾邮件尝试(尽管这个IP地址每天都在变化),试图幸运地猜测我的Web服务器上的可执行文件。他们都追溯到同一个地方-中国的腾讯云计算。这些垃圾邮件尝试使服务器崩溃,从而使网站无法访问。 如何停止此操作?
我尝试联系网络滥用电子邮件并致电我的ISP,以查看他们是否可以做些什么,但无济于事。
下面显示的示例Apache日志。
[Thu Sep 20 22:47:34.169296 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/help.php' not found or unable to stat
[Thu Sep 20 22:47:34.418703 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/java.php' not found or unable to stat
[Thu Sep 20 22:47:34.682234 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/_query.php' not found or unable to stat
[Thu Sep 20 22:47:34.910484 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/test.php' not found or unable to stat
[Thu Sep 20 22:47:35.138673 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/db_cts.php' not found or unable to stat
[Thu Sep 20 22:47:35.369907 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/db_pma.php' not found or unable to stat
[Thu Sep 20 22:47:36.382860 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/logon.php' not found or unable to stat
[Thu Sep 20 22:47:37.920666 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/help-e.php' not found or unable to stat
[Thu Sep 20 22:47:38.149610 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/license.php' not found or unable to stat
[Thu Sep 20 22:47:38.382743 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/log.php' not found or unable to stat
[Thu Sep 20 22:47:38.616254 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/hell.php' not found or unable to stat
[Thu Sep 20 22:47:38.880654 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/pmd_online.php' not found or unable to stat
[Thu Sep 20 22:47:39.111538 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/x.php' not found or unable to stat
[Thu Sep 20 22:47:39.344646 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/shell.php' not found or unable to stat
[Thu Sep 20 22:47:40.321053 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/desktop.ini.php' not found or unable to stat
[Thu Sep 20 22:47:41.916380 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/z.php' not found or unable to stat
[Thu Sep 20 22:47:42.167929 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/lala.php' not found or unable to stat
[Thu Sep 20 22:47:42.429254 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/lala-dpr.php' not found or unable to stat
[Thu Sep 20 22:47:42.691206 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/wpo.php' not found or unable to stat
[Thu Sep 20 22:47:42.944551 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/text.php' not found or unable to stat
[Thu Sep 20 22:47:43.199610 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/wp-config.php' not found or unable to stat
[Thu Sep 20 22:47:43.455259 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/muhstik.php' not found or unable to stat
[Thu Sep 20 22:47:44.529700 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/muhstik2.php' not found or unable to stat
[Thu Sep 20 22:47:45.925214 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/muhstiks.php' not found or unable to stat
[Thu Sep 20 22:47:46.165955 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/muhstik-dpr.php' not found or unable to stat
[Thu Sep 20 22:47:46.424593 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/lol.php' not found or unable to stat
[Thu Sep 20 22:47:46.683114 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/uploader.php' not found or unable to stat
[Thu Sep 20 22:47:46.941768 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/cmd.php' not found or unable to stat
[Thu Sep 20 22:47:47.199412 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/cmx.php' not found or unable to stat
[Thu Sep 20 22:47:47.436995 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/cmv.php' not found or unable to stat
[Thu Sep 20 22:47:48.608073 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/cmdd.php' not found or unable to stat
[Thu Sep 20 22:47:49.941993 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/knal.php' not found or unable to stat
[Thu Sep 20 22:47:50.202085 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/cmd.php' not found or unable to stat
[Thu Sep 20 22:47:50.465856 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/shell.php' not found or unable to stat
[Thu Sep 20 22:47:50.719343 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/appserv.php' not found or unable to stat
[Thu Sep 20 22:47:53.919666 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/wuwu11.php' not found or unable to stat
[Thu Sep 20 22:47:54.135087 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/xw.php' not found or unable to stat
[Thu Sep 20 22:47:54.365319 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/xw1.php' not found or unable to stat
[Thu Sep 20 22:47:54.600458 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/9678.php' not found or unable to stat
[Thu Sep 20 22:47:54.844971 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/wc.php' not found or unable to stat
[Thu Sep 20 22:47:55.109660 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/xx.php' not found or unable to stat
[Thu Sep 20 22:47:55.364916 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/s.php' not found or unable to stat
[Thu Sep 20 22:47:55.581704 2018] [:error] [pid 27541] [client 192.144.156.249:29474] script '/var/www/html/w.php' not found or unable to stat
更新:其他日志
'[Tue Sep 25 07:59:21.537385 2018] [core:notice] [pid 28393] AH00094: Command line: '/usr/sbin/apache2'
'[星期二2018年9月25日08:32:08.233864] [自动索引:错误] [pid 29290] [客户端192.141.161.31:41020] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(索引(.html,index.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二08:51:23.208687] [自动索引:错误] [pid 29759] [客户端81.199.17.114:33476] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(index.html,index (.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二09:07:45.829806] [自动索引:错误] [pid 30004] [客户端157.119.212.30:38609] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(index.html,index (.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二09:33:49.984459] [自动索引:错误] [pid 30699] [客户端187.10.199.101:35686] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(index.html,index (.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二11:24:46.399677] [自动索引:错误] [pid 794] [客户端31.7.122.119:57011] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(index.html,index (.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二11:53:06.380975] [自动索引:错误] [pid 1362] [客户端84.22.54.93:37588] AH01276:无法提供目录/ var / www / html /:没有匹配的DirectoryIndex(index.html,index (.cgi,index.pl,index.php,index.xhtml,index.htm),并且服务器生成的目录索引受Options指令禁止
[2018年9月25日星期二12:22:27.732958] [mpm_prefork:notice] [pid 28393] AH00169:捕获了SIGTERM,关闭了
[2018年9月25日星期二12:22:51.582214] [:通知] [pid 2041] FastCGI:进程管理器已初始化(pid 2041)
[2018年9月25日星期二12:22:51.892511] [mpm_prefork:notice] [pid 2040] AH00163:Apache / 2.4.10(Raspbian)mod_fastcgi / mod_fastcgi-SNAP-0910052141 mpm-itk / 2.4.7-02 PHP / 5.6。已配置36-0 + deb8u1 OpenSSL / 1.0.1t-恢复正常操作
[2018年9月25日星期二12:22:51.892924] [core:notice] [pid 2040] AH00094:命令行:'/ usr / sbin / apache2'
[2018年9月25日星期二12:23:01.247551] [core:error] [pid 2040] AH00046:子进程2046仍未退出,正在发送SIGKILL
[2018年9月25日星期二12:23:01.247755] [core:error] [pid 2040] AH00046:子进程2047仍未退出,正在发送SIGKILL
[2018年9月25日星期二12:23:02.249062] [mpm_prefork:notice] [pid 2040] AH00169:捕获了SIGTERM,关闭了'
答案 0 :(得分:3)
在中国。
您无法阻止它。
您可以添加防火墙规则以丢弃来自该IP的流量;但是它没有用,因为它只会从另一个IP中出现,最终您将拥有成千上万的删除规则,这将影响性能。
限制来自单个IP的请求将减少服务器负载,但是不会停止扫描。如果您确实想走在“封锁”道路上,fail2ban会很好地工作。
通常,您的代码只需要能够处理此问题。
如果您的网络应用程序是内部应用程序或访问者有限,则可以丢弃除授权地址以外的所有流量。
答案 1 :(得分:2)
我在Raspberry Pi3B +上运行了一个基于节点的HTTP服务器-我对此探针非常了解。每个IP探针仅使用IP地址,因此,如果您查看HTTP标头“主机”,它将是您域的IP地址,或更糟的是 localhost 。
我今晚捕获的这个特定探针从WebDAV上的攻击媒介开始,尝试使缓冲区溢出。 WebDAV使用唯一的HTTP标头-PROPFIND。整个捕获内容不适合一个图像,但是下一部分使用localhost并进一步探究WebDAV。
然后,探针开始检查PHP脚本,这就是您在Apache日志中显示的内容。
合法流量无法做到这一点-它使用域的主机名,合法bot在用户代理标头中都有其名称,因此,对HTTP标头的分析很长一段路要走。 ;-)
此外-您遇到的崩溃发生在扫描的最后一部分,它不是GET-它是POST。 (CGI =通用网关接口-POST)。 请注意,大量的GET间隔为24秒...有趣的是-该扫描程序可能实际上正在同时探测数千个IP-考虑到探测的来源,您可能没有理由抱怨滥用。 最好的建议是完全忽略它。在Node中,我可以销毁连接,甚至可以将IP列入黑名单,但是-我运行了很多分析代码来支持该连接,因此我不知道Apache在这方面提供了什么。
答案 2 :(得分:0)
这不是“拒绝服务”,而是相当常见的扫描以查找可能的利用。知识产权在中国并不重要-在不必服务于该地区的同时,人们可以拒绝为其服务。
您可以使用render
文件(或虚拟主机配置);这至少会使服务器不响应:
.htaccess
一个人可以拒绝来自整个子网的请求...这可能有助于彻底摆脱它们:
deny from 192.144.156.249
添加类似的防火墙规则,甚至都不会让这些请求到达服务器。
区分IP流量几乎不属于应用程序代码的范围。
答案 3 :(得分:0)
我创建了一个每1分钟运行一次的脚本,并检测error.log和access.log中的所有失败类型 它还会检查星号消息文件“是否失败” 当找到尝试次数超过20次的IP时,会将其添加到ufw中。 到目前为止-它像一种魅力。
这是脚本:
#!/bin/bash
clear
#ban IPs:
bip() {
echo "" > tmpIPs
ufw status | grep DENY | awk '$1 !="Anywhere" {print $1}' | sort > tmpinc
exst=$(ufw status | grep "Anywhere DENY" | awk '{print $3}' | sort | uniq)
cat $cTarget | while read line
do
add=$(cat tmpinc | grep $line)
if [ "$add" != "$line" ]
then
ip=$(echo $line | cut -d '.' -f 1,2,3)
if [ $ip != $ignorIP ]
then
echo $line >> tmpIPs
fi
fi
done
lAdd=$(cat tmpIPs)
cat tmpIPs | while read line
do
if [ "$line" != "" ]
then
/usr/sbin/ufw insert 1 deny from $line to any >> $cBanIpLog
/usr/sbin/ufw insert 1 deny to $line from any >> $cBanIpLog
echo " Banned $line" >> $cBanIpLog
fi
done
rm tmpIPs
}
nMax=5 # Maximum failes
cTarget="/tmp/_ban.ip" # Temporary storage file
cLogFile="/var/log/apache2/access.log" # apache2 access log file
cLogFile1="/var/log/apache2/error.log" # apache2 error.log
cLogFile2="/var/log/asterisk/messages" # asterisk log file
cBanLog="/var/log/banips.log" #This script log file
cBanIpLog="/var/log/banIP.log"
ignorIP="192.168.1" #IP to ignor, usually home network
dt=$(date +%Y-%m-%d)
echo "Banning IP run at $(date)
Maximum offends: $nMax
Checking logs
$cLogFile
$cLogFile1
$cLogFile11
$cLogFile12
" > $cBanIpLog
#Get the bastards out of apache2 and asterisk:
#apache2 access.log
grep 404 $cLogFile | cut -d ' ' -f 1,4 | cut -d ':' -f 1,2,3 | tr -d '[' | sort | uniq -c | sort -rn | awk ' $1 > '"$nMax"' {print $2}' | uniq -c | awk '{print $2}' > $cTarget.tmp
#apache2 error.log
grep "not found or unable to stat" $cLogFile1 | awk '{print $1,$2,$3,$5,$10}' | cut -d ':' -f 1 | sort | uniq -c | awk ' $1 > '"$nMax"' {print $6}' >> $cTarget.tmp
#asterisk messages
grep "failed for" $cLogFile2 | awk -F'failed for' '{print $2}' | awk -F' ' '{print $1}' | awk -F':' '{print $1}' | tr -d "'" | sort | uniq -c | sort -nr | awk ' $1 > '"$nMax"' {print $2}' >> $cTarget.tmp
#asterisk messages
grep "rejected because extension not found" /var/log/asterisk/messages | awk -F'(' '{print $2}' | awk -F':' '{print $1}' | sort | uniq -c | awk ' $1 > '"$nMax"' {print $2}' >> $cTarget.tmp
#Check myAnt logons
#grep LogonERR /var/www/html/_Public/sys_logs/_qryLogIn.log | awk '{print $3}' | sort | uniq -c | sort -nr | awk '$1 > $nMax {print $2}' >> $cTarget.tmp
#Leave uniq ips
cat $cTarget.tmp | sort | uniq > $cTarget
rm $cTarget.tmp
#Banning
bip
if [ "$lAdd" != "" ]
then
#Conclude:
/bin/systemctl restart ufw
/bin/systemctl status ufw >> $cBanIpLog
/usr/sbin/ufw status >> $cBanIpLog
cat $cBanLog | sort | uniq | sort >> /var/log/banips.tmp
rm $cBanLog
mv /var/log/banips.tmp $cBanLog
cat $cBanLog | nl >> $cBanIpLog
echo "Log file at $cBanIpLog
nano $cBanLog
Finished banning $(date)
" >> $cBanIpLog
#echo nano /var/log/banips.log
clear
cat $cBanIpLog
fi