邮箱服务器是放在内网映射的公司IP,开放端口后,一直被不停的暴力破解,郁闷死了。其中有个IP 有6W多次啊;从而利用脚本屏蔽IP访问。
1、脚本如下:
#! /bin/bash
# author: kuangl
# mial: kuangl@orient-media.com
# date: 2013-05-04
source /etc/profile
awk -F"[" '/disconnect from unknown/ {print $NF}' /var/log/maillog |grep -v "189.154.4.22" |sed "s/]//g"|sort -nr|uniq -c|sort|awk '{print $1"="$2}' >/root/bad_ip_tmp.txt
awk -F":" '/verification failed/ {print $5}' /var/log/maillog |grep -v "189.154.4.22" |grep -v "SASL"|sort -nr|uniq -c|awk '{print $1"="$2}' >>/root/bad_ip_tmp.txt
awk -F"-" '/\/phpmyadmin\/scripts\/setup\.php/ {print $1}' /var/log/httpd/access_log |grep -v "189.154.4.22" |sort -nr|uniq -c |sort -n |awk '{print $1"="$2}' >>/root/bad_ip_tmp.txt
awk -F"-" '/ZmEu/ {print $1}' /var/log/httpd/access_log |grep -v "189.154.4.22" |sort -nr|uniq -c |sort -n |awk '{print $1"="$2}' >>/root/bad_ip_tmp.txt
sort /root/bad_ip_tmp.txt|uniq >/root/bad_ip.txt
DEFINE="2"
for i in $(cat /root/bad_ip.txt)
do
NUM=`echo $i |awk -F"=" '{print $1}'`
IP=`echo $i|awk -F"=" '{print $2}'`
if [ $NUM -ge $DEFINE ];
then
iptables -L -n|grep $IP > /dev/null
if [ $? -gt 0 ];
then
iptables -I RH-Firewall-1-INPUT 4 -s $IP -j DROP
fi
fi
done
2、假如任务计划5分钟运行一次
*/5 * * * * /home/kuangl/deny_bad_ip_for_smtp.sh
0 1 * * * /etc/init.d/iptables restart
3、查看防火墙
DROP all -- 192.241.206.14 0.0.0.0/0
DROP all -- 198.50.251.242 0.0.0.0/0
DROP all -- 198.23.245.154 0.0.0.0/0
DROP all -- 217.139.66.140 0.0.0.0/0
DROP all -- 134.0.27.102 0.0.0.0/0
DROP all -- 218.22.226.6 0.0.0.0/0
DROP all -- 218.22.226.5 0.0.0.0/0
DROP all -- 202.158.163.158 0.0.0.0/0
DROP all -- 109.169.86.193 0.0.0.0/0
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。