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.
Steps
-
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
-
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
-
Block it for everyone: the sinkhole
Time to move from watching to blocking. Turn the whole
evildomain 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 likewww.sitestill 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
-
The sinkhole logs who arrives
The malware does not know anything changed, so it still beacons to
c2.evilon 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
-
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/