Portknocking
Portknocking is a method to open ports that the firewall normally keeps closed by executing a series of connection attempts (knocks) to other ports. Upon the valid sequence of port knocks, the required port will open.
Think of portknocking as a special knock on a door for the door to open.
Here is an example from ArchLinux wiki:
$ ssh username@host
(Ctrl+c to exit) ^C
$ nmap -Pn --host_timeout 201 --max-retries 0 -p 1111 host
$ nmap -Pn --host_timeout 201 --max-retries 0 -p 2222 host
$ ssh user@host
user@host's password:
The user knocks port 1111
followed by 2222
to open up port 22
for SSH.
Portspoof
Portspoof is a program which makes interpreting port scan results very difficult, therefore slowing down being able to identify open ports.
The Portspoof program primary goal is to enhance OS security through a
set of new techniques:
- All TCP ports are always open
Instead of informing an attacker that a particular port is CLOSED or FILTERED
state Portspoof will return SYN+ACK for every port connection attempt.
As a result it is impractical to use stealth (SYN, ACK, etc.) port
scanning against your system, since all ports are always reported as
OPEN.
Every open TCP port emulates a services
Portspoof has a huge database of dynamic service signatures, that will be used to fool
scanners to believe there's a legitimate service running. Scanning
software usually tries to determine a service version that is running
on an open port. Portspoof will respond to every service probe with a
valid service signature, that is dynamically generated based on a
service signature regular expression database. As a result an attacker
will not be able to determine which port numbers your system is truly
using.
Quoted from https://github.com/drk1wi/portspoof
Portspoof makes identifying listening services much more difficult and as the README states, it would take over 8 hours to identify which ports are actually listening. Identifying the real ports is so time consuming that the attackers will likely give up.
This guide shows how you can install Portspoof:
- Compile the software, go in the directory where you have unzipped/put the sources and give these commands:
$./configure $ make $ sudo make install
OR
$ g++ -lpthread -Wall -g Configuration.cpp connection.cpp
Portspoof.cpp revregex.cpp Utils.cpp Fuzzer.cpp Server.cpp -o
portspoof
- Configure your firewall rules:
iptables -A PREROUTING -i eth0 -p tcp -m tcp --dport 1:65535 -j REDIRECT --to-ports 4444
iptables-restore < iptables-config
(system_files directory)
Run Portspoof with service emulation:
$ portspoof -c portspoof.conf -s portspoof_signatures -D
Run Portspoof in “open port” mode:
$ portspoof -D
- Add portspoof to your system’s startup scripts. To do this modify or use the default init.d script that you can found in the
‘system_files’ directory.
Combine Portknocking with Portspoof and you've got yourself a nice defense from port scanners.