[How to fight against] Massive hacking attempts to hosted PBX

Superspeed

Well-Known Member
Joined
Jan 4, 2010
Messages
301
Reaction score
1
Location
Sandton
Our hosted PBX's have been under attack the last week from Jordan. At one stage we were being hit by up to 5000 hack attempts per hour. This reach a tipping point where they almost managed to get through the last leg of our security measures. They were trying to phone a number in Togo non stop. We phoned that number and turns out its some conference facility that bills you R6 per minute. The only thing that stopped them was our pinsets that we put on our international calls. I STRONGLY suggest you put this on all PBX's - even on site ones.

For Elastix, FreePBX, AsteriskNow and PIAF users do the following:

1) Under settings create a new pinset and call it international. Add a single pin in there with AT LEAST 5 digits.
2) Create a new outbound route and call it "International"
3) Add a dial pattern in: 00.
4) Select pinset "International"
5) Select an appropriate trunk (preferably a prepaid one in case this method also fails)
6) Save and add the International Route to the top of your outbound routes.
7) Make sure your normal route that doesn't have a pin can not phone international routes. Do that by adding only 0ZXXXXXXXX as dial pattern and not 0. or 00.
8) Inform your users/customers what the pin is BY PHONE. Don't email it.

That's it for now. I have new IPTables rules that we put together that I'll post shortly. It makes our PBX invisible to any IP ranges outside of South Africa.

Good luck and be safe. South Africa is under attack. It's not a matter of if - it's when they will hack you if you don't use every possible safety measure available.
 
Last edited:
You can follow this post to ensure your PBX firewall is secured. Do the Fail2Ban part as well - trust me!

https://blog.ls20.com/securing-your-asterisk-voip-server-with-iptables/

Here are the results from our server using this script. The ones marked in bold shows the number of scan attempts with SIP hacking software. This is over a 48 hour period... Scary stuff!


Chain PREROUTING (policy ACCEPT 1703K packets, 176M bytes)
pkts bytes target prot opt in out source destination
0 0 DROP tcp -- eth+ * 0.0.0.0/0 0.0.0.0/0 tcp dpts:5060:5082 recent: UPDATE name: BADSIP side: source
139 102K DROP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 recent: UPDATE name: BADSIP side: source
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "sundayddr" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "sipsak" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "sipvicious" ALGO name bm TO 65535 ICASE
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "friendly-scanner" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "iWar" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ *0.0.0.0/0 tcp dpts:5060:5082 STRING match "sip-scan" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "sipcli" ALGO name bm TO 65535
0 0 BADSIP tcp -- eth+ * 0.0.0.0/0 tcp dpts:5060:5082 STRING match "eyeBeam" ALGO name bm TO 65535
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "sundayddr" ALGO name bm TO 1500
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "sipsak" ALGO name bm TO 1500
28 12288 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "sipvicious" ALGO name bm TO 1500 ICASE
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "friendly-scanner" ALGO name bm TO 1500
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "iWar" ALGO name bm TO 1500
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "sip-scan" ALGO name bm TO 1500
3 2336 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "sipcli" ALGO name bm TO 1500
0 0 BADSIP udp -- eth+ * 0.0.0.0/0 udp dpts:5060:5082 STRING match "eyeBeam" ALGO name bm TO 1500
 
Last edited:
What would have happened if we didn't have pinsets

Can you go back a step and describe what the hack would have achieved if successful?

As you can see from the image below there were thousands of call attempts to some number in Togo. The authenticate part is our PBX asking him to enter the pin for the international route.
hack attempt stopped by pin sets.jpg

If we didn't have that it would have meant they would have used all of the available credit. We fortunately use prepaid so the damage would have been limited to R5000 or so but if you are on post paid.... Well there is no limit to what your damage can be.

This is really extremely serious and all care should be taken to safeguard your systems. If you need us to assist in any manner let me know.We need to protect the integrity and name of the South African VoIP industry.

Btw - the attempts you see here on extension 1001 was with a password that had strong characters - e.g Fdaft421@#?!ddafad1_+35 so using a strong password DOES NOT HELP.
 

Attachments

  • hack attempt stopped by pin sets.jpg
    hack attempt stopped by pin sets.jpg
    23.4 KB · Views: 2,484
Last edited:
Can someone technical share with us how they go about this? Is it a vulnerability exploit in software?

The password of 'Fdaft421@#?!ddafad1_+35' seems very secure and unlikely to be guessable, how did they spoof the password

ED
 
If you're not using fail2ban or similar methods eg iptables rules to prevent brute force attempts, then they can guess a password like that with enough time.
Some attacks are distributed, some are not - so blocking specific ip's doesn't always help.

I'd also use alwaysauthreject=yes in the sip.conf file so that they can't guess account names either.
Probably also a good thing to drop icmp packets so pings don't work also.

