Skip to contentSkip to conversation

Port Cloaking

DISCUSSION Sean Donner 1 participant 1 message Nov 19, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

Now that I have ported the random match to 2.6.X, I wanted to talk to you guys about how I use it and see if you had any tips to improve on my idea.
I came up with this idea not too long ago about having iptables spoof the
state of a port, whether its open or closed. Combining this with the port-scan-detection and random matches, my goal was to make it so that when my box is being portscanned, the attacker would see various ports as open even if they were really closed, and all of my truely open ports would be filtered/stealthed. With the help of the random match, every time my box is portscanned (even by the same attacker) the would see a whole new set of fake ports as open.

The only way I could think of, that would allow a closed port to fake as if it were open was to write a very small "dummy server" that does nothing but bind to an arbitrary port. Once bound, I would send all psd matched packets to that dummy server port via REDIRECT. So here is the flow.

1) Attacker runs a port scan againt my box
2) Port-scan-detection threshold reached, packets sent to portcloak_random chain
3) Check to see if packet is destined to a truley open port, if so drop it.
4) Randomly match remaining packets with a 1% average and send them to the dummy server listening on $DUMMYPORT via REDIRECT.
5) Drop all remaining packets.

Here is how I implimented it:

-----------------------
-t nat -N portcloak_random
-t nat -A PREROUTING -p tcp -i $EXT_NET -m psd --psd-delay-threshold 2000 -j portcloak_random

-t nat -A portcloak_random -p tcp -m multiport --destination-ports echo $SINGLE_PORTS | sed 's/\ /,/g' -j DROP
-t nat -A portcloak_random -p tcp -m random --average 1 -j REDIRECT --to-ports $DUMMYPORT
-t nat -A portcloak_random -j DROP
-----------------------

One thing to note, $SINGLE_PORTS expands to the truely open ports on my box.

Using this implimentation ive had some very positive results but there are some drawbacks that I hope you guys could help remedy.

1) First and foremost, if at all possible I would like to get rid of the need to have a dummy server and do the entire thing using iptables rules.

2) This implimentation only works against half open portscans (nmap -sS) and not with a full TCP handshake scan (nmap -sT). Im guessing because the final ACK packet from the attacker will be dropped 99% of the time thanks to the random match, and thats assuming it gets past the port-scan-detection match.

I was thinking that a possible fix for this is to use the CONNMARK match/target within the portcloak_random chain and mark all connections that are sent to the dummy server. Then, add an additional rule before the port-scan-detection rule that will REDIRECT any packet with the
correct CONNMARK to the dummy server. Havn't tried this out yet, cause
ive had problems with CONNMARK compiling on 2.6.X.

3) Assuming #1 is not possible, every time one of the scans connects to my dummy server that uses up resources, both from conntrack as well as kernel mem for the sockets. I pretty much borrowed the dummy_server.c code from a network programming howto, so if any of you feel like taking a once over on it and seeing if you see any blatent security risks that can lead to an easy DoS of my box, or see some way to make it more efficient with the resources it uses I would appreciate it; the code is fairly short. All it has to do is just bind to a port.

Sorry for the lengthy post, I appreciate all comments. My dummy_server.c code is attached.

-Sean