text stringlengths 0 152 |
|---|
number chosen by the attacker, even though you did not explicitly grant access to the |
PRI to that caller. This problem can quickly cost you a whole lot of money. |
There are several approaches to avoiding this problem. The first and easiest approach |
is to always use strict pattern matching. If you know the length of extensions you are |
expecting and expect only numeric extensions, use a strict numeric pattern match. |
For example, this would work if you are expecting four-digit numeric extensions |
only: |
exten => _XXXX,1,Dial(PJSIP/otherserver/${EXTEN},30) |
Another approach to mitigating dialplan injection vulnerabilities is by using the FIL |
TER() dialplan function. Perhaps you would like to allow numeric extensions of any |
length. FILTER() makes that easy to achieve safely: |
exten => _X.,1,Set(SAFE_EXTEN=${FILTER(0-9A-F,${EXTEN})}) |
same => n,Dial(PJSIP/otherserver/${SAFE_EXTEN},30) |
For more information about the syntax for the FILTER() dialplan function, see the |
output of the core show function FILTER command at the Asterisk CLI. |
A more comprehensive (but also complex) approach might be to have all dialed digits |
validated by functions outside of your dialplan (for example, database queries that |
validate the dialed string against user permissions, routing patterns, restriction tables, |
and so forth). This is a powerful concept, but beyond the scope of this book. |
Be wary of dialplan injection vulnerabilities. Use strict pattern |
matching or use the FILTER() dialplan function to avoid these |
problems. |
372 |
| |
Chapter 22: Security |
Securing Asterisk Network APIs |
To secure AGI, AMI, and ARI, you will need to carefully consider the following rec‐ |
ommended practices: |
• Only allow connections directly to the API from localhost/127.0.0.1. |
• Use an appropriate framework in between the Asterisk API and your client appli‐ |
cation, and handle connection security through the framework. |
• Control access to the framework and the system through strict firewall rules. |
Beyond that, the same sort of security rules and best practices apply that you would |
follow in any mission-critical web application. |
Other Risk Mitigation |
There are other useful features in Asterisk that can be used to mitigate the risk of |
attacks. The first is to use the permit and deny options to build access control lists |
(ACLs) for privileged accounts. Consider a PBX that has SIP phones on a local net‐ |
work, but also accepts SIP calls from the public internet. Calls coming in over the |
internet are only granted access to the main company menu, while local SIP phones |
have the ability to make outbound calls that cost you money. In this case, it is a very |
good idea to set ACLs to ensure that only devices on your local network can use the |
accounts for the phones. |
In your ps_endpoints table, the permit and deny options allow you to specify IP |
addresses, but you can also point to a label in the /etc/asterisk/acl.conf file. In fact, |
ACLs are accepted almost everywhere that connections to IP services are configured. |
For example, another useful place for ACLs is in /etc/asterisk/manager.conf, to restrict |
AMI accounts to the single host that is supposed to be using the manager interface. |
ACLs can be defined in /etc/asterisk/acl.conf. |
[named_acl_1] |
deny=0.0.0.0/0.0.0.0 |
permit=10.1.1.50 |
permit=10.1.1.55 |
[named_acl_2] ; Named ACLs support IPv6, as well. |
deny=:: |
permit=::1/128 |
[local_phones] |
deny=0.0.0.0/0.0.0.0 |
permit=192.168.0.0/255.255.0.0 |
Once named ACLs have been defined in acl.conf, have Asterisk load them using the |
reload acl command. Once loaded, they should be available via the Asterisk CLI: |
Securing Asterisk Network APIs |
| |
373 |
*CLI> module reload acl |
*CLI> acl show |
acl |
--- |
named_acl_1 |
named_acl_2 |
local_phones |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.