Reading logs is also a must, isn't too hard to setup Nagios or similar with some triggers to email you when things look iffy.

This is good advice - http://ipcomms.net/blog/70-11-steps-to-secure-your-asterisk-ip-pbx
 
We are using Fail2Ban, a session border controller, are rejecting anonymous inbound calls, only allow packets from a local IP, use strong passwords, have Asterisk 11.7 running everywhere to avoid exploits and .... they still managed to breach the system.
 
From the screenshots it looks like you are running freepbx?

Why is it absolutely necessary for your system to be access via public network?

Have you changed the common ports on the system to random port SIP SSH etc ?
 
The relevance of SIP Domains

When a SIP request is sent to your Asterisk server, the main header should contain a Request URI (or R-URI) that looks somewhat like one of the following:

sip:[email protected]
sip:[email protected]
sip:[email protected]

In each case, the destination is defined as a number then the @ symbol and finally the “SIP domain”. In the first two examples, the SIP domain is given as a host name and would have to be resolvable by public DNS servers to be useful. In the third example, the sip domain is given as an IP address – it would therefore need to match the IP address of your Asterisk server (or perhaps the external, or WAN, IP address of your NAT router if behind NAT).

Asterisk can be configured to be indifferent to SIP domains or you can specify a list of “allowed” domains that it will support.
A benefit of SIP domains

Activating support for SIP Domains in Asterisk can give you one more layer of security, but it will only be effective if you can:

Avoid having your PBX’s Internet IP address as one of the domains, and
Set the parameter allowexternaldomains = no

Doing both of the above will cause Asterisk to reject all SIP requests where the R-URI is using the external IP address of the PBX rather than a legitimate SIP domain – one that you have configured and approved. Since most hacking attempts are based on IP address only, this could be a useful extra layer of protection for your server.
A potential pitfall with SIP domains

Every silver lining has a cloud and so it is with SIP domains. All the advice offered in part 2 about checking which dial plan will be used for inbound calls can be rendered invalid if you have defined a sip domain with the additional optional parameter, context, appended on the end. For example:
sip.conf
[general]
domain=mysipdomain.com,mycontext

Any request sent to your Asterisk server where the R-URI is using the above sip domain, will use the dial plan configured for the context called mycontext. I would recommend avoiding using the additional parameter when defining a sip domain in Asterisk because it could act like a hidden back-door that is easy to overlook.
Automated-Attendants, DISA and other risks

The vulnerabilites discussed so far have mostly involved quite technical weaknesses, especially related to malicious SIP requests arriving over the Internet. However, it is also possible to leave the door open for mis-use through the menus and options that are offered to ordinary callers. Features that are very convenient for legitimate users can provide a route in for hackers, especially if weak passwords have been used. You would be ill advised to assume that a “hidden” menu option known only to employees will never be found by a potential hacker – there are only 12 keys on a telephone key pad so it doesn’t take much effort to try all twelve at various points in the caller menus.

Areas to watch include Automated-Attendants, voicemail access, follow-me and call forwarding options, DISA or any similar trunk-to-trunk callout feature.
Protecting against Denial of Service attacks

Asterisk is good at many things, but handling a lot of simultaneous requests is not one of them. It would be relatively easy to overwhelm most Asterisk servers by bombarding them with a lot of SIP requests in a short space of time. Restricting access at the firewall is the best solution because it stops the requests before they reach Asterisk, but it is not always an option. Correct use of security parameters within Asterisk such as “allowexternaldomains” and “allowguest” can help deflect unauthorised requests before they demand too much processing, but once again it may not always be possible to use them. So how might it be possible to protect your Asterisk servers against Denial of Service attacks if the aforementioned options are not available or are not adequate?
OpenSIPS as an intelligent firewall

One possibility would be to use an OpenSIPS server as a barrier between the Internet and Asterisk. OpenSIPS is able to handle much greater demands in terms of requests per minute and is also able to inspect SIP requests in great detail to determine if they are valid or malicious. In this scenario, the OpenSIPS server would be accessible from any address on the Internet, but the Asterisk server would only accept connections from the OpenSIPS server. This configuration also has the advantage of being scalable – if one Asterisk server is not enough, you can add more behind a single OpenSIPS server which will load balance requests across all the Asterisk servers.
Fail2ban

Another option to consider is the use of Fail2ban or a similar add-on product. Fail2ban is an open-source product that will dynamically modify the rules in an iptables (or similar) firewall based on the number and frequency of unauthorised access attempts made from a given remote address. It works by constantly monitoring the Asterisk log file – or other log file – to identify brute force attacks. Parameters can be configured to adjust settings such as how long to block the remote address, how many failures before it should be blocked, etc. It comes with standard rule sets and templates that will work with a number of commonly used applications, but you can also configure your own rule sets to cope with unsupported applications.

