e-mail server is placed in the intranet map of the company IP, open port, has been the constant violence to crack, depressed dead. One of the IP has 6 w many times Ah, thereby using the script to mask IP access.
1. The script is as follows:
#! /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 $ = ' $} ' >/root/bad_ip_tmp.txt
Awk-f ":" '/verification failed/{print $} '/var/log/maillog |grep-v ' 189.154.4.22 ' |grep-v ' SASL ' |sort-nr|uniq-c|awk ' {print $ = ' $} ' >>/root/bad_ip_tmp.txt
Awk-f "-" '/\/phpmyadmin\/scripts\/setup\.php/{print} '/var/log/httpd/access_log |grep-v "189.154.4.22" |sort-nr|u Niq-c |sort-n |awk ' {print $ ' = ' $} ' >>/root/bad_ip_tmp.txt
Awk-f "-" '/zmeu/{print} '/var/log/httpd/access_log |grep-v "189.154.4.22" |sort-nr|uniq-c |sort-n ' {print $ 1 "=" $} ' >>/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)
Todo
Num= ' echo $i |awk-f "=" ' {print $} '
Ip= ' echo $i |awk-f ' = ' {print $} '
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. If the task is scheduled to run once in 5 minutes
*/5 * * * */home/kuangl/deny_bad_ip_for_smtp.sh
0 1 * * */etc/init.d/iptables restart
3, view the firewall
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
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Network/Security/