Blame SOURCES/bind-9.16-CVE-2021-25220-test.patch

0ba27c
From bd8fdeb2d1ece6db6dfe9fdc024f3a81440c1c0c Mon Sep 17 00:00:00 2001
0ba27c
From: Mark Andrews <marka@isc.org>
0ba27c
Date: Tue, 18 Jan 2022 00:19:47 +1100
0ba27c
Subject: [PATCH] Add tests for forwarder cache poisoning scenarios
0ba27c
0ba27c
- Check that an NS in an authority section returned from a forwarder
0ba27c
  which is above the name in a configured "forward first" or "forward
0ba27c
  only" zone (i.e., net/NS in a response from a forwarder configured for
0ba27c
  local.net) is not cached.
0ba27c
- Test that a DNAME for a parent domain will not be cached when sent
0ba27c
  in a response from a forwarder configured to answer for a child.
0ba27c
- Check that glue is rejected if its name falls below that of zone
0ba27c
  configured locally.
0ba27c
- Check that an extra out-of-bailiwick data in the answer section is
0ba27c
  not cached (this was already working correctly, but was not explicitly
0ba27c
  tested before).
0ba27c
0ba27c
(cherry picked from commit bf3fffff67e1de78e9387a93674d471bf4291604)
0ba27c
(cherry picked from commit 59d1eb3ff810145c8098a0a4fbf93ef4380ad739)
0ba27c
---
0ba27c
 bin/tests/system/forward/ans11/ans.py         | 136 ++++++++++++++++++
0ba27c
 bin/tests/system/forward/clean.sh             |   2 +
0ba27c
 bin/tests/system/forward/ns1/diditwork.net.db |  22 +++
0ba27c
 bin/tests/system/forward/ns1/named.conf.in    |  20 +++
0ba27c
 bin/tests/system/forward/ns1/net.example.lll  |  15 ++
0ba27c
 bin/tests/system/forward/ns1/spoofed.net.db   |  22 +++
0ba27c
 bin/tests/system/forward/ns1/sub.local.net.db |  22 +++
0ba27c
 bin/tests/system/forward/ns10/fakenet.zone    |  17 +++
0ba27c
 bin/tests/system/forward/ns10/fakenet2.zone   |  15 ++
0ba27c
 .../system/forward/ns10/fakesublocalnet.zone  |  15 ++
0ba27c
 .../system/forward/ns10/fakesublocaltld.zone  |  15 ++
0ba27c
 bin/tests/system/forward/ns10/named.conf.in   |  53 +++++++
0ba27c
 bin/tests/system/forward/ns10/net.example.lll |  15 ++
0ba27c
 bin/tests/system/forward/ns10/spoofednet.zone |  16 +++
0ba27c
 bin/tests/system/forward/ns2/tld.db           |   6 +
0ba27c
 bin/tests/system/forward/ns4/named.conf.in    |   5 +
0ba27c
 bin/tests/system/forward/ns4/sibling.tld.db   |  22 +++
0ba27c
 bin/tests/system/forward/ns8/named.conf.in    |   5 +
0ba27c
 bin/tests/system/forward/ns8/sub.local.tld.db |  15 ++
0ba27c
 bin/tests/system/forward/ns9/local.net.db     |  16 +++
0ba27c
 bin/tests/system/forward/ns9/local.tld.db     |  15 ++
0ba27c
 bin/tests/system/forward/ns9/named1.conf.in   |  67 +++++++++
0ba27c
 bin/tests/system/forward/ns9/named2.conf.in   |  70 +++++++++
0ba27c
 bin/tests/system/forward/ns9/named3.conf.in   |  50 +++++++
0ba27c
 bin/tests/system/forward/ns9/named4.conf.in   |  47 ++++++
0ba27c
 bin/tests/system/forward/ns9/root.db          |  13 ++
0ba27c
 bin/tests/system/forward/setup.sh             |   2 +
0ba27c
 bin/tests/system/forward/tests.sh             | 122 ++++++++++++++++
0ba27c
 bin/tests/system/ifconfig.sh                  |   8 +-
0ba27c
 29 files changed, 844 insertions(+), 4 deletions(-)
0ba27c
 create mode 100644 bin/tests/system/forward/ans11/ans.py
0ba27c
 create mode 100644 bin/tests/system/forward/ns1/diditwork.net.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns1/net.example.lll
0ba27c
 create mode 100644 bin/tests/system/forward/ns1/spoofed.net.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns1/sub.local.net.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/fakenet.zone
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/fakenet2.zone
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/fakesublocalnet.zone
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/fakesublocaltld.zone
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/named.conf.in
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/net.example.lll
0ba27c
 create mode 100644 bin/tests/system/forward/ns10/spoofednet.zone
0ba27c
 create mode 100644 bin/tests/system/forward/ns4/sibling.tld.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns8/sub.local.tld.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/local.net.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/local.tld.db
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/named1.conf.in
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/named2.conf.in
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/named3.conf.in
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/named4.conf.in
0ba27c
 create mode 100644 bin/tests/system/forward/ns9/root.db
