2015-10-27 20:11

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)
2015-10-27 20:11

5 Comments

  1. Funny, did you know we’re still using it at Smile ? :)

    So, it’s not a secret anymore !

    Reply

  2. 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!

    Reply

    • 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

      Reply

  3. Pingback: Detect outgoing port blocking with nmap and portquiz.net - Michael Altfield's Tech Blog

Leave a Reply to zjcqoo Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>