From 8beba5ee096dae24608158e294316f045a02ebd1 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 14 Feb 2020 17:43:31 -0300 Subject: [PATCH 1/4] Fixed rebinding protection bug when using forwarder setups BIND wasn't honoring option "deny-answer-aliases" when configured to forward queries. Before the fix it was possible for nameservers listed in "forwarders" option to return CNAME answers pointing to unrelated domains of the original query, which could be used as a vector for rebinding attacks. The fix ensures that BIND apply filters even if configured as a forwarder instance. --- lib/dns/resolver.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index bc9cc36079..7c44478a26 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -6447,9 +6447,16 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname, /* * If the target name is a subdomain of the search domain, allow it. + * + * Note that if BIND is configured as a forwarding DNS server, the + * search domain will always match the root domain ("."), so we + * must also check whether forwarding is enabled so that filters + * can be applied; see GL #1574. */ - if (dns_name_issubdomain(tname, &fctx->domain)) + if ((fctx->fwdpolicy == dns_fwdpolicy_none) && + dns_name_issubdomain(tname, &fctx->domain)) { return (true); + } /* * Otherwise, apply filters. From eace12fb70870af2dc703a93f50f75aec5d75d84 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Thu, 13 Feb 2020 20:35:25 -0300 Subject: [PATCH 2/4] Add test for the proposed fix This test asserts that option "deny-answer-aliases" works correctly when forwarding requests. As a matter of example, the behavior expected for a forwarder BIND instance, having an option such as deny-answer-aliases { "domain"; } is that when forwarding a request for *.anything-but-domain, it is expected that it will return SERVFAIL if any answer received has a CNAME for "*.domain". --- bin/tests/system/forward/ns4/malicious.db | 22 ++++++++++++++++++++++ bin/tests/system/forward/ns4/named.conf.in | 5 +++++ bin/tests/system/forward/ns5/named.conf.in | 7 +++++++ bin/tests/system/forward/ns5/rebind.db | 22 ++++++++++++++++++++++ bin/tests/system/forward/tests.sh | 13 +++++++++++++ util/copyrights | 2 ++ 6 files changed, 71 insertions(+) create mode 100644 bin/tests/system/forward/ns4/malicious.db create mode 100644 bin/tests/system/forward/ns5/rebind.db diff --git a/bin/tests/system/forward/ns4/malicious.db b/bin/tests/system/forward/ns4/malicious.db new file mode 100644 index 0000000000..b47208c164 --- /dev/null +++ b/bin/tests/system/forward/ns4/malicious.db @@ -0,0 +1,22 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, You can obtain one at http://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$TTL 86400 +@ IN SOA malicious. admin.malicious. ( + 1 ; Serial + 604800 ; Refresh + 86400 ; Retry + 2419200 ; Expire + 86400 ) ; Negative Cache TTL + +@ IN NS ns + +ns IN A 10.53.0.4 + +target IN CNAME subdomain.rebind. diff --git a/bin/tests/system/forward/ns4/named.conf.in b/bin/tests/system/forward/ns4/named.conf.in index 643e1271b5..fee76b41e5 100644 --- a/bin/tests/system/forward/ns4/named.conf.in +++ b/bin/tests/system/forward/ns4/named.conf.in @@ -55,3 +55,8 @@ zone "grafted" { forward only; forwarders { 10.53.0.2; }; }; + +zone "malicious." { + type master; + file "malicious.db"; +}; diff --git a/bin/tests/system/forward/ns5/named.conf.in b/bin/tests/system/forward/ns5/named.conf.in index 0e65985d52..6742222d4d 100644 --- a/bin/tests/system/forward/ns5/named.conf.in +++ b/bin/tests/system/forward/ns5/named.conf.in @@ -19,9 +19,16 @@ options { listen-on-v6 { none; }; forward only; forwarders { 10.53.0.4; }; + deny-answer-aliases { "rebind"; }; + dnssec-validation yes; }; zone "." { type hint; file "root.db"; }; + +zone "rebind" { + type master; + file "rebind.db"; +}; diff --git a/bin/tests/system/forward/ns5/rebind.db b/bin/tests/system/forward/ns5/rebind.db new file mode 100644 index 0000000000..3e71327a48 --- /dev/null +++ b/bin/tests/system/forward/ns5/rebind.db @@ -0,0 +1,22 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, You can obtain one at http://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$TTL 86400 +@ IN SOA rebind. admin.rebind. ( + 1 ; Serial + 604800 ; Refresh + 86400 ; Retry + 2419200 ; Expire + 86400 ) ; Negative Cache TTL + +@ IN NS ns + +ns IN A 10.53.0.5 + +subdomain IN A 10.53.0.1 diff --git a/bin/tests/system/forward/tests.sh b/bin/tests/system/forward/tests.sh index 8db1024b79..1e199e49d3 100644 --- a/bin/tests/system/forward/tests.sh +++ b/bin/tests/system/forward/tests.sh @@ -210,5 +210,18 @@ sent=`grep -c "10.53.0.7#.* (.): query '\./NS/IN' approved" ns1/named.run` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` +n=$((n+1)) +echo_i "checking that rebinding protection works in forward only mode ($n)" +ret=0 +# 10.53.0.5 will forward target.malicious. query to 10.53.0.4 +# which in turn will return a CNAME for subdomain.rebind. +# to honor the option deny-answer-aliases { "rebind"; }; +# ns5 should return a SERVFAIL to avoid potential rebinding attacks +dig_with_opts +noadd +noauth @10.53.0.5 target.malicious. > dig.out.$n || ret=1 +grep "status: SERVFAIL" dig.out.$n > /dev/null || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status+ret)) + + echo_i "exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/util/copyrights b/util/copyrights index eba1b2a554..fa07f42aba 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1433,9 +1433,11 @@ ./bin/tests/system/forward/ns2/root.db ZONE 2000,2001,2004,2007,2016,2018,2019,2020 ./bin/tests/system/forward/ns3/named.conf.in CONF-C 2018,2019,2020 ./bin/tests/system/forward/ns3/root.db ZONE 2000,2001,2004,2007,2016,2018,2019,2020 +./bin/tests/system/forward/ns4/malicious.db ZONE 2020 ./bin/tests/system/forward/ns4/named.conf.in CONF-C 2018,2019,2020 ./bin/tests/system/forward/ns4/root.db ZONE 2000,2001,2004,2007,2016,2018,2019,2020 ./bin/tests/system/forward/ns5/named.conf.in CONF-C 2018,2019,2020 +./bin/tests/system/forward/ns5/rebind.db ZONE 2020 ./bin/tests/system/forward/ns5/root.db ZONE 2011,2016,2018,2019,2020 ./bin/tests/system/forward/ns7/named.conf.in CONF-C 2019,2020 ./bin/tests/system/forward/ns7/root.db ZONE 2019,2020 From 11b825984637c431ece83031b0f8a017656750fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 8 Apr 2020 08:56:26 +0200 Subject: [PATCH 3/4] Add CHANGES --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index bdaa552fe0..aebe378e7d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +5376. [bug] Fix DNS ineffective rebinding protection when BIND 9 + is configured as a forwarding DNS server. [GL #1574] + (Thanks to Tobias Klein) + 5368. [bug] Named failed to restart if 'rndc addzone' names contained special characters (e.g. '/'). [GL #1655] From fc2bead3149670121ff6d39c96806348f778036b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 8 Apr 2020 08:58:53 +0200 Subject: [PATCH 4/4] Add release notes --- doc/arm/notes-9.11.18.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/arm/notes-9.11.18.xml b/doc/arm/notes-9.11.18.xml index f581d9e885..76d200d4b3 100644 --- a/doc/arm/notes-9.11.18.xml +++ b/doc/arm/notes-9.11.18.xml @@ -15,7 +15,9 @@ - None. + DNS rebinding protection was ineffective when BIND 9 is configured as + a forwarding DNS server. Found and responsibly reported by Tobias + Klein. [GL #1574]