FYI IPTables & Port Knocking

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
So I am having trouble getting port knocking to work.

I've installed IncrediblePBX on Ubuntu 14.04 using http://nerdvittles.com/?p=9713

My problem is that port knocking only seems to work for whitelisted IP addresses out of the box (which defeats the purpose).

Tailing the kockd.log file only outputs anything using nmap from one of the IPs manually whitelisted like
Code:
-A INPUT -s 123.123.123.123 -j ACCEPT

Reading the post http://nerdvittles.com/?p=9871 and it says "These ports need not be opened in your IPtables firewall configuration! We’re just knocking, not entering." So what am I doing wrong?
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
I've also verified I am testing from IPs allowed to pass through the hardware firewall and toggled the iptables whitelist for these IPs
 

tycho

Guru (not...)
Joined
Aug 9, 2011
Messages
652
Reaction score
272
I recently installed incredible PBX 12 on an Ubuntu 14 instance on my new CloudAtCost server. I experimented with port knocking, installing the DroidKnocker app on my Moto X smartphone. I switched off wifi on the phone and switched on 4G LTE, thereby obtaining a completely different IP address from my home IP range. I activated DroidKnocker, and then check the port knocker log on the PBX. The log reflected the knocks, and it showed that the foreign 4G LTE IP address had been added. I checked again later, and the address expired, as expected, after an hour. So , from what I can tell, it is working as advertised.
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
I installed IncrediblePBX from
Code:
http://incrediblepbx.com/incrediblepbx11.4.ubuntu14.tar.gz
. And then used the update script. Good to know it is working for you. Trying to figure out what is going on with mine
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
tycho
Thanks that was helpful. I did not realize the latest version was 12 instead of 11.4. I will create a new instance and see if that fixes my issues.

Also, I read up on virtualization approaches because I am given the choice between paravirtual and hvm. I rebuilt the previous image as paravirtual and got responses back from nmap when attempting to knock. But it still wasn't granting me access.
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
Hrm... still no luck.

With the following in rules.v4 I can port knock and see a log entry when tailing /var/log/knockd.log
Code:
-A INPUT -s 123.123.123.123 -j ACCEPT

If I change it to
Code:
#-A INPUT -s 123.123.123.123 -j ACCEPT
and run "sudo iptables-restart", I get a "host seems down" from nmap and see no log output for the knock.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,206
Reaction score
5,228
gordon Is your server behind a hardware-based firewall?? If so, you must forward the three knock ports from the firewall to your server's private IP address.
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
gordon Is your server behind a hardware-based firewall?? If so, you must forward the three knock ports from the firewall to your server's private IP address.

Thanks for the reply. The server is behind a hardware based firewall, but I've whitelisted all traffic from my IP until I get everything running as expected. Since the knocks are received when I disable IPTables, I think my hardware-based firewall is allowing the knocks to pass in both cases.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,206
Reaction score
5,228
That shouldn't work if you're not forwarding the ports unless your server is in DMZ. What type firewall?
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
I guess it would be analogous to DMZ. Amazon EC2 Security Group. I guess it isn't technically a hardware based firewall.
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
It is set to allow all tcp/udp/icmp traffic from my IP address
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,206
Reaction score
5,228
To put it charitably, Amazon is different. They're probably blocking the port knocks. Do yourself and your wallet a favor. Find another provider.
 

tycho

Guru (not...)
Joined
Aug 9, 2011
Messages
652
Reaction score
272
gordon:

Well, it works on my VM on CloudAtCost...

I actually never toyed with port knocking on my previous DigOcean droplet. If have time I will fire that one back up from the saved state that I probably still have on D.O. and check. However, I created it some time ago, and I don't now recall if it is a version that incorporates port knocker...
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
wardmundy

So I just tried this on DigitalOcean with CentOS 6.5 and IncrediblePBX 11.4 from http://nerdvittles.com/?p=10079 and I observed the same behavior.

I know this is used by lots of people, but I do not think this is something I am doing at this point. Can anyone confirm with either CentOS 6.5 or Ubuntu 14.04 and IncrediblePBX 11.4 or Ubuntu 14.04 and IncrediblePBX 12 that port knocking from an ip that is not already whitelisted with iptables works correctly when deployed on DigitalOcean or Amazon EC2 (or another virtualized cloud provider)?

Here is nmap output from a ip that is already whitelisted in iptables:
Code:
COMPUTER #1 WITH WHITELISTED IP
 
$ nmap -p 1234 foo.bar.com
 
Starting Nmap 6.40 ( http://nmap.org ) at 2014-12-12 18:44 EST
Nmap scan report for foo.bar.com (123.123.123.123)
Host is up (0.040s latency).
PORT    STATE  SERVICE
1234/tcp closed unknown

Here is nmap output that fails:


Code:
COMPUTER #2 NO IPTABLES ENTRY
 
 
 
$nmap -p 1234 foo.bar.com
 
 
 
Starting Nmap 6.47 ( http://nmap.org ) at 2014-12-12 15:44 Pacific Standard Time
 
 
 
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
 
 
 
Nmap done: 1 IP address (0 hosts up) scanned in 5.75 seconds
 

gordon

Member
Joined
Jun 7, 2013
Messages
96
Reaction score
7
Well, I've got no idea what is going on... but I changed the knock sequence to expect udp instead of tcp and it works with CentOS 6.5 (didn't try Ubuntu because I trashed the image). If I change it back to tcp, it doesn't work. Neither nmap nor the knock client works with tcp ports. But I can get it to respond to udp ports consistently from the knock client so that is something anyways.
 

tycho

Guru (not...)
Joined
Aug 9, 2011
Messages
652
Reaction score
272
Interesting. Using Ubuntu and I-PBX 12 on my CloudAtCost instance, and DroidKnocker on my Moto X, my experience was exactly the opposite. I had been tinkering with DroidKnocker and was given the option of knocking using either TCP or UDP. I couldn't recall which I was supposed to use, so I tried both. TCP worked; UDP did not work.
 

Members online

No members online now.

Forum statistics

Threads
25,825
Messages
167,849
Members
19,250
Latest member
mark-curtis
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top