Categories

Archives

Using IP tables to secure Linux server against common TCP hack attempts

hackattempt

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 designed as a secure system of protocols. There are so many security holes and exploits in it that no one can probably ever close and overcome them all. Its a constant cat and mouse game between the security exploiters and security [...]

What to do when your asterisk is hacked

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 [...]

Securing Asterisk - Fail2Ban

windows

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 which is responsible to generate that pattern.

Every asterisk installation must have this tool installed to secure it against unwanted SIP registration attempts, which is the most common type of attack on asterisks servers. This one security measure alone is enough to make your asterisk server secure. Here I’ll describe how to do it. These instructions I have primarily taken from voip-info.org (http://ilovetovoip.com/QQ).

After installing fail2ban, create a file called asterisk.conf in the fail2ban filters folder:

touch /etc/fail2ban/filter.d/asterisk.conf

Now add the following in this file:

# Fail2Ban configuration file
#
#
# $Revision: 250 $
#

[INCLUDES]

# Read common prefixes. If any customizations available — read them from
# common.local
#before = common.conf

[Definition]

#_daemon = asterisk

# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named “host”. The tag “<HOST>” can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>\S+)
# Values: TEXT
#

failregex = NOTICE.* .*: Registration from ‘.*’ failed for ‘<HOST>’ – Wrong password
NOTICE.* .*: Registration from ‘.*’ failed for ‘<HOST>’ – No matching peer found
NOTICE.* .*: Registration from ‘.*’ failed for ‘<HOST>’ – Username/auth name mismatch
NOTICE.* .*: Registration from ‘.*’ failed for ‘<HOST>’ – Device does not match ACL
NOTICE.* <HOST> failed to authenticate as ‘.*’$
NOTICE.* .*: No registration for peer ‘.*’ \(from <HOST>\)
NOTICE.* .*: Host <HOST> failed MD5 authentication for ‘.*’ (.*)
NOTICE.* .*: Failed to authenticate user .*@<HOST>.*

# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#

ignoreregex =

In the above lines you can see that fail2ban will look for the pharases: “Wrong password”, “No matching peer found”, “Username/auth name mismatch” and “Device does not match ACL”.

Next add the following lines in /etc/fail2ban/jail.conf

[asterisk-iptables]

enabled = true
filter = asterisk
action = iptables-allports[name=ASTERISK, protocol=all]
sendmail-whois[name=ASTERISK, dest=root, sender=fail2ban@example.org]
logpath = /var/log/asterisk/full
maxretry = 5
bantime = 259200

This filter will ban the bad IPs for three days, i.e. 259200 seconds.

DON’T BAN YOURSELF

Make sure you don’t ban your own IP address. For this purpose edit /etc/fail2ban/jail.conf and add your IP address in the ignoreip list under the [DEFAULT] [...]

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 to compromise it for making expensive phone calls. It takes merely a few minutes to generate enough calls to cause a few hundred dollars worth of damage to the owner of a compromised server. Usually it takes a few hours before the owner of the server notices that something fishy is going on, but by that time the loss can already be a few thousand dollars.

There are various measures to secure a Linux server. As for the Asterisk part, international calling and expensive destinations MUST be disabled for all the new users by default, and only trusted users should be allowed to dial these destinations. This way even if such a server is compromised, the loss will be minimal.

Here we’ll discuss how to use Linux’s built-in firewall, which is called iptables, to secure a Linux server.

You should know that TCP/IP networks are very innocent and assume other people in the world are also equally innocent, and so they are not aware of bad hackers, criminals and similar inhabitants of the world. They welcome all the network traffic with open heart and offer them the best hospitality which they can.

This means that all the Linux servers are wide open to the network traffic by default and their network connections are completely insecure. They accept all the traffic on all the ports from all the IP addresses, and respond to all the requests.

Blocking access for all except for the selected ones

If the server doesn’t need to be accessed by everybody and only a selected few IPs or networks should be able to access it, then the first step should be to block ALL the network traffic. This must be done while logged onto the server locally, and not remotely, otherwise you would block your own self too.

iptables -P INPUT DROP

Next, allow the IP addresses which you would like to access the server, e.g. to give access to google.com at 173.194.32.104 do this:

iptables -I INPUT -s 173.194.32.104 -j ACCEPT

If you don’t have access to the server locally, and you are logged in via ssh or telnet, then you can do the following:

iptables -A INPUT -s ! 173.194.32.104 -j DROP

This will drop all incoming network traffic except from the given IP address. But be careful when using this command, because a mistake in the IP address will lock you out from the system.

If you want to allow your local network to access the server, and network address is 192.168.1.0 with netmask of 255.255.255.0, do this:

iptables -I INPUT -i eth1 -s 192.168.1.0/24 -j ACCEPT

If you have multiple network interfaces and you want to apply iptables rules to only selected one(s), do it like this, e.g. for eth0 it’ll be:

iptables -I INPUT -i eth0 -s 173.194.32.104 -j ACCEPT

Blocking access for SIP [...]

VoIP Security and Possible Threats

I once did some research on VoIP based security threats and the results were surprising to me. Despite being a VoIP professional, even I was not aware of these tricks to exploit this wonderful technology. It is amazing how some human minds can find ways to misuse anything they can find to harm others.

Now that VoIP is all around us, it is absolutely necessary that we all know how VoIP can hurt us. Whether we use it or not, it is using us anyways.

Based on my finding, the threats can be divided into following categories.

Caller ID Spoofing

Toll Fraud

Vishing
Eavesdropping
Call Hijacking
Injected Messages

1. Caller ID Spoofing
Make a call seem originate from a different number

Attackers can call with a caller ID information to make it appear that their calls originate from elsewhere. They can make themselves appear calling from your bank, employer, neighbor, relative, etc. and steal  personal information from you. Unfortunately, lately it has become so easy to spoof caller ID, that almost anyone with a VoIP service, who wants to do it, can do it. Seems like regulatory authorities have no interest in controlling it. Many small VoIP service providers provide you with this service, that you can log into your account online and change your outgoing caller ID and name.

Even if a VoIP service provider doesn’t allow it, the attackers can still send a caller ID of their own and it’ll fool most of the VoIP systems and successfully reach the called party.

HOW TO PROTECT YOURSELF:

As an end user, if it is a call from your bank, credit card company, insurance company, or any source which involves money matters, and you don’t recognize the person on the other end. Tell them that you’ll call them back, hangup, and call them back on a valid number from your bank statement, back of your card, invoice, bill, etc.
Even if you recognize the number, you might be a victim of caller ID spoofing. So when you hang up and call the same number back, it’ll not go back to the attacker but go to the real person, unless it is a case of call hijacking, in which case you really can’t do anything.

If you are a VoIP system administrator:

Never authenticate calls based on caller IDs.
Two privacy SIP headers were added to the SIP protocol for authentication purposes, which many VoIP companies don’t use due to their complexity, but it is important to use them on SIP proxy servers to avoid caller ID spoofing.

2. Toll Fraud
Making calls using your information

Hackers are always trying to gain access to not well secured VoIP networks and allow unauthorized users to make repeated long distance calls, especially to international destinations. VoIP systems are particularly vulnerable to toll fraud because they form an integral part of an enterprise’s IP network. Toll fraud causes serious financial damages every year, in millions of dollars to small VoIP companies in North America.

HOW TO PROTECT YOURSELF:

Don’t provide your VoIP hardware or account log in info to anybody
If someone is hacked into the providers [...]