Labs / Recon / Recon: packets, banners and DNS

Lab 2 of 3 · Recon: packets, banners and DNS

hping3: reading a firewall off its own replies

Craft lone TCP and ICMP probes with hping3 and read a perimeter firewall's policy from how it answers each one.

Start this lab 5 steps

The idea

Nadia has a signed engagement against Cobalt Mining Co., and you are at her Kali box kali. Their perimeter answers no ping. A port scanner would call every quiet port "filtered" and move on. But why a port is quiet is itself a finding.

With hping3 you send one packet at a time, choose every field in it, and read the single reply: a SYN-ACK, a RST, or nothing at all. Three answers mean three different things the firewall is doing. And the ports it does let through give you a way to map the network hiding behind it.

Silence has two causes
Silence has two causes
One SYN, no connection
One SYN, no connection
Same SYN, three answers
Same SYN, three answers
The allowed port is a window
The allowed port is a window
A lone ACK gets a reset
A lone ACK gets a reset

Steps

  1. ping comes back empty

    The first thing anyone tries is ping, and against Cobalt's perimeter it dies: no reply, every packet lost. That is not proof the host is down. A firewall that drops ICMP, the protocol ping speaks, produces exactly the same silence as a switched-off machine: the probe leaves and nothing comes back, and from here the two cases look the same.

    So ping has told you one thing only: do not trust silence. You need a probe whose reply carries information, and you need to choose what that probe looks like.

    kali:~# ping -c 2 10.0.3.10
  2. Craft one SYN and read the flags

    A normal TCP connection opens with a three-way handshake: your machine sends a SYN, the server replies SYN-ACK, your machine answers ACK. hping3 lets you send only the first packet and stop, so you learn whether a port is open without ever completing the connection.

    -S sets the SYN flag; -p 80 aims at the port; -c 3 sends three and quits. hping3 needs raw sockets to build a packet by hand, so it runs under sudo (your Kali user has it). Read the flags= field of each reply.

    kali:~# sudo hping3 -S -p 80 -c 3 10.0.3.10
  3. The same probe, three different answers

    Now send the identical SYN to two more ports and line up the replies. Port 22 is Cobalt's ssh; port 3306 is where a database would listen. Watch what comes back from each, and compare all three to port 80:

    • flags=SA: open. A service is listening and the SYN reached it.
    • flags=RA: a RST-ACK, a reset. The connection is actively refused. A closed port sends this, and so does a firewall configured to reject rather than drop. Either way the door is shut, but you got an answer.
    • nothing: silence. The probe was dropped with no reply, exactly like ping. Open the port? Closed? You cannot tell; all you know is a rule ate the packet.

    The reset and the silence are the firewall's two ways of saying no, and the difference is a finding. A reset is fast and certain; a silent drop makes an attacker wait out a timeout on every probe and never confirms the port even exists. Which one a perimeter uses tells you how it was built.

    kali:~# sudo hping3 -S -p 22 -c 3 10.0.3.10
    kali:~# sudo hping3 -S -p 3306 -c 3 10.0.3.10
  4. Walk a probe past the firewall

    Every IP packet carries a TTL, a hop counter that each router lowers by one. Reach zero and the router throws the packet away and sends back an ICMP time-exceeded, naming itself. traceroute abuses this on purpose: send TTL 1, then 2, then 3, and each router in turn reports its own address.

    hping3 does the walk with a TCP SYN instead of the usual UDP, so the probe looks like ordinary traffic to port 80, the one port the firewall allows all the way through. A probe the firewall passes climbs deep into the network, and every router that expires it names itself. This is Firewalking: using an allowed port to map what sits behind the wall.

    The firewall only lets this work because a time-exceeded error about an allowed connection counts as part of that connection and is let back in. It is the same connection tracking that lets the status page's own replies return (the Stateful firewall concept covers it). Aim the same trick at a port the firewall drops and the probe dies at the wall, so you see the firewall and nothing past it.

    kali:~# sudo hping3 --traceroute -S -p 80 -c 5 10.0.3.10
    kali:~# sudo hping3 --traceroute -S -p 3306 -c 5 10.0.3.10
  5. What Cobalt's admin should take from this

    Nadia's report is not "you have open ports". Cobalt needs port 80 open: that is the point of it. It is what the rest of the perimeter gave away for free:

    • A reset is a confirmation. The clean RA on port 22 told Nadia ssh is there and refused, not that it is absent. Dropping those packets instead would have left her guessing, and guessing costs an attacker time and certainty. Reserve resets for inside the network where the speed helps your own people; make the outside wait.
    • Silence is the stronger default, which is why port 3306 was the hardest to read. A default-drop perimeter is a wall an attacker has to map one slow timeout at a time.
    • An allowed port is a path, not only a service. Because 80 is let through end to end, firewalking rode it straight to a router Cobalt never advertised. The fix is not to close 80 but to stop the errors leaking back: rate-limit outbound ICMP and strip time-exceeded at the edge, so a firewalk stalls at the wall.

    None of this is exotic traffic. Every probe here is a single, legal-looking packet, which is why the defence is to give boring, uniform answers, not to hope a scanner looks suspicious.

    Running these same probes against a system whose owner has not authorised you in writing is a criminal offence under laws like the UK Computer Misuse Act and the United States' CFAA, however harmless one packet looks.

    kali:~# sudo hping3 -A -p 80 -c 3 10.0.3.10

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab