{"id":177,"date":"2020-02-12T01:31:47","date_gmt":"2020-02-12T01:31:47","guid":{"rendered":"https:\/\/blog.lns.com\/?p=177"},"modified":"2020-05-03T23:03:37","modified_gmt":"2020-05-03T23:03:37","slug":"protecting-your-asterisk-pbx","status":"publish","type":"post","link":"https:\/\/blog.lns.com\/?p=177","title":{"rendered":"Protecting your Asterisk PBX&#8230;"},"content":{"rendered":"<p><em>Disclaimer:\u00a0 This is likely not everything you should do in securing your FreePBX box, but it is a good starting point.\u00a0 \u00a0It is meant to limit your exposure to the public Internet, but this doesn&#8217;t cover exploits that can happen after you lock that down such as from address space you are allowing.\u00a0 Having good credentials, among other security measures is also expected.<\/em><\/p>\n<p><a href=\"https:\/\/www.freepbx.org\/\">FreePBX<\/a>&#8216;s GUI makes setting up <a href=\"https:\/\/www.asterisk.org\/\">Asterisk<\/a> a breeze.\u00a0 This is a great product that\u00a0Sangoma has been supporting for a while.\u00a0 You can get the main package at <a href=\"https:\/\/www.freepbx.org\/downloads\/freepbx-distro\">https:\/\/www.freepbx.org\/downloads\/freepbx-distro<\/a>\u00a0for running on your own server or VM.\u00a0 I am running <a href=\"http:\/\/www.raspberry-asterisk.org\/\">RasPBX<\/a> that is a slightly slimmed down version that runs very nicely on a Raspberry Pi.<\/p>\n<p>The packages are built on a Debian-based Linux but have some exposure that one needs to do to really lock it down.\u00a0 There are a bunch of applications that are on FreePBX that are listening and waiting for the rest of the Internet to exploit them.\u00a0 You can easily see them by running the command &#8220;lsof -i | grep LISTEN&#8221;.\u00a0 You may see something like:<\/p>\n<pre class=\"p1\"><span class=\"s1\">root@asterisk:\/etc\/network# lsof -i | grep LISTEN<\/span>\r\n<span class=\"s1\">sshd<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>612<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>3u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4 <span class=\"Apple-converted-space\">\u00a0 <\/span>10163<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:ssh (LISTEN)<\/span>\r\n<span class=\"s1\">sshd<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>612<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>10165<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:ssh (LISTEN)<\/span>\r\n<span class=\"s1\">mysqld <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>1149 <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>mysql <span class=\"Apple-converted-space\">\u00a0 <\/span>10u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4 <span class=\"Apple-converted-space\">\u00a0 <\/span>10996<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:mysql (LISTEN)<\/span>\r\n<span class=\"s1\">exim4<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>1592 Debian-exim<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4 <span class=\"Apple-converted-space\">\u00a0 <\/span>11165<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:smtp (LISTEN)<\/span>\r\n<span class=\"s1\">exim4<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>1592 Debian-exim<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>5u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>11166<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:smtp (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>1971<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>13u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>15624<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:omniorb (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>1971<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>14u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>15625<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:8089 (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>1971<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>15u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4 <span class=\"Apple-converted-space\">\u00a0 <\/span>13884<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:5038 (LISTEN)<\/span>\r\n<span class=\"s1\">node <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>6868<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>13u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 2435746<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:8001 (LISTEN)<\/span>\r\n<span class=\"s1\">node <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>6868<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>14u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 2435747<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:8003 (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>24214<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>10221<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:http (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>24214<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>6u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>10225<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:https (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>24215<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6 <span class=\"Apple-converted-space\">\u00a0 <\/span>10221<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:http [...]<\/span>\r\n\r\n<span class=\"s1\">root@asterisk:\/etc\/network# <\/span><\/pre>\n<p>The first column shows the application that is bound and listening to that port.\u00a0 The last column shows the protocol, what IP address it is bound to and what port.\u00a0 Anything that shows &#8220;*:&#8230;&#8221; means it is listening to all IP addresses on the server.\u00a0 Anything that shows &#8220;localhost:&#8230;&#8221; means it is listening to a local IP address and is not exposed to the public Internet.<\/p>\n<p>So what are these applications and why do they need to be open to the net?\u00a0 The first one is &#8220;sshd&#8221; which you likely are using to log into the server with.<\/p>\n<p>&#8220;<a href=\"https:\/\/www.mysql.com\">mysqld<\/a>&#8221; is the daemon for the MySQL database that FreePBX uses for configuration and it is bound to the &#8220;localhost&#8221; so no worry here.\u00a0 If it isn&#8217;t you can s<span class=\"s1\">ee\u00a0<a href=\"https:\/\/serversforhackers.com\/c\/mysql-network-security\">https:\/\/serversforhackers.com\/c\/mysql-network-security<\/a> for a guide on how to lock down MySQL.<\/span><\/p>\n<p>&#8220;<span class=\"s1\"><a href=\"https:\/\/www.exim.org\">exim4<\/a>&#8221; is a mail server.\u00a0 Normally this is used for delivery of mail to users when there is voicemail or there is a report that needs to be mailed out to an administrator.\u00a0 <\/span><\/p>\n<p><span class=\"s1\">&#8220;asterisk&#8221; has a number of ports open.\u00a0 The &#8220;omniorb&#8221; port really is port &#8220;8088&#8221;.\u00a0 You can see this in the file \/etc\/services.\u00a0 The 8089 port is used by the same feature in Asterisk.\u00a0 This is the &#8220;<a href=\"https:\/\/wiki.asterisk.org\/wiki\/display\/AST\/Asterisk+GUI\">Asterisk GUI<\/a>&#8221; framework.\u00a0 FreePBX uses this for interaction with Asterisk.\u00a0 It really should be locked down to the localhost IP address.\u00a0 \u00a0 You can change this to the localhost IP address of &#8220;127.0.0.1&#8221; in FreePBX&#8217;s &#8220;Settings&#8221; -&gt; &#8220;Advance Settings&#8221; tab.\u00a0 Change the HTTP and HTTPS bind address entries for these ports and click on &#8220;Submit&#8221; and then &#8220;Apply Config&#8221;.\u00a0 Port\u00a05038 is used for the <a href=\"https:\/\/wiki.asterisk.org\/wiki\/display\/AST\/The+Asterisk+Manager+TCP+IP+API\">API<\/a> for Asterisk.\u00a0 By the default config, it is already bound to locahost \/ 127.0.0.1.<\/span><\/p>\n<p>&#8220;node&#8221; that is listening on ports 8001 and 8003 is the FreePBX\u00a0<a href=\"https:\/\/git.freepbx.org\/projects\/FL\/repos\/freepbx-nodejs\/browse\">nodejs<\/a> application that is used for the &#8220;<a href=\"https:\/\/wiki.freepbx.org\/display\/FPG\/Node+Server-UCP\">User Control Panel (UCP) Node Server<\/a>&#8221; that FreePBX uses.\u00a0 This is used for a user to check voicemail, etc.\u00a0 \u00a0You can map Asterisk to use the localhost IP address by going into the &#8220;Settings&#8221; and then &#8220;Advanced Settings&#8221; and go to the section called &#8220;UCP NodeJS Server&#8221; and update the &#8220;Bind Address&#8221; to &#8220;127.0.0.1&#8221;.\u00a0 (This seems to be not on FreePBX 15 and is already mapped to the localhost.)<\/p>\n<p><b>Session Initiation Protocol<\/b>\u00a0(<b>SIP<\/b>)<\/p>\n<p>SIP is going to be your biggest risk.\u00a0 \u00a0Depending on the distribution of FreePBX\/RasPBX\/etc., asterisk really has to listen to the SIP ports (5060\/5061) so your phones and providers can send commands to Asterisk to do things like making a call.\u00a0 Having Asterisk just exposed to the Internet at large means that your Asterisk box will be cracked in 30 seconds once you put it on the net.\u00a0 Hackers love to find an exposed SIP server out there to make outbound calls through your box.\u00a0 This obscures who is making the call and they don&#8217;t have to pay for the VoIP service.\u00a0 You are.<\/p>\n<p>There are a number of ways to deploy an Asterisk box.\u00a0 You can either do it behind a firewall with rules on the firewall to allow certain IP addresses to be passed to the Asterisk box or you can have Linux do the filtering.\u00a0 \u00a0FreePBX and RasPBX both have <a href=\"https:\/\/www.fail2ban.org\/\">FAIL2BAN<\/a> as an option.\u00a0 \u00a0Fail2Ban is a program that scans the logs of various programs like SSH and Asterisk and looks for times that an IP address is trying to crack into your site and was unsuccessful.\u00a0 If so, it will add a firewall rule on Linux to prevent that IP address from accessing the box for some time frame.\u00a0 By default, this is about 10 minutes.\u00a0 After that, the rule is taken out and that IP address can try again.\u00a0 This can retard the progress of someone trying to crack into your box, but do you really want the hassle?\u00a0 What happens if they do make through?\u00a0 Then you may find some rather expensive bills from your VoIP provider.\u00a0 \u00a0Unless you really want to be serving up SIP to the rest of the Internet, let&#8217;s lock this puppy down.<\/p>\n<p>My installation has a public IP address and I rely on using Linux&#8217;s &#8220;netfilter&#8221; to firewall.\u00a0 Netfilter can be configured a couple of ways.\u00a0 The more traditional is to use IPTABLES.\u00a0 I am not going into detail on how to use IPTABLES as there are plenty of sites that can show you that.<\/p>\n<p>First off, identify the IP addresses you need to allow to connect to your Asterisk box.\u00a0 This will include your VoIP provider&#8217;s\u00a0session border controller\u00a0(SBC) that will be protecting their SIP server.\u00a0 I use VoIP.ms out of Canada and they list their servers on their <a href=\"https:\/\/wiki.voip.ms\/article\/Choosing_Server\">wiki<\/a>.\u00a0 Also, identify the IP addresses that your phones will be using.\u00a0 This may be on your local LAN or they may be coming from other sites.\u00a0 Hopefully, these are IP addresses that won&#8217;t be changing much.\u00a0 In times past, I had to run an Asterisk server that had a number of home employees, so they were coming from cable providers that would change the IP address on occasion.\u00a0 Normally this wouldn&#8217;t change that often so it was manageable.\u00a0 Let&#8217;s say you have the following IP\u00a0 addresses&#8230;<\/p>\n<ul>\n<li>VOIP provider: 1.1.1.1<\/li>\n<li>Your local LAN&#8217;s prefix 192.168.0.0\/24 assuming your Asterisk box is directly connected.<\/li>\n<li>Your local LAN&#8217;s public IP address 2.2.2.2\/32 if your Asterisk box is not connected to your LAN<\/li>\n<li>An offsite worker: 3.3.3.3\/32.<\/li>\n<\/ul>\n<p>You will need to create a file like <strong>\/etc\/iptables\/rules.v4<\/strong> that looks something like:<\/p>\n<pre class=\"p1\"><span class=\"s1\">*filter<\/span>\r\n<span class=\"s1\"># SIP...<\/span>\r\n<span class=\"s1\">-A INPUT -s 1.1.1.1 -p all -m all --dport 5060 -m comment --comment \"VoIP Provider\" -j ACCEPT<\/span>\r\n<span class=\"s1\">-A INPUT -s 1.1.1.1 -p all -m all --dport 5061 -m comment --comment \"VoIP Provider\" -j ACCEPT<\/span>\r\n<span class=\"s1\">-A INPUT -s 2.2.2.2 -p all -m all --dport 5060 -m comment --comment \"Public IP of Office\" -j ACCEPT<\/span>\r\n<span class=\"s1\">-A INPUT -s 2.2.2.2 -p all -m all --dport 5061 -m comment --comment \"Public IP of Office\" -j ACCEPT\r\n-A INPUT -s 3.3.3.3 -p all -m all --dport 5060 -m comment --comment \"Remote Worker\" -j ACCEPT\r\n-A INPUT -s 3.3.3.3 -p all -m all --dport 5061 -m comment --comment \"Remote Worker\" -j ACCEPT<\/span>\r\n<span class=\"s1\">-A INPUT -p all -m all --dport 5060 -m comment --comment \"Drop all other SIP connections\" -j DROP<\/span>\r\n<span class=\"s1\">-A INPUT -p all -m all --dport 5061 -m comment --comment \"Drop all other SIP-TLS connections\" -j DROP\r\n<\/span><\/pre>\n<p>In this file, you are allowing SIP access for the IP addresses listed to port 5060 (UDP) and port 5061 (TCP\/TLS).\u00a0 The very last two rules say, if IP addresses don&#8217;t match the above, then DROP those packets.<\/p>\n<h6><b>Secure Shell<\/b>\u00a0(SSH)<\/h6>\n<p>This is another popular service that as soon as you stand up a server, you will see bots knocking at your door.\u00a0 Again, fail2ban can address this, but why would you want the exposure?\u00a0 Let&#8217;s just lock it down to a couple of IP addresses with IP tables.\u00a0 Updating the <strong>\/etc\/iptables\/rules.v4<\/strong> file and using the example IP addresses we used for SIP&#8230;<\/p>\n<pre class=\"p1\"><span class=\"s1\"># SSH...\r\n<\/span><span class=\"s1\">-A INPUT -s 2.2.2.2 -p tcp -m tcp --dport 22 -m comment --comment \"Office Public IP Address\" -j ACCEPT\r\n<\/span><span class=\"s1\">-A INPUT -s 3.3.3.3 -p tcp -m tcp --dport 22 -m comment --comment \"Offisite IT Provider\" -j ACCEPT\r\n<\/span><span class=\"s1\">-A INPUT -p tcp -m tcp --dport 22 -m comment --comment \"Drop all other SSH TCP connections\" -j DROP\r\n<\/span><\/pre>\n<h6><b>Apache<\/b><\/h6>\n<p>This is the webserver to get into the FreePBX GUI.\u00a0 Let&#8217;s just lock it down to a couple of IP addresses with IP tables.\u00a0 Again, updating the <strong>\/etc\/iptables\/rules.v4<\/strong> file and using the example IP addresses we used for SIP&#8230;<\/p>\n<pre class=\"p1\"><span class=\"s1\"># Apache...\r\n<\/span><span class=\"s1\">-A INPUT -s 2.2.2.2 -p tcp -m tcp --dport 80 -m comment --comment \"Office Public IP Address\" -j ACCEPT\r\n<\/span><span class=\"s1\">-A INPUT -s 3.3.3.3 -p tcp -m tcp --dport 80 -m comment --comment \"Offisite IT Provider\" -j ACCEPT\r\n<\/span><span class=\"s1\">-A INPUT -p tcp -m tcp --dport 80 -m comment --comment \"Drop all other Web TCP connections\" -j DROP\r\n-A INPUT -s 2.2.2.2 -p tcp -m tcp --dport 443 -m comment --comment \"Office Public IP Address\" -j ACCEPT \r\n-A INPUT -s 3.3.3.3 -p tcp -m tcp --dport 443 -m comment --comment \"Offisite IT Provider\" -j ACCEPT \r\n<\/span>-A INPUT -p tcp -m tcp --dport 443 -m comment --comment \"Drop all other Web SSL TCP connections\" -j DROP<\/pre>\n<h6><b>IPTABLES That is Persistent<\/b><\/h6>\n<p>I mentioned added these rules to\u00a0<strong>\/etc\/iptables\/rules.v4<\/strong>. We are going to add a bit of config to the networking section of FreePBX to have the server add these rules on reboot.<\/p>\n<p>Simply you need to add the line &#8220;<span class=\"s1\">pre-up \/sbin\/iptables-restore \/etc\/iptables\/rules.v4&#8243; for the network interface you are using to \/etc\/network\/interfaces.\u00a0 It should look something like:<\/span><\/p>\n<pre class=\"p1\"><span class=\"s1\">auto eth0\r\n<\/span><span class=\"s1\">iface eth0 inet static\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>pre-up \/sbin\/iptables-restore \/etc\/iptables\/rules.v4<\/span><\/pre>\n<p>This tells the server to load the rules you created before it turns up the network interface.<\/p>\n<p>The more recent FreePBX\/Raspbx uses dhcpcd.\u00a0 There is a set of scripts that get run in \/lib\/dhcpcd\/dhcpcd-hooks\/.\u00a0 You can create a file called &#8220;<strong>\/lib\/dhcpcd\/dhcpcd-hooks\/05-iptables<\/strong>&#8221; and put &#8220;<span class=\"s1\"><strong>\/sbin\/iptables-restore \/etc\/iptables\/rules.v4<\/strong>&#8221; it in.\u00a0 This will add the rules before the rest of the network gets turned up.<\/span><\/p>\n<h6><b>Check Your work<\/b><\/h6>\n<p>Reboot your box and see if the IPTABLES loaded.\u00a0 If you have fail2ban loaded, you will also see entries from it there.<\/p>\n<pre class=\"p1\"><span class=\"s1\">root@asterisk:\/home\/pozar# iptables --list<\/span>\r\n<span class=\"s1\">Chain INPUT (policy ACCEPT)<\/span>\r\n<span class=\"s1\">target <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>prot opt source <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>destination<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/span>\r\n<span class=\"s1\">fail2ban-asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip<\/span>\r\n<span class=\"s1\">fail2ban-asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>udp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>udp dpt:sip<\/span>\r\n<span class=\"s1\">fail2ban-asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip-tls<\/span>\r\n<span class=\"s1\">fail2ban-ssh<span class=\"Apple-converted-space\">\u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>multiport dports ssh<\/span>\r\n<span class=\"s1\">ACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>any<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>1.1.1.1<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>any dpt:sip \/* voip provider *\/<\/span>\r\n<span class=\"s1\">ACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>1.1.1.1<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip-tls \/* voip provider *\/<\/span>\r\n<span class=\"s1\">ACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>any<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>2.2.2.2 <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>any dpt:sip \/* Office Public IP *\/<\/span>\r\n<span class=\"s1\">ACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>2.2.2.2 <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip-tls \/* Office Public IP *\/\r\nACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>any<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 3.3.3.3<\/span> <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>any dpt:sip \/* Joe's Home Office *\/\r\nACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 3.3.3.3<\/span> <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip-tls \/* Joe's Home Office *\/<\/span>\r\n<span class=\"s1\">DROP <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>any<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>any dpt:sip \/* Drop all other SIP UDP connections *\/<\/span>\r\n<span class=\"s1\">DROP <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:sip-tls \/* Drop all other SIP-TLS connections *\/<\/span>\r\n<span class=\"s1\">ACCEPT <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a02.2.2.2<\/span><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:ssh \/* Office Public IP address *\/<\/span>\r\n<span class=\"s1\">DROP <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>tcp<span class=\"Apple-converted-space\">\u00a0 <\/span>--<span class=\"Apple-converted-space\">\u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>anywhere <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>tcp dpt:ssh \/* Drop all other SSH TCP connections *\/<\/span><\/pre>\n<p>Now look at the daemons and see if they are bound to the IP addresses you are expected:<\/p>\n<pre class=\"p1\"><span class=\"s1\">root@asterisk:\/home\/pozar# lsof -i | grep LIST<\/span>\r\n<span class=\"s1\">sshd <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>604<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>3u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>12384<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:ssh (LISTEN)<\/span>\r\n<span class=\"s1\">sshd <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>604<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12386<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:ssh (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>1087<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12480<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:http (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>1087<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>root<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>6u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12484<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:https (LISTEN)<\/span>\r\n<span class=\"s1\">mysqld<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>1148 <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>mysql <span class=\"Apple-converted-space\">\u00a0 <\/span>10u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>13502<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:mysql (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>1176<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12480<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:http (LISTEN)<\/span>\r\n<span class=\"s1\">apache2 <span class=\"Apple-converted-space\">\u00a0 <\/span>1176<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>6u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12484<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP *:https (LISTEN)<\/span>\r\n[...]\r\n<span class=\"s1\">exim4 <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>1562 Debian-exim<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>4u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>12786<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:smtp (LISTEN)<\/span>\r\n<span class=\"s1\">exim4 <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>1562 Debian-exim<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>5u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv6<span class=\"Apple-converted-space\">\u00a0 <\/span>12787<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:smtp (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>1802<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>13u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>13291<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:omniorb (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>1802<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>14u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>13292<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:8089 (LISTEN)<\/span>\r\n<span class=\"s1\">asterisk<span class=\"Apple-converted-space\">\u00a0 <\/span>1802<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>15u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>13293<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:5038 (LISTEN)<\/span>\r\n<span class=\"s1\">node<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>1993<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>13u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>14461<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:8001 (LISTEN)<\/span>\r\n<span class=\"s1\">node<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>1993<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>asterisk <span class=\"Apple-converted-space\">\u00a0 <\/span>14u<span class=\"Apple-converted-space\">\u00a0 <\/span>IPv4<span class=\"Apple-converted-space\">\u00a0 <\/span>14462<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>0t0<span class=\"Apple-converted-space\">\u00a0 <\/span>TCP localhost:8003 (LISTEN)<\/span><\/pre>\n<h6><b>Conclusion<\/b><\/h6>\n<p>As mentioned in my disclaimer, this likely isn&#8217;t everything you need to do but it will make a dent in having your server hijacked for unwanted SIP calls to countries you never thought you called.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Disclaimer:\u00a0 This is likely not everything you should do in securing your FreePBX box, but it is a good starting point.\u00a0 \u00a0It is meant to limit your exposure to the public Internet, but this doesn&#8217;t cover exploits that can happen after you lock that down such as from address space you are allowing.\u00a0 Having good &hellip; <a href=\"https:\/\/blog.lns.com\/?p=177\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Protecting your Asterisk PBX&#8230;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lns.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177"}],"version-history":[{"count":21,"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/blog.lns.com\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions\/198"}],"wp:attachment":[{"href":"https:\/\/blog.lns.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lns.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lns.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}