Hey All
Just a quick how to......
First and formost you need to use key based authentication... See
http://macnugget.org/projects/publickeys/Port knocking is a stealth method to externally open ports that, by default, the firewall keep closed. It works by requiring connection attempts to a series of predefined closed ports. When the correct sequence of port "knocks" (connection attempts) is received, the firewall opens certain port(s).
The benefit is that, for a regular port scan, it may appear as the service of the port is just not available.
Download Locations
Server: Source
http://www.zeroflux.org/proj/knock/files/knock-0.6.tar.gz Debian
http://packages.debian.org/unstable/net/knockd RPM
http://www.invoca.ch/pub/packages/knock/Client: Windows
http://gregsowell.com/wp-content/plugins/download-monitor/download.php?id=19 MAC
http://www.zeroflux.org/proj/knock/files/knock-macos.tar.gz Iphone
http://www.dannysung.com/main/?q=node/25 Andriod
https://play.google.com/store/apps/details?id=com.droidknocker Also check your Distributions repos for knockd and knock.
Once installed we now need to configure knockd
vi /etc/knockd.confThis example uses a single knock to control access to port 22 (SSH). After receiving a successful knock, the daemon will run the start_command, wait for the time specified in cmd_timeout, then execute the stop_command. This is useful to automatically close the door behind a knocker. The knock sequence uses both UDP and TCP ports.
[options]
logfile = /var/log/knockd.log
[opencloseSSH]
sequence = 2222:udp,3333:tcp,4444:udp
seq_timeout = 15
tcpflags = syn,ack
start_command = /usr/sbin/iptables -A INPUT -s %IP% -p tcp --syn --dport 22 -j ACCEPT
cmd_timeout = 10
stop_command = /usr/sbin/iptables -D INPUT -s %IP% -p tcp --syn --dport 22 -j ACCEPTChange the sequence line to your preferred port sequence
Now that you've changed the port sequences to your liking you now can start up knockd:
/etc/init.d/knockd startMake sure it's running
ps fax | grep -i knockJust as a fail safe ensure you have a iptables rule like
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPTBefore closing your ssh port
Use the client software to run the port sequence, quickly ssh and WHOOOOP you're in!
See iptables sample output below
:INPUT DROP [5:240]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1183:743831]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 993 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
I Hope everyone understands what im going on about, not very good at tutorials
Thanks
Richard