| Configure fail2ban for Asterisk (CentOS 5) |
|
|
|
| News - Ubuntu / Linux / Unix | ||||||||||||||||||||||||||||||||
| Written by Mark Veenstra | ||||||||||||||||||||||||||||||||
| Friday, 07 January 2011 18:16 | ||||||||||||||||||||||||||||||||
|
Fail2Ban is a limited intrusion detection/prevention system. It works by scanning log files and then taking action based on the entries in those logs. In here a will show you howto configure Fail2Ban for Asterisk. I will implement Fail2Ban with a configuration to be able to prevent SIP brute force attacks against your Asterisk PBXs. You can get Fail2Ban, as well as more documentation, at www.fail2ban.org. At the time this is being written, the current release is 0.8.4.
Requirements Execute the following command as root on your Asterisk server.
If your CentOS doesn't find the package, please execute the following command and then try again.
Make sure python and iptables is installed on your server.
Configure Fail2Ban for Asterisk First we need to create a configuration file for Fail2Ban so it can understand the logfiles of Asterisk and get IP addresses from it to ban. Create the configuration as follows.
Fill this configuration with the followin text.
Next edit /etc/fail2ban/jail.conf
Add the following section so that it uses the new filter. This example does a 3-day ban (set to -1 for always ban) on the IP that performed the attack (bantime). It is recommend to set the bantime in the [DEFAULT] section so if affects all attacks. It is also recommend to turn on an iptables ban for ssh, httpd/apache, and ftp if they are running on the system. Be sure to edit the sendmail-whois action to send notifications to an appropriate address.
Note that you logpath can be different depending an your solution. You can check it in the file /etc/asterisk/logger.conf. Exclude yourself from being banned; by opening the jail.conf.
Add your IP addresses and every other IP adres you want to be ignored into the ignore sections, for example.
Asterisk logging We must change how Asterisk does its time stamp for logging. The default format does not work with Fail2Ban because the pattern Fail2Ban uses that would match this format has a beginning of line character (^), and Asterisk puts its date/time inside of []. The other formats that Fail2Ban supports, however, do not have this character and can be used with Asterisk.
Add the following line under [general] section (You may have to create this before the [logfiles] section). This causes the date and time to be formatted as Year-Month-Day Hour:Minute:Second, [2008-10-01 13:40:04] for example.
Then reload the logger module for Asterisk. At the command line of your Asterisk server, run the following command as root:
Finalize your setup If iptables is not running yet start it. (You need to be root)
Then start Fail2Ban as follows (only for the user root)
Check your installation If iptables and fail2ban started properly, please execute the next command.
You should see something like the following for the INPUT chain (you will see more if you have other Fail2Ban filters enabled):
If you do not see something similar to that, then you have some troubleshooting to do; check out /var/log/fail2ban.log. |
||||||||||||||||||||||||||||||||
| Last Updated on Friday, 07 January 2011 18:56 |




Click here to hear this article
Comments
Perhaps a last thing to add is add this two instructions for having iptables and fail2ban started at reboot
Thanks