如何用shell防止郵件暴力破解

來源:互聯網
上載者:User

郵箱伺服器是放在內網映射的公司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  --  222.73.115.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

本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Network/Security/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.