GenerationIP

Just for you

  • Increase font size
  • Default font size
  • Decrease font size
Home Documentation Mini Howto Use Fail2Ban to contact the IP provider's of bruteforce attacks source

Use Fail2Ban to contact the IP provider's of bruteforce attacks source

E-mail Print PDF
User Rating: / 4
PoorBest 

Type : System
Operating System : Linux

Fail2ban is a very useful and powerful solution to limit the bruteforce on your server. but fail2ban doesn't provide you a way to contact directly the IP provider's of bruteforce attacks source. I have modify an fail2ban action file's and create a script for that.

INSTALLATION

Go to the fail2ban action folders :

# cd /etc/fail2ban/action.d

Copy an existant file :

# cp mail-whois-lines.conf mail-whois-autosend-line.conf

Edit the file and change the actionban line like that :

# vim mail-whois-autosend-line.conf

...

actionban = /etc/fail2ban/action.d/mail-whois.sh <ip> <name> <logpath> <failures> <dest>

...

Don't forget to customize the end of this file.

Now you have to create mail-whois.sh script :

# vim mail-whois.sh

for i in `whois $1 | perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}' | sort | uniq` "$5"; do echo "Hi,

The IP $1 has just been banned by Fail2Ban after $4 attempts against $2.
Here are more information about $1:

 `whois $1`


Lines containing IP: $1 in $3

 `grep $1 $3`


Regards,
Fail2Ban"|mail -s "[Fail2Ban] $2: banned $1" $i; done;

Activate execution right:

# chmod 750 mail-whois.sh

Now you have to edit jail.conf present in your fail2ban folder to change the mail action :

[ssh-iptables]

enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
mail-whois-autosend-line[name=SSH, dest=root, sender=root]
logpath  = /var/log/secure
maxretry = 5


Last Updated on Wednesday, 10 February 2010 22:42  

Share this article:

Add to: Mr. Wong Add to: Webnews Add to: Icio Add to: Oneview Add to: Kledy.de Social Bookmarking Add to:  FAV!T Social Bookmarking Add to: Favoriten.de Add to: Seekxl Add to: Social Bookmark Portal Add to: BoniTrust Add to: Power-Oldie Add to: Bookmarks.cc Add to: Newskick Add to: Newsider Add to: Linksilo Add to: Readster Add to: Yigg Add to: Linkarena Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: Jumptags Add to: Upchuckr Add to: Simpy Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Diigo Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Ma.Gnolia Add to: Smarking Add to: Netvouz Add to: Folkd Add to: Spurl Add to: Google Add to: Blinklist Information