text
stringlengths
0
152
24 hours. If the host attacks again, they’ll be blocked again.
Oh, you might also want to tell it to ignore your IP (or any other IP addresses that are
OK to receive connection attempts from). If you haven’t yet accidentally gotten your‐
self blocked because you were doing some lab work and misregistering, don’t worry,
you will eventually do this to yourself (unless, of course, you create an ignore list for
appropriate IPs).
[DEFAULT]
ignoreip = <ip address(es), separated by commas>
[asterisk]
enabled = true
filter = asterisk
action = iptables-allports[name=ASTERISK, protocol=all]
sendmail[name=ASTERISK, dest=me@shifteight.org, sender=fail2ban@shifteight.org]
logpath = /var/log/asterisk/messages
/var/log/asterisk/security
maxretry = 5
findtime = 21600
bantime = 86400
Restart Fail2ban and you’re good to go.
$ sudo systemctl reload fail2ban
Test it out if you can, from an IP address you don’t mind being blocked (for example,
an extra computer in your lab that can be the test subject for this). Attempt to register
using bad credentials, and after five attempts (or whatever you set maxretry to), that
IP should be blocked.
You can see what addresses the Asterisk jail is blocking with the command:
$ sudo fail2ban-client status asterisk
370
|
Chapter 22: Security
And if you want to unblock an IP,2 the following command should do so.
$ sudo fail2ban-client set asterisk unbanip ip to unban
More information about Fail2ban can be found at the Fail2ban wiki.
Encrypted Media
While we gave examples in this book that used encryption, be aware that you can
configure SIP so that media will be sent unencrypted. In that case, anyone intercept‐
ing the RTP traffic between two SIP peers will be able to use fairly simple tools to
extract the audio from those calls.
Dialplan Vulnerabilities
The Asterisk dialplan is another area where taking security into consideration is criti‐
cal. The dialplan can be broken down into multiple contexts to provide access control
to extensions. For example, you may want to allow your office phones to make calls
out through your service provider. However, you do not want to allow anonymous
callers that come into your main company menu to be able to then dial out through
your service provider. Use contexts to ensure that only the callers you intend have
access to services that cost you money.
Build dialplan contexts with great care. Also, avoid putting any
extensions that could cost you money in the [default] context.
One of the more recent Asterisk dialplan vulnerabilities to have been discovered and
published is the idea of dialplan injection. A dialplan injection vulnerability begins
with an extension that has a pattern that ends with the match-all character, a period.
Take this extension as an example:
exten => _X.,1,Dial(PJSIP/otherserver/${EXTEN},30)
The pattern for this extension matches all extensions (of any length) that begin with a
digit. Patterns like this are pretty common and convenient. The extension then sends
this call over to another server using the IAX2 protocol, with a dial timeout of 30 sec‐
onds. Note the usage of the ${EXTEN} variable here. That’s where the vulnerability
exists.
2 For example, yourself, because you forgot to define ignoreip...
Encrypted Media
|
371
In the world of Voice over IP, there is no reason that a dialed extension must be
numeric. In fact, it is quite common using SIP to be able to dial someone by name.
Since it is possible for non-numeric characters to be a part of a dialed extension, what
would happen if someone sent a call to this extension?
1234&DAHDI/g1/12565551212
A call like this is an attempt at exploiting a dialplan injection vulnerability. In the pre‐
vious extension definition, once ${EXTEN} has been evaluated, the actual Dial()
statement that will be executed is:
exten => _X.,1,Dial(PJSIP/otherserver/1234&DAHDI/g1/12565551212,30)
If the system has a PRI configured, this call will cause a call to go out on the PRI to a