How to use Shell to prevent mail from brute force

Source: Internet
Author: User
Tags log mail sort iptables firewall

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.