Hey Wazo Enthusiast,
why do attackers have interest to attack your PBX? Making money is the biggest I guess, dialing expensive foreign country or service numbers etc. They try to find out which extensions are enabled with spamming INVITEs.
When I started off and accessed the asterisk console (asterisk -rvc, pjsip set logger on), I got several malicious invites per second.
My first ban attempts got me lists of 50+ IP addresses on ban. The attackers also try different methods.
I did a lot of research to secure my server with fail2ban without using a proxy and want to share with you a compact set of results.
Letâs tighten our firewall. I use fail2ban in conjunction with iptables. First thing you want to do is adding extra security output into the log:
In â/etc/asterisk/logger.d/01-wazo.confâ add âsecurityâ output to fail2ban like this:
fail2ban => notice,security
Now open â/etc/fail2ban/filter.d/asterisk-wazo.confâ and extend the failregex = with following line:
SecurityEvent="ChallengeSent".AccountID="<unknown>".\/UDP\/<host>\/.*,Challenge=""
Registrated users have valid AccountIDs so when it is unknown, somebody attempts to guess himself in.
If we have âtrue friendsâ, we can also enable the recidive jail.
/etc/fail2ban/jail.d/recidive.conf
[recidive]
enabled = true
Now from time to time there is a false positive which forces you to unban manually. This is no option with production servers, so I decided to get a whitelist in place. Whenever a user logs in successfully, his IP will be whitelisted for a day (ignorelist on fail2ban). We need several files for that. On windows please check twice, that you use LF for Line-Breaks when you copy paste from here, otherwise fail2ban will fail.
/etc/fail2ban/filter.d/wazo-whitelist.conf
[Definition]
failregex = SecurityEvent=âSuccessfulAuthâ.AccountID="[a-z0-9]{8}"./UDP//.*,UsingPassword=â1â
ignoreregex =
/etc/fail2ban/action.d/ipwhitelist.conf
[Definition]
actioncheck = iptables -nL | grep -q âf2b-ASTERISK[ \t]â
actionban = fail2ban-client set <name> addignoreip <ip>
#fail2ban-client set recidive addignoreip <ip>
actionunban = fail2ban-client set <name> delignoreip <ip>
#fail2ban-client set recidive delignoreip <ip>
[Init]
name = default
chain = INPUT
/etc/fail2ban/jail.d/wazo-whitelist.conf
[wazo-whitelist]
enabled = true
port = all
action = ipwhitelist[name=asterisk-wazo]
logpath = /var/log/asterisk/fail2ban
maxretry = 1
bantime = 1d
When you are done and saved everything,
fail2ban-client restart
wazo-service restart
I hope I got everything important covered. Otherwise please ask. Enjoy the silence