Categories

Archives

What to do when your asterisk is hacked

A hacker concept image of a hand coming throug...

There are various types of malicious hacks on Linux systems. When dealing with Asterisk server, most common one is that of registering a SIP extension from a hacker’s machine and use it to make expensive international calls. This is financially the most damaging and can easily costs in thousands of dollars in a few hours. Unfortunately by the time an admin finds out about it, few hours have already passed, meaning the company has incurred a loss of a few thousand dollars.

To have something like Fail2Ban is a must to avoid this situation. Instructions about it I have in another blog here.

In this blog I am going to suggest what an asterisk system admin should do once his server is hacked, and he has become aware of it. I assume that you do have iptables or some sort of firewall installed. How you become aware of a hack depends upon your understanding of your system. You should know regular call patterns on your server. Hackers start sending tens of calls per second, which is clearly visible both from the asterisk CLI and the CDR. For example if a hacker is trying to call the UK, you’ll see calls with multiple prefixes, e.g. 001144, 0044, 01144, 1144, and so on. The way calls are made makes it very clear that somebody is trying to guess the dial out pattern from your asterisk server.

Another symptom of a hacked server is that genuine extensions go offline and your users can’t make calls. This is because the hackers usually put so much load on the server that Asterisk can’t keep up with the users registrations and can’t serve their requests to make calls.

When you find out that your asterisk is hacked, without panicking, start working on two things: 1) Find out the extension(s) which are being used by the hackers and 2) find out the IP address(es) involved in making these calls. This will take only a few minutes. If you can afford, you can stop the asterisk server using command ‘stop now’ but it’ll also affect your genuine users, so better not do it. You don’t need to give them impression that your service can interrupt their calls, and also don’t need to tell them that your server was hacked, as it will make your customers feel insecure.

To find out which extensions were making these calls, there are various ways to do it, one of which could be to go in to asterisk CLI and look for the active channels:

asterisk -vvvr
set verbose 0
show channels

I set verbose to zero to get an empty screen, otherwise fast scrolling messages will make it impossible to see the output of any command.

By simply looking at the output of ‘show channels’ you should be able to figure out which extension(s) are making suspicious calls. Usually it is one extension which has a lot of international calls attached to it, which obviously a genuine user can’t do. Lets say you figure out that it is extensions 200 and 201.

Now go to your sip.conf or wherever you have your sip users defined, or in case of real-time architecture, open the table which has entries for sip users (default is `sip_buddies`). Here simply change the ‘secret’ for extensions 200 and 201. Once done do a:

sip show peers like 20
sip reload

You can omit ‘sip reload’ which is only partially effective at this stage because it won’t kill the in progress calls, and you’ll have to wait for the registration to time out, but by using ‘sip show peers’ command you’ll get info on the IP addresses which are used to register extensions 200 and 201.

Once you know the IP addresses, block them in the iptables. For example if the bad IP address is 173.194.32.104, do the following:

iptables -I INPUT -s 173.194.32.104 -j DROP

If you can’t use iptables due to any reason, then block the IP address at whatever firewall you have.

If you don’t have any firewall, then you are yourself responsible to harm yourself, don’t blame the hackers. In this case the most effective option is only to restart asterisk:

restart now

which will kill all the calls, including the genuine ones, and restart asterisk. Once restarted, the bad IP address(es) won’t be able to register on asterisk because of the changed SIP secrets.

Once things are in control, contact the users of these extensions and tell them that their sip secrets  have been changed. Tell them to be careful with their sip secrets as their extensions were compromised. As a good practice, use really long and difficult to guess secrets. I would suggest to use 20 character long alphanumeric secrets.

2 people like this post.

Other posts related to this topic

  • Using iptables to secure a Linux based Asterisk installation against hack attempts
    Security of a Asterisk based VoIP server is absolutely necessary when putting it into production. There is an unlimited number of hackers who are all the time looking for insecure Asterisk servers, and once they hack into one, they waste no time...
  • Phone Reminders – Make your life easier
    A phone reminder is a reminder which is sent to you over the phone. It amazingly makes various things in your life more manageable which otherwise would stay mismanaged because you simply forget about them. Life is busy for everyone in this age, an...
  • Using IP tables to secure Linux server against common TCP hack attempts
    In today's world, where the term online security has become almost a joke, we should be more and more careful to whatever extent we can secure our systems which are open to the Internet. TCP/IP suite of protocol which runs the whole Internet was not ...
  • Securing Asterisk – Fail2Ban
    Fail2Ban from www.fail2ban.org is a great tool to block unwanted IP addresses from accessing your server. It works along with iptables, and checks the log files for predefined patterns, and on finding a matching pattern blocks the IP address ...
  • Setup DHCP on Asterisk Server to Assign Static IP Addresses
    Make sure your server's IP address belongs to the subnet defined in DHCP conf....
  • Proxmox and Two Subnets on the Same Network Interface, Properly Routed
    This was a little bit tricky, but thanks to the power of the freely available (though hard to find sometimes) knowledge on the Internet, and Google's searches, I just finished this task and thought to write a blog about it. Though the following is fo...
  • Setup SNMP on an Asterisk server
    SNMP - Simple Network Monitoring Protocol, as it name suggests, is a protocol used to monitor various properties of network equipment. These properties are identified by something called OIDs (Object Identifiers) which are long numeric strings and id...
  • Getting started with AEL
    AEL stands for Asterisk Extensions Language. It is intended to make writing dialplans easier than the standard syntax used in extensions.conf. The standard syntax is not very user friendly, makes it difficult to write complex dialplans, and makes it ...
  • ARP (Address Resolution Protocol) and ARP Poisoning
    ARP is a protocol which is used by the network devices, installed on the Ethernet networks, to find out each other's MAC addresses. If the network devices don't know each other's MAC addresses, they can't communicate with each other on an Ethernet ne...
  • Bash Script to Find All IPs and their Associated MAC addresses on a Network
    One way to accomplish this is to go to each and every desk and see the MAC addresses under the phone, and check in the Windows Control Panel for the computer's network card. And the second way is to do it by pinging all the IP addresses on the networ...

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free