This time I’d like to give you a short usage description of icmpKNOCK that was recently released. The main reason I wrote it was lack of security measurements on my boxes. I didn’t want any sophisticated IDS tools nor complicated monitoring services. I wanted to implement something which will run on (almost) any platform without any external toolsb. Since the ping utility is available on most modern systems using ICMP packets to communicate with the server was the most reasonable approach. There are plenty of other port knocking tools but these are mostly binaries. These have to be first compiled on the running system which is bad. So the second thought was to use a programming language powerful enough to fulfill my needs and be portable. It had to be Python.
Getting started
First you’ll have to get the latest version of icmpKNOCK. Please check the SVN download link for the newest packages. Then make sure to upload the package to your server and copy it to a secret place where nobody - besides you - has read permissions on the actions file. Why is that important? Because the actions file contains your secret
hex sequences used to trigger certain actions. So you don’t want anybody to know these ones. In that case potential attackers might manipulate the behaviour of your system without noticing it.
|
|
Generate hex sequences
Now you’ll have to generate your keys. You could use MD4, MD5, SHA-1 etc hashes. This is what I did:
|
|
That should do the work. Now you’ll have to edit your actions file (conf/actions.conf) and copy these values to it. Please have a look at the descriptive text inside the file for further information.
Define actions
This is the most interesting part. In this HowTo I’ll give you an example how to block/open SSH port 22 using icmpKNOCK. Therefor I’ll be using iptables which should be available within every Linux distribution. So let’s start…
For this tutorial the SSH port should be always closed. Let’s define the action describing that:
|
|
Everytime the server receives the secret hex sequences it will close port 22 to block any external connections. What about opening it?
|
|
In that case you simply delete the previously created rule. Afterwards port 22 should be open again.
Of course: There are lot of other possible configurations. Perhaps it is a better idea to define only 1 action which allows you to connect to port 22 within 20 seconds, close the port again after 20 seconds and keep the established connections. Feel free to use your brain.
Prepare your scripts
Your server - along with the Python application - will listen for incoming ICMP packets. Your client will be the ping utility as described above. In order to send your sequences to the server you’ll need a small bash script which will do the rest for you:
|
|
That’s all. Just name your script something like start_ssh.sh
and run it every time you you’ll connect to the server. The same applies to cllosing the port
.
For any comments, new features or simply feedback, please use the comment functionality or drop me a mail.