I’ve been asked a few time how Portquiz.net works.
It’s really simple. It’s just made of a few iptables rules. I’m using the iptables-persistent Debian package to make the rules persist a reboot.
Here is the content of /etc/iptables/rules.v4:
# Generated by iptables-save v1.4.14 on Sun Aug 25 12:43:34 2013
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -i lo -j RETURN
-A PREROUTING -p icmp -j RETURN
-A PREROUTING -m state --state RELATED,ESTABLISHED -j RETURN
-A PREROUTING -p tcp -m tcp --dport 22 -j RETURN
-A PREROUTING -p tcp -m tcp --dport 21 -j RETURN
-A PREROUTING -p tcp -m tcp --dport 25 -j RETURN
-A PREROUTING -p tcp -m tcp --dport 80 -j RETURN
-A PREROUTING -p tcp -m tcp --dport 443 -j RETURN
-A PREROUTING -p tcp -j DNAT --to-destination :80
COMMIT
# Completed on Sun Aug 25 12:43:34 2013
# Generated by iptables-save v1.4.14 on Sun Aug 25 12:43:34 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -j DROP
COMMIT
# Completed on Sun Aug 25 12:43:34 2013
The filter table is classical: ACCEPT a few services, then DROP the rest.
Portquiz.net logic is in the nat table:
- Forward connection on any port to port 80 (DNAT –to-destination :80)
- Except for normal services (just RETURN for normal activity)
Funny, did you know we’re still using it at Smile ? :)
So, it’s not a secret anymore !
Nice !
you read port number from http host header?
when I try:
curl http://portquiz.net:9999/ -H “Host: portquiz.net:7777″
Port 7777 test successful!
…
Hello,
Good catch. The script is just reading the $_SERVER["SERVER_PORT"] variable in PHP.
Apache has no easy way of knowing the real destination port, as it is natted.
Marc
Pingback: Detect outgoing port blocking with nmap and portquiz.net - Michael Altfield's Tech Blog