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.
Steps
-
A host with no way out
Dagny's build machine,
victimin 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
-
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
-
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
-
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
-
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