0ba27c
0ba27c
diff --git a/bin/tests/system/forward/ans11/ans.py b/bin/tests/system/forward/ans11/ans.py
0ba27c
new file mode 100644
0ba27c
index 0000000000..1d35b3d3f1
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ans11/ans.py
0ba27c
@@ -0,0 +1,136 @@
0ba27c
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+#
0ba27c
+# SPDX-License-Identifier: MPL-2.0
0ba27c
+#
0ba27c
+# This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+#
0ba27c
+# See the COPYRIGHT file distributed with this work for additional
0ba27c
+# information regarding copyright ownership.
0ba27c
+
0ba27c
+from __future__ import print_function
0ba27c
+import os
0ba27c
+import sys
0ba27c
+import signal
0ba27c
+import socket
0ba27c
+import select
0ba27c
+from datetime import datetime, timedelta
0ba27c
+import time
0ba27c
+import functools
0ba27c
+
0ba27c
+import dns, dns.message, dns.query, dns.flags
0ba27c
+from dns.rdatatype import *
0ba27c
+from dns.rdataclass import *
0ba27c
+from dns.rcode import *
0ba27c
+from dns.name import *
0ba27c
+
0ba27c
+# Log query to file
0ba27c
+def logquery(type, qname):
0ba27c
+    with open("qlog", "a") as f:
0ba27c
+        f.write("%s %s\n", type, qname)
0ba27c
+
0ba27c
+############################################################################
0ba27c
+# Respond to a DNS query.
0ba27c
+############################################################################
0ba27c
+def create_response(msg):
0ba27c
+    m = dns.message.from_wire(msg)
0ba27c
+    qname = m.question[0].name.to_text()
0ba27c
+    rrtype = m.question[0].rdtype
0ba27c
+    typename = dns.rdatatype.to_text(rrtype)
0ba27c
+
0ba27c
+    with open("query.log", "a") as f:
0ba27c
+        f.write("%s %s\n" % (typename, qname))
0ba27c
+        print("%s %s" % (typename, qname), end=" ")
0ba27c
+
0ba27c
+    r = dns.message.make_response(m)
0ba27c
+    r.set_rcode(NOERROR)
0ba27c
+    if rrtype == A:
0ba27c
+        tld=qname.split('.')[-2] + '.'
0ba27c
+        ns="local." + tld
0ba27c
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, A, "10.53.0.11"))
0ba27c
+        r.answer.append(dns.rrset.from_text(tld, 300, IN, NS, "local." + tld))
0ba27c
+        r.additional.append(dns.rrset.from_text(ns, 300, IN, A, "10.53.0.11"))
0ba27c
+    elif rrtype == NS:
0ba27c
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, NS, "."))
0ba27c
+    elif rrtype == SOA:
0ba27c
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, SOA, ". . 0 0 0 0 0"))
0ba27c
+    else:
0ba27c
+        r.authority.append(dns.rrset.from_text(qname, 300, IN, SOA, ". . 0 0 0 0 0"))
0ba27c
+    r.flags |= dns.flags.AA
0ba27c
+    return r
0ba27c
+
0ba27c
+def sigterm(signum, frame):
0ba27c
+    print ("Shutting down now...")
0ba27c
+    os.remove('ans.pid')
0ba27c
+    running = False
0ba27c
+    sys.exit(0)
0ba27c
+
0ba27c
+############################################################################
0ba27c
+# Main
0ba27c
+#
0ba27c
+# Set up responder and control channel, open the pid file, and start
0ba27c
+# the main loop, listening for queries on the query channel or commands
0ba27c
+# on the control channel and acting on them.
0ba27c
+############################################################################
0ba27c
+ip4 = "10.53.0.11"
0ba27c
+ip6 = "fd92:7065:b8e:ffff::11"
0ba27c
+
0ba27c
+try: port=int(os.environ['PORT'])
0ba27c
+except: port=5300
0ba27c
+
0ba27c
+query4_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
0ba27c
+query4_socket.bind((ip4, port))
0ba27c
+havev6 = True
0ba27c
+try:
0ba27c
+    query6_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
0ba27c
+    try:
0ba27c
+        query6_socket.bind((ip6, port))
0ba27c
+    except:
0ba27c
+        query6_socket.close()
0ba27c
+        havev6 = False
0ba27c
+except:
0ba27c
+    havev6 = False
0ba27c
+signal.signal(signal.SIGTERM, sigterm)
0ba27c
+
0ba27c
+f = open('ans.pid', 'w')
0ba27c
+pid = os.getpid()
0ba27c
+print (pid, file=f)
0ba27c
+f.close()
0ba27c
+
0ba27c
+running = True
0ba27c
+
0ba27c
+print ("Listening on %s port %d" % (ip4, port))
0ba27c
+if havev6:
0ba27c
+    print ("Listening on %s port %d" % (ip6, port))
0ba27c
+print ("Ctrl-c to quit")
0ba27c
+
0ba27c
+if havev6:
0ba27c
+    input = [query4_socket, query6_socket]
0ba27c
+else:
0ba27c
+    input = [query4_socket]
0ba27c
+
0ba27c
+while running:
0ba27c
+    try:
0ba27c
+        inputready, outputready, exceptready = select.select(input, [], [])
0ba27c
+    except select.error as e:
0ba27c
+        break
0ba27c
+    except socket.error as e:
0ba27c
+        break
0ba27c
+    except KeyboardInterrupt:
0ba27c
+        break
0ba27c
+
0ba27c
+    for s in inputready:
0ba27c
+        if s == query4_socket or s == query6_socket:
0ba27c
+            print ("Query received on %s" %
0ba27c
+                    (ip4 if s == query4_socket else ip6), end=" ")
0ba27c
+            # Handle incoming queries
0ba27c
+            msg = s.recvfrom(65535)
0ba27c
+            rsp = create_response(msg[0])
0ba27c
+            if rsp:
0ba27c
+                print(dns.rcode.to_text(rsp.rcode()))
0ba27c
+                s.sendto(rsp.to_wire(), msg[1])
0ba27c
+            else:
0ba27c
+                print("NO RESPONSE")
0ba27c
+    if not running:
0ba27c
+        break
0ba27c
diff --git a/bin/tests/system/forward/clean.sh b/bin/tests/system/forward/clean.sh
0ba27c
index bc04eadb2c..b65b092680 100644
0ba27c
--- a/bin/tests/system/forward/clean.sh
0ba27c
+++ b/bin/tests/system/forward/clean.sh
0ba27c
@@ -10,10 +10,12 @@
0ba27c
 #