Link: Click here to visit the Fail2ban web site.
Stopping a “friendly-scanner” DoS attack

One form of attack that has been widely reported (and which may even be made more likely if you use settings such as “alwaysauthreject=yes”) is an intense and endless stream of REGISTER requests sent from one source address on the Internet and using the “friendly-scanner” user agent name.
Summing up

The level of risk has certainly intensified in the last year or possibly even the last few months and there is little doubt that the unwary will get caught and will end up paying for someone else’s phone calls to weird and unlikely destinations like North Korea or Ethiopia. Once an unsecured PBX has been found, it is likely to be hit with hundreds of expensive calls and very large bills can be run up in a matter of hours. This is not a problem to be taken lightly – it could even sink a small business.

You cannot seriously expect protection or redress from the authorities or the Telcos – you would be extremely lucky to get more than passing sympathy from either. Protecting your PBX is therefore up to you, your PBX maintainer and IT support team. If all Asterisk PBX’s were locked down and properly protected then the hackers would soon lose interest and look for other ways to make money, so make it as difficult for them as you can. Make sure all your passwords are very strong, that you have set “alwaysauthreject” to yes and check all the other points raised in these articles.
 
From the screenshots it looks like you are running freepbx?

Why is it absolutely necessary for your system to be access via public network?

Have you changed the common ports on the system to random port SIP SSH etc ?

That is correct. These are hosted PBX's so they have to be public facing. We block access to port 22,80 and the rest for IP's outside of South Africa.

Changing port 22 doesn't help really - if they know your IP it is very easy to scan and exploit it regardless of the SSH port. I have a detailed article about that somewhere. I'll have a look to see if I can find it.
 
Hey Superspeed.

dont forget to firewall 443, its also open for web traffic.

One more thing to consider with public facing systems.
I have had issues with freepbx security vulnerabilities in the frontend allowing crafty attacker access to frontend and from there, password views/changes.

If you are running fail2ban on sip auth failures, chances are it was not brute force and your apache logs will show you some entry point.

To be extra paranoid, added the following to /etc/httpd/conf/httpd.conf at the end of the Director block:
Code:
<Directory "/var/www/html">

Code:
        AuthName "prevent remote access to this site, please enter valid login!"
        AuthType Basic
        AuthUserFile /var/www/.htpasswd
       AuthGroupFile /dev/null
        require user superspeed

once thats done, just put in a file at /var/www/.htpasswd with a valid password entry for superspeed.

This should stop any attempts at frontend vulnerabilities too.
 
That is correct. These are hosted PBX's so they have to be public facing. We block access to port 22,80 and the rest for IP's outside of South Africa.

Changing port 22 doesn't help really - if they know your IP it is very easy to scan and exploit it regardless of the SSH port. I have a detailed article about that somewhere. I'll have a look to see if I can find it.

Hello Superspeed, I am the author of the PBX security article you mentioned. Just want to add my comment here on how to block those open port scanners from your server (e.g. hide your new SSH port). This can be done via the "psd" module from "xtables-addons" which extends the functionality of IPTables. There are also other useful modules such as "geoip" (i.e. allow/block entire countries via IPTables).

For details on how to set this up, please follow the link in the 2nd post, click on the blog title on top, and then see the article titled "IPTables GeoIP, Port Knocking and Port Scan Detection".
 
Hey Superspeed.

dont forget to firewall 443, its also open for web traffic.

One more thing to consider with public facing systems.
I have had issues with freepbx security vulnerabilities in the frontend allowing crafty attacker access to frontend and from there, password views/changes.

If you are running fail2ban on sip auth failures, chances are it was not brute force and your apache logs will show you some entry point.

To be extra paranoid, added the following to /etc/httpd/conf/httpd.conf at the end of the Director block:
Code:
<Directory "/var/www/html">

Code:
        AuthName "prevent remote access to this site, please enter valid login!"
        AuthType Basic
        AuthUserFile /var/www/.htpasswd
       AuthGroupFile /dev/null
        require user superspeed

once thats done, just put in a file at /var/www/.htpasswd with a valid password entry for superspeed.

This should stop any attempts at frontend vulnerabilities too.

Thanks for this! Will do.
 
Hello Superspeed, I am the author of the PBX security article you mentioned. Just want to add my comment here on how to block those open port scanners from your server (e.g. hide your new SSH port). This can be done via the "psd" module from "xtables-addons" which extends the functionality of IPTables. There are also other useful modules such as "geoip" (i.e. allow/block entire countries via IPTables).

For details on how to set this up, please follow the link in the 2nd post, click on the blog title on top, and then see the article titled "IPTables GeoIP, Port Knocking and Port Scan Detection".

Hi Howard. Thank you so much for your contribution. We appreciate it more than you can imagine!
 
Top
Sign up to the MyBroadband newsletter
X