Labs / Night Watch / DNS sinkholes & covert channels

Lab 1 of 2 · DNS sinkholes & covert channels

DNS sinkhole: blocking bad domains for every client at once

Block a bad domain for every client at once and find the infected host.

Start this lab 5 steps

The idea

Tomasz looks after IT at Harrow & Pike, a 30-person architecture studio. This morning a threat feed flagged the domain evil as a malware command-and-control server, and he wants two things: to know whether any studio machine has talked to it, and to cut every machine off from it at once.

Both PCs, infectedPc and cleanPc, ask the same company resolver for every name. That resolver is where Tomasz builds a DNS sinkhole: a dead end for the bad domain that blocks it for everyone and writes down who came looking.

Every lookup goes through one box
Every lookup goes through one box
The lookup names the machine
The lookup names the machine
The policy answers first
The policy answers first
Two logs, two kinds of proof
Two logs, two kinds of proof
Sinkhole or NXDOMAIN
Sinkhole or NXDOMAIN

Steps

  1. One resolver for every client

    Both PCs point at the same DNS server, the company resolver at 10.0.1.12, in /etc/resolv.conf. Every name they look up passes through this one box, so whatever it decides, including what to block, lands on the whole network at once.

    infectedPc:~# cat /etc/resolv.conf
    infectedPc:~# dig +short www.site
    cleanPc:~# dig +short www.site
  2. An infected host phones home, and the log names it

    infectedPc runs malware that calls home to its command-and-control (C2) domain, c2.evil. Tomasz has not blocked anything yet, so the name resolves and the beacon lands. The resolver does log every query, though, and that log is how he finds which machine is infected.

    infectedPc:~# dig +short c2.evil
    infectedPc:~# curl -sS -m3 http://c2.evil/
    resolver:~# grep c2.evil /var/log/unbound.log
  3. Block it for everyone: the sinkhole

    Time to move from watching to blocking. Turn the whole evil domain into a policy zone that answers every name under it with the sinkhole's address, 10.0.2.13. The policy covers one domain only, so a legitimate name like www.site still resolves.

    resolver:~# unbound-control local_zone evil. redirect
    resolver:~# unbound-control local_data "evil. A 10.0.2.13"
    infectedPc:~# dig +short panel.evil
    cleanPc:~# dig +short www.site
  4. The sinkhole logs who arrives

    The malware does not know anything changed, so it still beacons to c2.evil on its schedule. That name now points at the sinkhole, which means the beacon lands on your web server instead of the attacker's. The server answers with a harmless "blocked" page and writes one line per connection in its access log.

    That log is a second list of infected machines, and a stronger one than the resolver's. A lookup only shows that a machine asked for a name, which a browser prefetching links can also do. An arrival shows the machine really tried to talk to the C2.

    For Tomasz the arrival log doubles as a to-do list: every address on it is a machine to clean. The list keeps growing while infected machines keep beaconing, so a laptop that was switched off this morning shows up as soon as it boots.

    infectedPc:~# curl -sS -m3 http://c2.evil/
    sinkhole:~# grep url: /var/log/httpd.log
  5. A hard block: NXDOMAIN

    A sinkhole address is one choice; refusing the name outright is another. Change the policy to always_nxdomain and the resolver answers "no such name", so the malware cannot even start a connection.

    The beacon still fails. Watch what you lose along with it, then switch back.

    resolver:~# unbound-control local_zone evil. always_nxdomain
    infectedPc:~# dig c2.evil
    infectedPc:~# curl -sS -m3 http://c2.evil/
    resolver:~# unbound-control local_zone evil. redirect
    infectedPc:~# curl -sS -m3 http://c2.evil/

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