0ba27c
 # Clean up after forward tests.
0ba27c
 #
0ba27c
+rm -f ./ans11/query.log
0ba27c
 rm -f ./dig.out.*
0ba27c
 rm -f ./*/named.conf
0ba27c
 rm -f ./*/named.memstats
0ba27c
 rm -f ./*/named.run ./*/named.run.prev
0ba27c
+rm -f ./*/named_dump.db
0ba27c
 rm -f ./ns*/named.lock
0ba27c
 rm -f ./ns*/managed-keys.bind*
0ba27c
 rm -f ./ns1/root.db ./ns1/root.db.signed
0ba27c
diff --git a/bin/tests/system/forward/ns1/diditwork.net.db b/bin/tests/system/forward/ns1/diditwork.net.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..fd9a46eb0c
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns1/diditwork.net.db
0ba27c
@@ -0,0 +1,22 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 300	; 5 minutes
0ba27c
+@			IN SOA	ns root (
0ba27c
+				2000082401 ; serial
0ba27c
+				1800       ; refresh (30 minutes)
0ba27c
+				1800       ; retry (30 minutes)
0ba27c
+				1814400    ; expire (3 weeks)
0ba27c
+				3600       ; minimum (1 hour)
0ba27c
+				)
0ba27c
+			NS	ns
0ba27c
+			TXT	"recursed"
0ba27c
+ns			A	10.53.0.1
0ba27c
diff --git a/bin/tests/system/forward/ns1/named.conf.in b/bin/tests/system/forward/ns1/named.conf.in
0ba27c
index 4aef4e55e5..c5fb2eb172 100644
0ba27c
--- a/bin/tests/system/forward/ns1/named.conf.in
0ba27c
+++ b/bin/tests/system/forward/ns1/named.conf.in
0ba27c
@@ -63,3 +63,23 @@ zone "sld.tld" {
0ba27c
 zone "example6" {
0ba27c
 	type forward;
0ba27c
 };
0ba27c
+
0ba27c
+zone "diditwork.net" {
0ba27c
+	type primary;
0ba27c
+	file "diditwork.net.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "spoofed.net" {
0ba27c
+	type primary;
0ba27c
+	file "spoofed.net.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "sub.local.net" {
0ba27c
+	type primary;
0ba27c
+	file "sub.local.net.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "net.example.lll" {
0ba27c
+	type master;
0ba27c
+	file "net.example.lll";
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns1/net.example.lll b/bin/tests/system/forward/ns1/net.example.lll
0ba27c
new file mode 100644
0ba27c
index 0000000000..ba0804fd75
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns1/net.example.lll
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+net.example.lll.		SOA	. . 0 0 0 0 0
0ba27c
+net.example.lll.		NS	attackSecureDomain.net.
0ba27c
+didItWork.net.example.lll.	TXT	"if you can see this record the attack worked"
0ba27c
diff --git a/bin/tests/system/forward/ns1/spoofed.net.db b/bin/tests/system/forward/ns1/spoofed.net.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..eedc46f5c0
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns1/spoofed.net.db
0ba27c
@@ -0,0 +1,22 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 300	; 5 minutes
0ba27c
+@			IN SOA	ns root (
0ba27c
+				2000082401 ; serial
0ba27c
+				1800       ; refresh (30 minutes)
0ba27c
+				1800       ; retry (30 minutes)
0ba27c
+				1814400    ; expire (3 weeks)
0ba27c
+				3600       ; minimum (1 hour)
0ba27c
+				)
0ba27c
+			NS	ns
0ba27c
+ns			A	10.53.0.1
0ba27c
+sub			TXT	"recursed"
0ba27c
diff --git a/bin/tests/system/forward/ns1/sub.local.net.db b/bin/tests/system/forward/ns1/sub.local.net.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..fd9a46eb0c
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns1/sub.local.net.db
0ba27c
@@ -0,0 +1,22 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 300	; 5 minutes
0ba27c
+@			IN SOA	ns root (
0ba27c
+				2000082401 ; serial
0ba27c
+				1800       ; refresh (30 minutes)
0ba27c
+				1800       ; retry (30 minutes)
0ba27c
+				1814400    ; expire (3 weeks)
0ba27c
+				3600       ; minimum (1 hour)
0ba27c
+				)
0ba27c
+			NS	ns
0ba27c
+			TXT	"recursed"
0ba27c
+ns			A	10.53.0.1
0ba27c
diff --git a/bin/tests/system/forward/ns10/fakenet.zone b/bin/tests/system/forward/ns10/fakenet.zone
0ba27c
new file mode 100644
0ba27c
index 0000000000..b655a32459
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/fakenet.zone
0ba27c
@@ -0,0 +1,17 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+net.			SOA	. . 0 0 0 0 0
0ba27c
+net.			NS	attackSecureDomain.net.
0ba27c
+attackSecureDomain.net.	A	10.53.0.10
0ba27c
+didItWork.net.		TXT	"if you can see this record the attack worked"
0ba27c
+ns.spoofed.net.		A	10.53.0.10
0ba27c
diff --git a/bin/tests/system/forward/ns10/fakenet2.zone b/bin/tests/system/forward/ns10/fakenet2.zone
0ba27c
new file mode 100644
0ba27c
index 0000000000..cd1e6e9944
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/fakenet2.zone
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+net2.			SOA	. . 0 0 0 0 0
0ba27c
+net2.			NS	attackSecureDomain.net.
0ba27c
+net2.			DNAME	net.example.lll.
0ba27c
diff --git a/bin/tests/system/forward/ns10/fakesublocalnet.zone b/bin/tests/system/forward/ns10/fakesublocalnet.zone
0ba27c
new file mode 100644
0ba27c
index 0000000000..160b5332b2
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/fakesublocalnet.zone
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+sub.local.net.		SOA	. . 0 0 0 0 0
0ba27c
+sub.local.net.		NS	ns.spoofed.net.
0ba27c
+sub.local.net.		TXT	"if you see this attacker overrode local delegation"
0ba27c
diff --git a/bin/tests/system/forward/ns10/fakesublocaltld.zone b/bin/tests/system/forward/ns10/fakesublocaltld.zone
0ba27c
new file mode 100644
0ba27c
index 0000000000..f78cbc77f6
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/fakesublocaltld.zone
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+sub.local.tld.		3600	IN	SOA	. . 0 0 0 0 0
0ba27c
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
0ba27c
+sub.local.tld.		3600	IN	TXT	bad
0ba27c
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
0ba27c
diff --git a/bin/tests/system/forward/ns10/named.conf.in b/bin/tests/system/forward/ns10/named.conf.in
0ba27c
new file mode 100644
0ba27c
index 0000000000..1f318dd867
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/named.conf.in
0ba27c
@@ -0,0 +1,53 @@
0ba27c
+/*
0ba27c
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+ *
0ba27c
+ * SPDX-License-Identifier: MPL-2.0
0ba27c
+ *
0ba27c
+ * This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+ *
0ba27c
+ * See the COPYRIGHT file distributed with this work for additional
0ba27c
+ * information regarding copyright ownership.
0ba27c
+ */
0ba27c
+
0ba27c
+options {
0ba27c
+	query-source address 10.53.0.10;
0ba27c
+	notify-source 10.53.0.10;
0ba27c
+	transfer-source 10.53.0.10;
0ba27c
+	port @PORT@;
0ba27c
+	pid-file "named.pid";
0ba27c
+	listen-on { 10.53.0.10; };
0ba27c
+	listen-on-v6 { none; };
0ba27c
+	minimal-responses no;
0ba27c
+};
0ba27c
+
0ba27c
+zone "net." {
0ba27c
+	type master;
0ba27c
+	file "fakenet.zone";
0ba27c
+};
0ba27c
+
0ba27c
+zone "spoofed.net." {
0ba27c
+	type master;
0ba27c
+	file "spoofednet.zone";
0ba27c
+};
0ba27c
+
0ba27c
+zone "sub.local.net." {
0ba27c
+	type master;
0ba27c
+	file "fakesublocalnet.zone";
0ba27c
+};
0ba27c
+
0ba27c
+zone "net2" {
0ba27c
+	type master;
0ba27c
+	file "fakenet2.zone";
0ba27c
+};
0ba27c
+
0ba27c
+zone "net.example.lll" {
0ba27c
+	type master;
0ba27c
+	file "net.example.lll";
0ba27c
+};
0ba27c
+
0ba27c
+zone "sub.local.tld." {
0ba27c
+	type master;
0ba27c
+	file "fakesublocaltld.zone";
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns10/net.example.lll b/bin/tests/system/forward/ns10/net.example.lll
0ba27c
new file mode 100644
0ba27c
index 0000000000..ba0804fd75
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/net.example.lll
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+net.example.lll.		SOA	. . 0 0 0 0 0
0ba27c
+net.example.lll.		NS	attackSecureDomain.net.
0ba27c
+didItWork.net.example.lll.	TXT	"if you can see this record the attack worked"
0ba27c
diff --git a/bin/tests/system/forward/ns10/spoofednet.zone b/bin/tests/system/forward/ns10/spoofednet.zone
0ba27c
new file mode 100644
0ba27c
index 0000000000..fb70a4372b
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns10/spoofednet.zone
0ba27c
@@ -0,0 +1,16 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL 86400
0ba27c
+spoofed.net.		SOA	. . 0 0 0 0 0
0ba27c
+spoofed.net.		NS	ns.spoofed.net.
0ba27c
+ns.spoofed.net.		A	10.53.0.10
0ba27c
+spoofed.net.		TXT	"this record is clearly spoofed"
0ba27c
diff --git a/bin/tests/system/forward/ns2/tld.db b/bin/tests/system/forward/ns2/tld.db
0ba27c
index 61b6569b07..819210dc05 100644
0ba27c
--- a/bin/tests/system/forward/ns2/tld.db
0ba27c
+++ b/bin/tests/system/forward/ns2/tld.db
0ba27c
@@ -10,3 +10,9 @@ $TTL 300	; 5 minutes
0ba27c
 ns			A	10.53.0.2
0ba27c
 sld			NS	ns.sld
0ba27c
 ns.sld			A	10.53.0.1
0ba27c
+local			NS	ns.local
0ba27c
+ns.local		A	10.53.0.9
0ba27c
+sibling			NS	ns.sibling
0ba27c
+ns.sibling		A	10.53.0.4
0ba27c
+sibling			NS	ns.sub.local
0ba27c
+ns.sub.local		A	10.53.0.10
0ba27c
diff --git a/bin/tests/system/forward/ns4/named.conf.in b/bin/tests/system/forward/ns4/named.conf.in
0ba27c
index 855b4bfb82..85349aa97e 100644
0ba27c
--- a/bin/tests/system/forward/ns4/named.conf.in
0ba27c
+++ b/bin/tests/system/forward/ns4/named.conf.in
0ba27c
@@ -60,3 +60,8 @@ zone "malicious." {
0ba27c
 	type primary;
0ba27c
 	file "malicious.db";
0ba27c
 };
0ba27c
+
0ba27c
+zone "sibling.tld" {
0ba27c
+	type primary;
0ba27c
+	file "sibling.tld.db";
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns4/sibling.tld.db b/bin/tests/system/forward/ns4/sibling.tld.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..fe080ae974
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns4/sibling.tld.db
0ba27c
@@ -0,0 +1,22 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+$TTL    86400
0ba27c
+@       IN      SOA     malicious. admin.malicious. (
0ba27c
+                              1         ; Serial
0ba27c
+                         604800         ; Refresh
0ba27c
+                          86400         ; Retry
0ba27c
+                        2419200         ; Expire
0ba27c
+                          86400 )       ; Negative Cache TTL
0ba27c
+
0ba27c
+@           IN    NS      ns
0ba27c
+
0ba27c
+ns          IN    A       10.53.0.4
0ba27c
diff --git a/bin/tests/system/forward/ns8/named.conf.in b/bin/tests/system/forward/ns8/named.conf.in
0ba27c
index 531ff59ece..f752eae885 100644
0ba27c
--- a/bin/tests/system/forward/ns8/named.conf.in
0ba27c
+++ b/bin/tests/system/forward/ns8/named.conf.in
0ba27c
@@ -26,3 +26,8 @@ zone "." {
0ba27c
 	type hint;
0ba27c
 	file "root.db";
0ba27c
 };
0ba27c
+
0ba27c
+zone "sub.local.tld" {
0ba27c
+	type primary;
0ba27c
+	file "sub.local.tld.db";
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns8/sub.local.tld.db b/bin/tests/system/forward/ns8/sub.local.tld.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..f2234c754e
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns8/sub.local.tld.db
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+sub.local.tld.		3600	IN	SOA	. . 0 0 0 0 0
0ba27c
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
0ba27c
+sub.local.tld.		3600	IN	TXT	good
0ba27c
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
0ba27c
diff --git a/bin/tests/system/forward/ns9/local.net.db b/bin/tests/system/forward/ns9/local.net.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..af0d2a5a67
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/local.net.db
0ba27c
@@ -0,0 +1,16 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+local.net.		3600	IN	SOA	. . 0 0 0 0 0
0ba27c
+local.net.		3600	IN	NS	localhost.
0ba27c
+ns.local.net.		3600	IN	A	10.53.0.9
0ba27c
+txt.local.net.		3600	IN	TXT	"something in the local auth zone"
0ba27c
+sub.local.net.		3600	IN	NS	ns.spoofed.net.  ; attacker will try to override this
0ba27c
diff --git a/bin/tests/system/forward/ns9/local.tld.db b/bin/tests/system/forward/ns9/local.tld.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..876a9139da
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/local.tld.db
0ba27c
@@ -0,0 +1,15 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+local.tld.		3600	IN	SOA	. . 0 0 0 0 0
0ba27c
+local.tld.		3600	IN	NS	localhost.
0ba27c
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
0ba27c
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
0ba27c
diff --git a/bin/tests/system/forward/ns9/named1.conf.in b/bin/tests/system/forward/ns9/named1.conf.in
0ba27c
new file mode 100644
0ba27c
index 0000000000..be9a43842f
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/named1.conf.in
0ba27c
@@ -0,0 +1,67 @@
0ba27c
+/*
0ba27c
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+ *
0ba27c
+ * SPDX-License-Identifier: MPL-2.0
0ba27c
+ *
0ba27c
+ * This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+ *
0ba27c
+ * See the COPYRIGHT file distributed with this work for additional
0ba27c
+ * information regarding copyright ownership.
0ba27c
+ */
0ba27c
+
0ba27c
+options {
0ba27c
+	query-source address 10.53.0.9;
0ba27c
+	notify-source 10.53.0.9;
0ba27c
+	transfer-source 10.53.0.9;
0ba27c
+	port @PORT@;
0ba27c
+	pid-file "named.pid";
0ba27c
+	listen-on { 10.53.0.9; };
0ba27c
+	listen-on-v6 { none; };
0ba27c
+	dnssec-validation no;
0ba27c
+	edns-udp-size 1232;
0ba27c
+};
0ba27c
+
0ba27c
+key rndc_key {
0ba27c
+	secret "1234abcd8765";
0ba27c
+	algorithm hmac-sha256;
0ba27c
+};
0ba27c
+
0ba27c
+controls {
0ba27c
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.10 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.11 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+zone "." {
0ba27c
+	type hint;
0ba27c
+	file "root.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net." {
0ba27c
+	type forward;
0ba27c
+	forwarders { 10.53.0.10; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net2." {
0ba27c
+	type forward;
0ba27c
+	forwarders { 10.53.0.10; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net3." {
0ba27c
+	type forward;
0ba27c
+	forwarders { 10.53.0.11; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "local.net." {
0ba27c
+	type primary;
0ba27c
+	file "local.net.db";
0ba27c
+	forwarders {};
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns9/named2.conf.in b/bin/tests/system/forward/ns9/named2.conf.in
0ba27c
new file mode 100644
0ba27c
index 0000000000..2c40b42a0c
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/named2.conf.in
0ba27c
@@ -0,0 +1,70 @@
0ba27c
+/*
0ba27c
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+ *
0ba27c
+ * SPDX-License-Identifier: MPL-2.0
0ba27c
+ *
0ba27c
+ * This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+ *
0ba27c
+ * See the COPYRIGHT file distributed with this work for additional
0ba27c
+ * information regarding copyright ownership.
0ba27c
+ */
0ba27c
+
0ba27c
+options {
0ba27c
+	query-source address 10.53.0.9;
0ba27c
+	notify-source 10.53.0.9;
0ba27c
+	transfer-source 10.53.0.9;
0ba27c
+	port @PORT@;
0ba27c
+	pid-file "named.pid";
0ba27c
+	listen-on { 10.53.0.9; };
0ba27c
+	listen-on-v6 { none; };
0ba27c
+	dnssec-validation no;
0ba27c
+	edns-udp-size 1232;
0ba27c
+};
0ba27c
+
0ba27c
+key rndc_key {
0ba27c
+	secret "1234abcd8765";
0ba27c
+	algorithm hmac-sha256;
0ba27c
+};
0ba27c
+
0ba27c
+controls {
0ba27c
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.10 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.11 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+zone "." {
0ba27c
+	type hint;
0ba27c
+	file "root.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net." {
0ba27c
+	type forward;
0ba27c
+	forward only;
0ba27c
+	forwarders { 10.53.0.10; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net2." {
0ba27c
+	type forward;
0ba27c
+	forward only;
0ba27c
+	forwarders { 10.53.0.10; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "attacksecuredomain.net3." {
0ba27c
+	type forward;
0ba27c
+	forward only;
0ba27c
+	forwarders { 10.53.0.11; };
0ba27c
+};
0ba27c
+
0ba27c
+zone "local.net." {
0ba27c
+	type primary;
0ba27c
+	file "local.net.db";
0ba27c
+	forwarders {};
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns9/named3.conf.in b/bin/tests/system/forward/ns9/named3.conf.in
0ba27c
new file mode 100644
0ba27c
index 0000000000..576f57c10b
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/named3.conf.in
0ba27c
@@ -0,0 +1,50 @@
0ba27c
+/*
0ba27c
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+ *
0ba27c
+ * SPDX-License-Identifier: MPL-2.0
0ba27c
+ *
0ba27c
+ * This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+ *
0ba27c
+ * See the COPYRIGHT file distributed with this work for additional
0ba27c
+ * information regarding copyright ownership.
0ba27c
+ */
0ba27c
+
0ba27c
+options {
0ba27c
+	query-source address 10.53.0.9;
0ba27c
+	notify-source 10.53.0.9;
0ba27c
+	transfer-source 10.53.0.9;
0ba27c
+	port @PORT@;
0ba27c
+	pid-file "named.pid";
0ba27c
+	listen-on { 10.53.0.9; };
0ba27c
+	listen-on-v6 { none; };
0ba27c
+	dnssec-validation no;
0ba27c
+	edns-udp-size 1232;
0ba27c
+	forward only;
0ba27c
+	forwarders { 10.53.0.10; };
0ba27c
+};
0ba27c
+
0ba27c
+key rndc_key {
0ba27c
+	secret "1234abcd8765";
0ba27c
+	algorithm hmac-sha256;
0ba27c
+};
0ba27c
+
0ba27c
+controls {
0ba27c
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.10 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+zone "." {
0ba27c
+	type hint;
0ba27c
+	file "root.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "local.net." {
0ba27c
+	type primary;
0ba27c
+	file "local.net.db";
0ba27c
+	forwarders {};
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns9/named4.conf.in b/bin/tests/system/forward/ns9/named4.conf.in
0ba27c
new file mode 100644
0ba27c
index 0000000000..5cd7d84109
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/named4.conf.in
0ba27c
@@ -0,0 +1,47 @@
0ba27c
+/*
0ba27c
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+ *
0ba27c
+ * SPDX-License-Identifier: MPL-2.0
0ba27c
+ *
0ba27c
+ * This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+ *
0ba27c
+ * See the COPYRIGHT file distributed with this work for additional
0ba27c
+ * information regarding copyright ownership.
0ba27c
+ */
0ba27c
+
0ba27c
+options {
0ba27c
+	query-source address 10.53.0.9;
0ba27c
+	notify-source 10.53.0.9;
0ba27c
+	transfer-source 10.53.0.9;
0ba27c
+	port @PORT@;
0ba27c
+	pid-file "named.pid";
0ba27c
+	listen-on { 10.53.0.9; };
0ba27c
+	listen-on-v6 { none; };
0ba27c
+	dnssec-validation no;
0ba27c
+	edns-udp-size 1232;
0ba27c
+};
0ba27c
+
0ba27c
+key rndc_key {
0ba27c
+	secret "1234abcd8765";
0ba27c
+	algorithm hmac-sha256;
0ba27c
+};
0ba27c
+
0ba27c
+controls {
0ba27c
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
0ba27c
+};
0ba27c
+
0ba27c
+server 10.53.0.10 {
0ba27c
+	edns no;
0ba27c
+};
0ba27c
+
0ba27c
+zone "." {
0ba27c
+	type hint;
0ba27c
+	file "root.db";
0ba27c
+};
0ba27c
+
0ba27c
+zone "local.tld." {
0ba27c
+	type primary;
0ba27c
+	file "local.tld.db";
0ba27c
+};
0ba27c
diff --git a/bin/tests/system/forward/ns9/root.db b/bin/tests/system/forward/ns9/root.db
0ba27c
new file mode 100644
0ba27c
index 0000000000..2cbdff5977
0ba27c
--- /dev/null
0ba27c
+++ b/bin/tests/system/forward/ns9/root.db
0ba27c
@@ -0,0 +1,13 @@
0ba27c
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
0ba27c
+;
0ba27c
+; SPDX-License-Identifier: MPL-2.0
0ba27c
+;
0ba27c
+; This Source Code Form is subject to the terms of the Mozilla Public
0ba27c
+; License, v. 2.0.  If a copy of the MPL was not distributed with this
0ba27c
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
0ba27c
+;
0ba27c
+; See the COPYRIGHT file distributed with this work for additional
0ba27c
+; information regarding copyright ownership.
0ba27c
+
0ba27c
+.			NS	a.root-servers.nil.
0ba27c
+a.root-servers.nil.	A	10.53.0.1
0ba27c
diff --git a/bin/tests/system/forward/setup.sh b/bin/tests/system/forward/setup.sh
0ba27c
index 21cf67b782..a56dd3c03f 100644
0ba27c
--- a/bin/tests/system/forward/setup.sh
0ba27c
+++ b/bin/tests/system/forward/setup.sh
0ba27c
@@ -19,6 +19,8 @@ copy_setports ns4/named.conf.in ns4/named.conf
0ba27c
 copy_setports ns5/named.conf.in ns5/named.conf
0ba27c
 copy_setports ns7/named.conf.in ns7/named.conf
0ba27c
 copy_setports ns8/named.conf.in ns8/named.conf
0ba27c
+copy_setports ns9/named1.conf.in ns9/named.conf
0ba27c
+copy_setports ns10/named.conf.in ns10/named.conf
0ba27c
 
0ba27c
 (
0ba27c
     cd ns1
0ba27c
diff --git a/bin/tests/system/forward/tests.sh b/bin/tests/system/forward/tests.sh
0ba27c
index 6096b06ca7..dfbaf887f7 100644
0ba27c
--- a/bin/tests/system/forward/tests.sh
0ba27c
+++ b/bin/tests/system/forward/tests.sh
0ba27c
@@ -253,5 +253,127 @@ grep "status: SERVFAIL" dig.out.$n.f1 > /dev/null || ret=1
0ba27c
 if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
 status=$((status+ret))
0ba27c
 
0ba27c
+#
0ba27c
+# Check various spoofed response scenarios. The same tests will be
0ba27c
+# run twice, with "forward first" and "forward only" configurations.
0ba27c
+#
0ba27c
+run_spooftests () {
0ba27c
+    n=$((n+1))
0ba27c
+    echo_i "checking spoofed response scenario 1 - out of bailiwick NS ($n)"
0ba27c
+    ret=0
0ba27c
+    # prime
0ba27c
+    dig_with_opts @10.53.0.9 attackSecureDomain.net > dig.out.$n.prime || ret=1
0ba27c
+    # check 'net' is not poisoned.
0ba27c
+    dig_with_opts @10.53.0.9 diditwork.net. TXT > dig.out.$n.net || ret=1
0ba27c
+    grep '^diditwork\.net\..*TXT.*"recursed"' dig.out.$n.net > /dev/null || ret=1
0ba27c
+    # check 'sub.local.net' is not poisoned.
0ba27c
+    dig_with_opts @10.53.0.9 sub.local.net TXT > dig.out.$n.sub || ret=1
0ba27c
+    grep '^sub\.local\.net\..*TXT.*"recursed"' dig.out.$n.sub > /dev/null || ret=1
0ba27c
+    if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+    status=$((status+ret))
0ba27c
+
0ba27c
+    n=$((n+1))
0ba27c
+    echo_i "checking spoofed response scenario 2 - inject DNAME/net2. ($n)"
0ba27c
+    ret=0
0ba27c
+    # prime
0ba27c
+    dig_with_opts @10.53.0.9 attackSecureDomain.net2 > dig.out.$n.prime || ret=1
0ba27c
+    # check that net2/DNAME is not cached
0ba27c
+    dig_with_opts @10.53.0.9 net2. DNAME > dig.out.$n.net2 || ret=1
0ba27c
+    grep "ANSWER: 0," dig.out.$n.net2 > /dev/null || ret=1
0ba27c
+    grep "status: NXDOMAIN" dig.out.$n.net2 > /dev/null || ret=1
0ba27c
+    if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+    status=$((status+ret))
0ba27c
+
0ba27c
+    n=$((n+1))
0ba27c
+    echo_i "checking spoofed response scenario 3 - extra answer ($n)"
0ba27c
+    ret=0
0ba27c
+    # prime
0ba27c
+    dig_with_opts @10.53.0.9 attackSecureDomain.net3 > dig.out.$n.prime || ret=1
0ba27c
+    # check extra net3 records are not cached
0ba27c
+    rndccmd 10.53.0.9 dumpdb -cache 2>&1 | sed 's/^/ns9 /' | cat_i
0ba27c
+    for try in 1 2 3 4 5; do
0ba27c
+        lines=$(grep "net3" ns9/named_dump.db | wc -l)
0ba27c
+        if [ ${lines} -eq 0 ]; then
0ba27c
+                sleep 1
0ba27c
+                continue
0ba27c
+        fi
0ba27c
+        [ ${lines} -eq 1 ] || ret=1
0ba27c
+        grep -q '^attackSecureDomain.net3' ns9/named_dump.db || ret=1
0ba27c
+        grep -q '^local.net3' ns9/named_dump.db && ret=1
0ba27c
+    done
0ba27c
+    if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+    status=$((status+ret))
0ba27c
+}
0ba27c
+
0ba27c
+echo_i "checking spoofed response scenarios with forward first zones"
0ba27c
+run_spooftests
0ba27c
+
0ba27c
+copy_setports ns9/named2.conf.in ns9/named.conf
0ba27c
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+sleep 1
0ba27c
+
0ba27c
+echo_i "rechecking spoofed response scenarios with forward only zones"
0ba27c
+run_spooftests
0ba27c
+
0ba27c
+#
0ba27c
+# This scenario expects the spoofed response to succeed. The tests are
0ba27c
+# similar to the ones above, but not identical.
0ba27c
+#
0ba27c
+echo_i "rechecking spoofed response scenarios with 'forward only' set globally"
0ba27c
+copy_setports ns9/named3.conf.in ns9/named.conf
0ba27c
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+sleep 1
0ba27c
+
0ba27c
+n=$((n+1))
0ba27c
+echo_i "checking spoofed response scenario 1 - out of bailiwick NS ($n)"
0ba27c
+ret=0
0ba27c
+# prime
0ba27c
+dig_with_opts @10.53.0.9 attackSecureDomain.net > dig.out.$n.prime || ret=1
0ba27c
+# check 'net' is poisoned.
0ba27c
+dig_with_opts @10.53.0.9 diditwork.net. TXT > dig.out.$n.net || ret=1
0ba27c
+grep '^didItWork\.net\..*TXT.*"if you can see this record the attack worked"' dig.out.$n.net > /dev/null || ret=1
0ba27c
+# check 'sub.local.net' is poisoned.
0ba27c
+dig_with_opts @10.53.0.9 sub.local.net TXT > dig.out.$n.sub || ret=1
0ba27c
+grep '^sub\.local\.net\..*TXT.*"if you see this attacker overrode local delegation"' dig.out.$n.sub > /dev/null || ret=1
0ba27c
+if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+status=$((status+ret))
0ba27c
+
0ba27c
+n=$((n+1))
0ba27c
+echo_i "checking spoofed response scenario 2 - inject DNAME/net2. ($n)"
0ba27c
+ret=0
0ba27c
+# prime
0ba27c
+dig_with_opts @10.53.0.9 attackSecureDomain.net2 > dig.out.$n.prime || ret=1
0ba27c
+# check that net2/DNAME is cached
0ba27c
+dig_with_opts @10.53.0.9 net2. DNAME > dig.out.$n.net2 || ret=1
0ba27c
+grep "ANSWER: 1," dig.out.$n.net2 > /dev/null || ret=1
0ba27c
+grep "net2\..*IN.DNAME.net\.example\.lll\." dig.out.$n.net2 > /dev/null || ret=1
0ba27c
+if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+status=$((status+ret))
0ba27c
+
0ba27c
+#
0ba27c
+# This test doesn't use any forwarder clauses but is here because it
0ba27c
+# is similar to forwarders, as the set of servers that can populate
0ba27c
+# the namespace is defined by the zone content.
0ba27c
+#
0ba27c
+echo_i "rechecking spoofed response scenarios glue below local zone"
0ba27c
+copy_setports ns9/named4.conf.in ns9/named.conf
0ba27c
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
0ba27c
+sleep 1
0ba27c
+
0ba27c
+n=$((n+1))
0ba27c
+echo_i "checking sibling glue below zone ($n)"
0ba27c
+ret=0
0ba27c
+# prime
0ba27c
+dig_with_opts @10.53.0.9 sibling.tld > dig.out.$n.prime || ret=1
0ba27c
+# check for glue A record for sub.local.tld is not used
0ba27c
+dig_with_opts @10.53.0.9 sub.local.tld TXT > dig.out.$n.sub || ret=1
0ba27c
+grep "ANSWER: 1," dig.out.$n.sub > /dev/null || ret=1
0ba27c
+grep 'sub\.local\.tld\..*IN.TXT."good"$' dig.out.$n.sub > /dev/null || ret=1
0ba27c
+if [ $ret != 0 ]; then echo_i "failed"; fi
0ba27c
+status=$((status+ret))
0ba27c
+
0ba27c
 echo_i "exit status: $status"
0ba27c
 [ $status -eq 0 ] || exit 1
0ba27c
diff --git a/bin/tests/system/ifconfig.sh b/bin/tests/system/ifconfig.sh
0ba27c
index e078f3313b..2a4d955caf 100755
0ba27c
--- a/bin/tests/system/ifconfig.sh
0ba27c
+++ b/bin/tests/system/ifconfig.sh
0ba27c
@@ -12,10 +12,10 @@
0ba27c
 #
0ba27c
 # Set up interface aliases for bind9 system tests.
0ba27c
 #
0ba27c
-# IPv4: 10.53.0.{1..10}				RFC 1918
0ba27c
+# IPv4: 10.53.0.{1..11}				RFC 1918
0ba27c
 #       10.53.1.{1..2}
0ba27c
 #       10.53.2.{1..2}
0ba27c
-# IPv6: fd92:7065:b8e:ffff::{1..10}		ULA
0ba27c
+# IPv6: fd92:7065:b8e:ffff::{1..11}		ULA
0ba27c
 #       fd92:7065:b8e:99ff::{1..2}
0ba27c
 #       fd92:7065:b8e:ff::{1..2}
0ba27c
 #
0ba27c
@@ -55,7 +55,7 @@ case "$1" in
0ba27c
 		  2) ipv6="00" ;;
0ba27c
 		  *) ipv6="" ;;
0ba27c
 		esac
0ba27c
-		for ns in 1 2 3 4 5 6 7 8 9 10
0ba27c
+		for ns in 1 2 3 4 5 6 7 8 9 10 11
0ba27c
 		do
0ba27c
 			[ $i -gt 0 -a $ns -gt 2 ] && break
0ba27c
 			int=`expr $i \* 10 + $ns`
0ba27c
@@ -160,7 +160,7 @@ case "$1" in
0ba27c
 		  2) ipv6="00" ;;
0ba27c
 		  *) ipv6="" ;;
0ba27c
 		esac
0ba27c
-		for ns in 10 9 8 7 6 5 4 3 2 1
0ba27c
+		for ns in 11 10 9 8 7 6 5 4 3 2 1
0ba27c
 		do
0ba27c
 			[ $i -gt 0 -a $ns -gt 2 ] && continue
0ba27c
 			int=`expr $i \* 10 + $ns - 1`
0ba27c
-- 
0ba27c
2.34.1
0ba27c