How To Patch BIND9 Against DNS Cache Poisoning On Debian Etch

Want to support HowtoForge? Become a subscriber!
Submitted by falko (Contact Author) (Forums) on Mon, 2008-07-28 15:17. :: BIND | Debian | DNS | Security

How To Patch BIND9 Against DNS Cache Poisoning On Debian Etch

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 07/28/2008

This article explains how you can fix a BIND9 nameserver on a Debian Etch system so that it is not vulnerable anymore to DNS cache poisoning.

This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!


1 Checking If BIND Is Vulnerable

Run the following command against your nameserver to find out if it is vulnerable (replace with your own nameserver address):

dig +short TXT

mh1:~# dig +short TXT
" is POOR: 26 queries in 4.4 seconds from 1 ports with std dev 0.00"

POOR indicates that BIND is vulnerable. In this case you must patch BIND.

If you don't get any answer at all, this means that your DNS server is no recursive resolver which means it doesn't answer queries for domains that it isn't authoritative for. In this case you're not vulnerable to cache poisoning, but still I strongly advise to update BIND!


2 Patching BIND

This is not so much a patch, but an update. Simply run

apt-get install bind9 bind9-host

This will install the updated BIND packages from the Debian repositories.

Afterwards open /etc/bind/named.conf and modify the options section. If you don't need a recursive resolver (i.e., if your nameserver should answer only queries for domains that it is responsible for), add allow-recursion { none; };. That way you turn off caching for other domains. The second line you should add is dnssec-enable yes; - this makes that BIND answers queries on random ports which are harder to guess for hackers (remember the answer to our dig command in chapter 1: [...]26 queries in 4.4 seconds from 1 ports[...] - BIND was answering on only one port...).

Correction: I've just received the following email from Alan Clegg:

Good day!

I just read your writeup at:

and have a couple of comments.

First off, thanks for writing this. We need as many people to fix this
problem as possible.

Secondly, there is a minor error that should be corrected. You state:

"The second line you should add is dnssec-enable yes; - this makes that
BIND answers queries on random ports which are harder to guess for hackers"

Actually, this line enables the server to respond with DNSSEC records
when the "DO" (DNSSEC OK) bit is set in the question being asked.

What you want people to look for is a statement like:

query-source [...] port XX;

Where the XX is a fixed port number on which the queries from this
system are to be sent. This undoes everything that the new versions of
BIND do to randomize the UDP source port.

If you have any questions, please feel free to send e-mail.

Alan Clegg
Internet Systems Consortium (ISC)
Training and Support

vi /etc/bind/named.conf

options {
        pid-file "/var/run/bind/run/";
        directory "/etc/bind";
        auth-nxdomain no;
        allow-recursion { none; };
        dnssec-enable yes;
         * If there is a firewall between you and nameservers you want
         * to talk to, you might need to uncomment the query-source
         * directive below.  Previous versions of BIND always asked
         * questions using port 53, but BIND 8.1 uses an unprivileged
         * port by default.
        // query-source address * port 53;

Restart BIND afterwards:

/etc/init.d/bind9 restart

(If you're using ISPConfig, your changes will be overwritten by ISPConfig. To prevent this, we take the named.conf template file /root/ispconfig/isp/conf/named.conf.master, modify it as shown above, and save the modified template in the /root/ispconfig/isp/conf/customized_templates directory => /root/ispconfig/isp/conf/customized_templates/named.conf.master. Please also modify /etc/bind/named.conf as shown above in addition to that.)


3 Checking BIND Again

Now we run the query from chapter 1 again:

dig +short TXT

If all went well, it should now show GOOD instead of POOR, and it should use more than just one port:

mh1:~# dig +short TXT
" is GOOD: 26 queries in 4.4 seconds from 26 ports with std dev 20195.32"

Congratulations, you have just fixed BIND!

You can also run the dig command against your ISP's nameservers to find out if their nameservers are still vulnerable. If they are, you should urge your ISP to update their nameservers!

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Martinss (registered user) on Thu, 2008-08-21 12:41.

After I updated, and edited all files, i checked my server again, but there was nothing to output - that means, that there all is ok?

 In consule looks like:

root@server:~# dig +short TXT


Submitted by admin (registered user) on Fri, 2008-08-22 09:03.
This probably means that your name server isn't a recursive resolver anymore which is fine.
Submitted by Snowman (registered user) on Thu, 2008-07-31 14:45.
is it possible to do this upgrade while server is running ispconfig ?
Submitted by admin (registered user) on Fri, 2008-08-01 08:11.
Submitted by nssy (registered user) on Tue, 2008-07-29 07:17.
nice and simple. thanks