1d9581
From 800ef75553881527e2406f22887e976bb1ba3bfe Mon Sep 17 00:00:00 2001
1d9581
From: Mark Andrews <marka@isc.org>
1d9581
Date: Tue, 18 Jan 2022 00:19:47 +1100
1d9581
Subject: [PATCH] Add tests for forwarder cache poisoning scenarios
1d9581
1d9581
- Check that an NS in an authority section returned from a forwarder
1d9581
  which is above the name in a configured "forward first" or "forward
1d9581
  only" zone (i.e., net/NS in a response from a forwarder configured for
1d9581
  local.net) is not cached.
1d9581
- Test that a DNAME for a parent domain will not be cached when sent
1d9581
  in a response from a forwarder configured to answer for a child.
1d9581
- Check that glue is rejected if its name falls below that of zone
1d9581
  configured locally.
1d9581
- Check that an extra out-of-bailiwick data in the answer section is
1d9581
  not cached (this was already working correctly, but was not explicitly
1d9581
  tested before).
1d9581
1d9581
- v9_11 backport: Revert primary/secondary to master/slave,
1d9581
  backport rndc helper, backport ns8 config.
1d9581
1d9581
(cherry picked from commit bf3fffff67e1de78e9387a93674d471bf4291604)
1d9581
(cherry picked from commit 29f08170f05c2c96fb67f3b561b46aa0bae356f7)
1d9581
---
1d9581
 bin/tests/system/forward/ans11/ans.py         | 136 ++++++++++++++++++
1d9581
 bin/tests/system/forward/clean.sh             |   2 +
1d9581
 bin/tests/system/forward/ns1/diditwork.net.db |  20 +++
1d9581
 bin/tests/system/forward/ns1/named.conf.in    |  20 +++
1d9581
 bin/tests/system/forward/ns1/net.example.lll  |  13 ++
1d9581
 bin/tests/system/forward/ns1/spoofed.net.db   |  20 +++
1d9581
 bin/tests/system/forward/ns1/sub.local.net.db |  20 +++
1d9581
 bin/tests/system/forward/ns10/fakenet.zone    |  15 ++
1d9581
 bin/tests/system/forward/ns10/fakenet2.zone   |  13 ++
1d9581
 .../system/forward/ns10/fakesublocalnet.zone  |  13 ++
1d9581
 .../system/forward/ns10/fakesublocaltld.zone  |  13 ++
1d9581
 bin/tests/system/forward/ns10/named.conf.in   |  51 +++++++
1d9581
 bin/tests/system/forward/ns10/net.example.lll |  13 ++
1d9581
 bin/tests/system/forward/ns10/spoofednet.zone |  14 ++
1d9581
 bin/tests/system/forward/ns4/named.conf.in    |   5 +
1d9581
 bin/tests/system/forward/ns4/sibling.tld.db   |  20 +++
1d9581
 bin/tests/system/forward/ns8/named.conf.in    |  33 +++++
1d9581
 bin/tests/system/forward/ns8/root.db          |  11 ++
1d9581
 bin/tests/system/forward/ns8/sub.local.tld.db |  13 ++
1d9581
 bin/tests/system/forward/ns9/local.net.db     |  14 ++
1d9581
 bin/tests/system/forward/ns9/local.tld.db     |  13 ++
1d9581
 bin/tests/system/forward/ns9/named1.conf.in   |  65 +++++++++
1d9581
 bin/tests/system/forward/ns9/named2.conf.in   |  68 +++++++++
1d9581
 bin/tests/system/forward/ns9/named3.conf.in   |  48 +++++++
1d9581
 bin/tests/system/forward/ns9/named4.conf.in   |  45 ++++++
1d9581
 bin/tests/system/forward/ns9/root.db          |  11 ++
1d9581
 bin/tests/system/forward/prereq.sh            |  14 ++
1d9581
 bin/tests/system/forward/setup.sh             |   3 +
1d9581
 bin/tests/system/forward/tests.sh             | 126 ++++++++++++++++
1d9581
 bin/tests/system/ifconfig.sh                  |   8 +-
1d9581
 30 files changed, 856 insertions(+), 4 deletions(-)
1d9581
 create mode 100644 bin/tests/system/forward/ans11/ans.py
1d9581
 create mode 100644 bin/tests/system/forward/ns1/diditwork.net.db
1d9581
 create mode 100644 bin/tests/system/forward/ns1/net.example.lll
1d9581
 create mode 100644 bin/tests/system/forward/ns1/spoofed.net.db
1d9581
 create mode 100644 bin/tests/system/forward/ns1/sub.local.net.db
1d9581
 create mode 100644 bin/tests/system/forward/ns10/fakenet.zone
1d9581
 create mode 100644 bin/tests/system/forward/ns10/fakenet2.zone
1d9581
 create mode 100644 bin/tests/system/forward/ns10/fakesublocalnet.zone
1d9581
 create mode 100644 bin/tests/system/forward/ns10/fakesublocaltld.zone
1d9581
 create mode 100644 bin/tests/system/forward/ns10/named.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns10/net.example.lll
1d9581
 create mode 100644 bin/tests/system/forward/ns10/spoofednet.zone
1d9581
 create mode 100644 bin/tests/system/forward/ns4/sibling.tld.db
1d9581
 create mode 100644 bin/tests/system/forward/ns8/named.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns8/root.db
1d9581
 create mode 100644 bin/tests/system/forward/ns8/sub.local.tld.db
1d9581
 create mode 100644 bin/tests/system/forward/ns9/local.net.db
1d9581
 create mode 100644 bin/tests/system/forward/ns9/local.tld.db
1d9581
 create mode 100644 bin/tests/system/forward/ns9/named1.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns9/named2.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns9/named3.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns9/named4.conf.in
1d9581
 create mode 100644 bin/tests/system/forward/ns9/root.db
1d9581
1d9581
diff --git a/bin/tests/system/forward/ans11/ans.py b/bin/tests/system/forward/ans11/ans.py
1d9581
new file mode 100644
1d9581
index 0000000000..2956cf6eff
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ans11/ans.py
1d9581
@@ -0,0 +1,136 @@
1d9581
+############################################################################
1d9581
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+#
1d9581
+# This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+# License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+#
1d9581
+# See the COPYRIGHT file distributed with this work for additional
1d9581
+# information regarding copyright ownership.
1d9581
+############################################################################
1d9581
+
1d9581
+from __future__ import print_function
1d9581
+import os
1d9581
+import sys
1d9581
+import signal
1d9581
+import socket
1d9581
+import select
1d9581
+from datetime import datetime, timedelta
1d9581
+import time
1d9581
+import functools
1d9581
+
1d9581
+import dns, dns.message, dns.query, dns.flags
1d9581
+from dns.rdatatype import *
1d9581
+from dns.rdataclass import *
1d9581
+from dns.rcode import *
1d9581
+from dns.name import *
1d9581
+
1d9581
+# Log query to file
1d9581
+def logquery(type, qname):
1d9581
+    with open("qlog", "a") as f:
1d9581
+        f.write("%s %s\n", type, qname)
1d9581
+
1d9581
+############################################################################
1d9581
+# Respond to a DNS query.
1d9581
+############################################################################
1d9581
+def create_response(msg):
1d9581
+    m = dns.message.from_wire(msg)
1d9581
+    qname = m.question[0].name.to_text()
1d9581
+    rrtype = m.question[0].rdtype
1d9581
+    typename = dns.rdatatype.to_text(rrtype)
1d9581
+
1d9581
+    with open("query.log", "a") as f:
1d9581
+        f.write("%s %s\n" % (typename, qname))
1d9581
+        print("%s %s" % (typename, qname), end=" ")
1d9581
+
1d9581
+    r = dns.message.make_response(m)
1d9581
+    r.set_rcode(NOERROR)
1d9581
+    if rrtype == A:
1d9581
+        tld=qname.split('.')[-2] + '.'
1d9581
+        ns="local." + tld
1d9581
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, A, "10.53.0.11"))
1d9581
+        r.answer.append(dns.rrset.from_text(tld, 300, IN, NS, "local." + tld))
1d9581
+        r.additional.append(dns.rrset.from_text(ns, 300, IN, A, "10.53.0.11"))
1d9581
+    elif rrtype == NS:
1d9581
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, NS, "."))
1d9581
+    elif rrtype == SOA:
1d9581
+        r.answer.append(dns.rrset.from_text(qname, 300, IN, SOA, ". . 0 0 0 0 0"))
1d9581
+    else:
1d9581
+        r.authority.append(dns.rrset.from_text(qname, 300, IN, SOA, ". . 0 0 0 0 0"))
1d9581
+    r.flags |= dns.flags.AA
1d9581
+    return r
1d9581
+
1d9581
+def sigterm(signum, frame):
1d9581
+    print ("Shutting down now...")
1d9581
+    os.remove('ans.pid')
1d9581
+    running = False
1d9581
+    sys.exit(0)
1d9581
+
1d9581
+############################################################################
1d9581
+# Main
1d9581
+#
1d9581
+# Set up responder and control channel, open the pid file, and start
1d9581
+# the main loop, listening for queries on the query channel or commands
1d9581
+# on the control channel and acting on them.
1d9581
+############################################################################
1d9581
+ip4 = "10.53.0.11"
1d9581
+ip6 = "fd92:7065:b8e:ffff::11"
1d9581
+
1d9581
+try: port=int(os.environ['PORT'])
1d9581
+except: port=5300
1d9581
+
1d9581
+query4_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1d9581
+query4_socket.bind((ip4, port))
1d9581
+havev6 = True
1d9581
+try:
1d9581
+    query6_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
1d9581
+    try:
1d9581
+        query6_socket.bind((ip6, port))
1d9581
+    except:
1d9581
+        query6_socket.close()
1d9581
+        havev6 = False
1d9581
+except:
1d9581
+    havev6 = False
1d9581
+signal.signal(signal.SIGTERM, sigterm)
1d9581
+
1d9581
+f = open('ans.pid', 'w')
1d9581
+pid = os.getpid()
1d9581
+print (pid, file=f)
1d9581
+f.close()
1d9581
+
1d9581
+running = True
1d9581
+
1d9581
+print ("Listening on %s port %d" % (ip4, port))
1d9581
+if havev6:
1d9581
+    print ("Listening on %s port %d" % (ip6, port))
1d9581
+print ("Ctrl-c to quit")
1d9581
+
1d9581
+if havev6:
1d9581
+    input = [query4_socket, query6_socket]
1d9581
+else:
1d9581
+    input = [query4_socket]
1d9581
+
1d9581
+while running:
1d9581
+    try:
1d9581
+        inputready, outputready, exceptready = select.select(input, [], [])
1d9581
+    except select.error as e:
1d9581
+        break
1d9581
+    except socket.error as e:
1d9581
+        break
1d9581
+    except KeyboardInterrupt:
1d9581
+        break
1d9581
+
1d9581
+    for s in inputready:
1d9581
+        if s == query4_socket or s == query6_socket:
1d9581
+            print ("Query received on %s" %
1d9581
+                    (ip4 if s == query4_socket else ip6), end=" ")
1d9581
+            # Handle incoming queries
1d9581
+            msg = s.recvfrom(65535)
1d9581
+            rsp = create_response(msg[0])
1d9581
+            if rsp:
1d9581
+                print(dns.rcode.to_text(rsp.rcode()))
1d9581
+                s.sendto(rsp.to_wire(), msg[1])
1d9581
+            else:
1d9581
+                print("NO RESPONSE")
1d9581
+    if not running:
1d9581
+        break
1d9581
diff --git a/bin/tests/system/forward/clean.sh b/bin/tests/system/forward/clean.sh
1d9581
index 26e4e76db6..26a550db49 100644
1d9581
--- a/bin/tests/system/forward/clean.sh
1d9581
+++ b/bin/tests/system/forward/clean.sh
1d9581
@@ -10,8 +10,10 @@
1d9581
 #
1d9581
 # Clean up after forward tests.
1d9581
 #
1d9581
+rm -f ./ans11/query.log
1d9581
 rm -f ./dig.out.*
1d9581
 rm -f ./*/named.conf
1d9581
 rm -f ./*/named.memstats
1d9581
 rm -f ./*/named.run ./*/named.run.prev
1d9581
+rm -f ./*/named_dump.db
1d9581
 rm -f ./ns*/named.lock
1d9581
diff --git a/bin/tests/system/forward/ns1/diditwork.net.db b/bin/tests/system/forward/ns1/diditwork.net.db
1d9581
new file mode 100644
1d9581
index 0000000000..be9a7f72bc
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns1/diditwork.net.db
1d9581
@@ -0,0 +1,20 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 300	; 5 minutes
1d9581
+@			IN SOA	ns root (
1d9581
+				2000082401 ; serial
1d9581
+				1800       ; refresh (30 minutes)
1d9581
+				1800       ; retry (30 minutes)
1d9581
+				1814400    ; expire (3 weeks)
1d9581
+				3600       ; minimum (1 hour)
1d9581
+				)
1d9581
+			NS	ns
1d9581
+			TXT	"recursed"
1d9581
+ns			A	10.53.0.1
1d9581
diff --git a/bin/tests/system/forward/ns1/named.conf.in b/bin/tests/system/forward/ns1/named.conf.in
1d9581
index 9904f37ef5..1c31d84608 100644
1d9581
--- a/bin/tests/system/forward/ns1/named.conf.in
1d9581
+++ b/bin/tests/system/forward/ns1/named.conf.in
1d9581
@@ -54,3 +54,23 @@ zone "example5." {
1d9581
 zone "example6" {
1d9581
 	type forward;
1d9581
 };
1d9581
+
1d9581
+zone "diditwork.net" {
1d9581
+	type master;
1d9581
+	file "diditwork.net.db";
1d9581
+};
1d9581
+
1d9581
+zone "spoofed.net" {
1d9581
+	type master;
1d9581
+	file "spoofed.net.db";
1d9581
+};
1d9581
+
1d9581
+zone "sub.local.net" {
1d9581
+	type master;
1d9581
+	file "sub.local.net.db";
1d9581
+};
1d9581
+
1d9581
+zone "net.example.lll" {
1d9581
+	type master;
1d9581
+	file "net.example.lll";
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns1/net.example.lll b/bin/tests/system/forward/ns1/net.example.lll
1d9581
new file mode 100644
1d9581
index 0000000000..d179853fa5
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns1/net.example.lll
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+net.example.lll.		SOA	. . 0 0 0 0 0
1d9581
+net.example.lll.		NS	attackSecureDomain.net.
1d9581
+didItWork.net.example.lll.	TXT	"if you can see this record the attack worked"
1d9581
diff --git a/bin/tests/system/forward/ns1/spoofed.net.db b/bin/tests/system/forward/ns1/spoofed.net.db
1d9581
new file mode 100644
1d9581
index 0000000000..d498d5fa0d
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns1/spoofed.net.db
1d9581
@@ -0,0 +1,20 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 300	; 5 minutes
1d9581
+@			IN SOA	ns root (
1d9581
+				2000082401 ; serial
1d9581
+				1800       ; refresh (30 minutes)
1d9581
+				1800       ; retry (30 minutes)
1d9581
+				1814400    ; expire (3 weeks)
1d9581
+				3600       ; minimum (1 hour)
1d9581
+				)
1d9581
+			NS	ns
1d9581
+ns			A	10.53.0.1
1d9581
+sub			TXT	"recursed"
1d9581
diff --git a/bin/tests/system/forward/ns1/sub.local.net.db b/bin/tests/system/forward/ns1/sub.local.net.db
1d9581
new file mode 100644
1d9581
index 0000000000..be9a7f72bc
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns1/sub.local.net.db
1d9581
@@ -0,0 +1,20 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 300	; 5 minutes
1d9581
+@			IN SOA	ns root (
1d9581
+				2000082401 ; serial
1d9581
+				1800       ; refresh (30 minutes)
1d9581
+				1800       ; retry (30 minutes)
1d9581
+				1814400    ; expire (3 weeks)
1d9581
+				3600       ; minimum (1 hour)
1d9581
+				)
1d9581
+			NS	ns
1d9581
+			TXT	"recursed"
1d9581
+ns			A	10.53.0.1
1d9581
diff --git a/bin/tests/system/forward/ns10/fakenet.zone b/bin/tests/system/forward/ns10/fakenet.zone
1d9581
new file mode 100644
1d9581
index 0000000000..14e5c777cb
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/fakenet.zone
1d9581
@@ -0,0 +1,15 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+net.			SOA	. . 0 0 0 0 0
1d9581
+net.			NS	attackSecureDomain.net.
1d9581
+attackSecureDomain.net.	A	10.53.0.10
1d9581
+didItWork.net.		TXT	"if you can see this record the attack worked"
1d9581
+ns.spoofed.net.		A	10.53.0.10
1d9581
diff --git a/bin/tests/system/forward/ns10/fakenet2.zone b/bin/tests/system/forward/ns10/fakenet2.zone
1d9581
new file mode 100644
1d9581
index 0000000000..7ca28a934e
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/fakenet2.zone
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+net2.			SOA	. . 0 0 0 0 0
1d9581
+net2.			NS	attackSecureDomain.net.
1d9581
+net2.			DNAME	net.example.lll.
1d9581
diff --git a/bin/tests/system/forward/ns10/fakesublocalnet.zone b/bin/tests/system/forward/ns10/fakesublocalnet.zone
1d9581
new file mode 100644
1d9581
index 0000000000..6caa071891
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/fakesublocalnet.zone
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+sub.local.net.		SOA	. . 0 0 0 0 0
1d9581
+sub.local.net.		NS	ns.spoofed.net.
1d9581
+sub.local.net.		TXT	"if you see this attacker overrode local delegation"
1d9581
diff --git a/bin/tests/system/forward/ns10/fakesublocaltld.zone b/bin/tests/system/forward/ns10/fakesublocaltld.zone
1d9581
new file mode 100644
1d9581
index 0000000000..6a431de47f
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/fakesublocaltld.zone
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+sub.local.tld.		3600	IN	SOA	. . 0 0 0 0 0
1d9581
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
1d9581
+sub.local.tld.		3600	IN	TXT	bad
1d9581
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
1d9581
diff --git a/bin/tests/system/forward/ns10/named.conf.in b/bin/tests/system/forward/ns10/named.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..025c108418
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/named.conf.in
1d9581
@@ -0,0 +1,51 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.10;
1d9581
+	notify-source 10.53.0.10;
1d9581
+	transfer-source 10.53.0.10;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.10; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	minimal-responses no;
1d9581
+};
1d9581
+
1d9581
+zone "net." {
1d9581
+	type master;
1d9581
+	file "fakenet.zone";
1d9581
+};
1d9581
+
1d9581
+zone "spoofed.net." {
1d9581
+	type master;
1d9581
+	file "spoofednet.zone";
1d9581
+};
1d9581
+
1d9581
+zone "sub.local.net." {
1d9581
+	type master;
1d9581
+	file "fakesublocalnet.zone";
1d9581
+};
1d9581
+
1d9581
+zone "net2" {
1d9581
+	type master;
1d9581
+	file "fakenet2.zone";
1d9581
+};
1d9581
+
1d9581
+zone "net.example.lll" {
1d9581
+	type master;
1d9581
+	file "net.example.lll";
1d9581
+};
1d9581
+
1d9581
+zone "sub.local.tld." {
1d9581
+	type master;
1d9581
+	file "fakesublocaltld.zone";
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns10/net.example.lll b/bin/tests/system/forward/ns10/net.example.lll
1d9581
new file mode 100644
1d9581
index 0000000000..d179853fa5
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/net.example.lll
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+net.example.lll.		SOA	. . 0 0 0 0 0
1d9581
+net.example.lll.		NS	attackSecureDomain.net.
1d9581
+didItWork.net.example.lll.	TXT	"if you can see this record the attack worked"
1d9581
diff --git a/bin/tests/system/forward/ns10/spoofednet.zone b/bin/tests/system/forward/ns10/spoofednet.zone
1d9581
new file mode 100644
1d9581
index 0000000000..13921a08cd
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns10/spoofednet.zone
1d9581
@@ -0,0 +1,14 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL 86400
1d9581
+spoofed.net.		SOA	. . 0 0 0 0 0
1d9581
+spoofed.net.		NS	ns.spoofed.net.
1d9581
+ns.spoofed.net.		A	10.53.0.10
1d9581
+spoofed.net.		TXT	"this record is clearly spoofed"
1d9581
diff --git a/bin/tests/system/forward/ns4/named.conf.in b/bin/tests/system/forward/ns4/named.conf.in
1d9581
index d42a9eb797..6db65e71bc 100644
1d9581
--- a/bin/tests/system/forward/ns4/named.conf.in
1d9581
+++ b/bin/tests/system/forward/ns4/named.conf.in
1d9581
@@ -60,3 +60,8 @@ zone "malicious." {
1d9581
 	type master;
1d9581
 	file "malicious.db";
1d9581
 };
1d9581
+
1d9581
+zone "sibling.tld" {
1d9581
+	type master;
1d9581
+	file "sibling.tld.db";
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns4/sibling.tld.db b/bin/tests/system/forward/ns4/sibling.tld.db
1d9581
new file mode 100644
1d9581
index 0000000000..58037d093b
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns4/sibling.tld.db
1d9581
@@ -0,0 +1,20 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+$TTL    86400
1d9581
+@       IN      SOA     malicious. admin.malicious. (
1d9581
+                              1         ; Serial
1d9581
+                         604800         ; Refresh
1d9581
+                          86400         ; Retry
1d9581
+                        2419200         ; Expire
1d9581
+                          86400 )       ; Negative Cache TTL
1d9581
+
1d9581
+@           IN    NS      ns
1d9581
+
1d9581
+ns          IN    A       10.53.0.4
1d9581
diff --git a/bin/tests/system/forward/ns8/named.conf.in b/bin/tests/system/forward/ns8/named.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..9260f69ded
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns8/named.conf.in
1d9581
@@ -0,0 +1,33 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.8;
1d9581
+	notify-source 10.53.0.8;
1d9581
+	transfer-source 10.53.0.8;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.8; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	forwarders { 10.53.0.2; };	// returns referrals
1d9581
+	forward first;
1d9581
+	dnssec-validation yes;
1d9581
+};
1d9581
+
1d9581
+zone "." {
1d9581
+	type hint;
1d9581
+	file "root.db";
1d9581
+};
1d9581
+
1d9581
+zone "sub.local.tld" {
1d9581
+	type master;
1d9581
+	file "sub.local.tld.db";
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns8/root.db b/bin/tests/system/forward/ns8/root.db
1d9581
new file mode 100644
1d9581
index 0000000000..4f30322270
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns8/root.db
1d9581
@@ -0,0 +1,11 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+.			NS	a.root-servers.nil.
1d9581
+a.root-servers.nil.	A	10.53.0.1
1d9581
diff --git a/bin/tests/system/forward/ns8/sub.local.tld.db b/bin/tests/system/forward/ns8/sub.local.tld.db
1d9581
new file mode 100644
1d9581
index 0000000000..eb20683ae9
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns8/sub.local.tld.db
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+sub.local.tld.		3600	IN	SOA	. . 0 0 0 0 0
1d9581
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
1d9581
+sub.local.tld.		3600	IN	TXT	good
1d9581
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
1d9581
diff --git a/bin/tests/system/forward/ns9/local.net.db b/bin/tests/system/forward/ns9/local.net.db
1d9581
new file mode 100644
1d9581
index 0000000000..2c971e1e93
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/local.net.db
1d9581
@@ -0,0 +1,14 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+local.net.		3600	IN	SOA	. . 0 0 0 0 0
1d9581
+local.net.		3600	IN	NS	localhost.
1d9581
+ns.local.net.		3600	IN	A	10.53.0.9
1d9581
+txt.local.net.		3600	IN	TXT	"something in the local auth zone"
1d9581
+sub.local.net.		3600	IN	NS	ns.spoofed.net.  ; attacker will try to override this
1d9581
diff --git a/bin/tests/system/forward/ns9/local.tld.db b/bin/tests/system/forward/ns9/local.tld.db
1d9581
new file mode 100644
1d9581
index 0000000000..59403915fb
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/local.tld.db
1d9581
@@ -0,0 +1,13 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+local.tld.		3600	IN	SOA	. . 0 0 0 0 0
1d9581
+local.tld.		3600	IN	NS	localhost.
1d9581
+sub.local.tld.		3600	IN	NS	ns.sub.local.tld.
1d9581
+ns.sub.local.tld.	3600	IN	A	10.53.0.8
1d9581
diff --git a/bin/tests/system/forward/ns9/named1.conf.in b/bin/tests/system/forward/ns9/named1.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..943e037d09
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/named1.conf.in
1d9581
@@ -0,0 +1,65 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.9;
1d9581
+	notify-source 10.53.0.9;
1d9581
+	transfer-source 10.53.0.9;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.9; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	dnssec-validation no;
1d9581
+	edns-udp-size 1232;
1d9581
+};
1d9581
+
1d9581
+key rndc_key {
1d9581
+	secret "1234abcd8765";
1d9581
+	algorithm hmac-sha256;
1d9581
+};
1d9581
+
1d9581
+controls {
1d9581
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.10 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.11 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+zone "." {
1d9581
+	type hint;
1d9581
+	file "root.db";
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net." {
1d9581
+	type forward;
1d9581
+	forwarders { 10.53.0.10; };
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net2." {
1d9581
+	type forward;
1d9581
+	forwarders { 10.53.0.10; };
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net3." {
1d9581
+	type forward;
1d9581
+	forwarders { 10.53.0.11; };
1d9581
+};
1d9581
+
1d9581
+zone "local.net." {
1d9581
+	type master;
1d9581
+	file "local.net.db";
1d9581
+	forwarders {};
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns9/named2.conf.in b/bin/tests/system/forward/ns9/named2.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..5a17d1998a
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/named2.conf.in
1d9581
@@ -0,0 +1,68 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.9;
1d9581
+	notify-source 10.53.0.9;
1d9581
+	transfer-source 10.53.0.9;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.9; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	dnssec-validation no;
1d9581
+	edns-udp-size 1232;
1d9581
+};
1d9581
+
1d9581
+key rndc_key {
1d9581
+	secret "1234abcd8765";
1d9581
+	algorithm hmac-sha256;
1d9581
+};
1d9581
+
1d9581
+controls {
1d9581
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.10 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.11 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+zone "." {
1d9581
+	type hint;
1d9581
+	file "root.db";
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net." {
1d9581
+	type forward;
1d9581
+	forward only;
1d9581
+	forwarders { 10.53.0.10; };
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net2." {
1d9581
+	type forward;
1d9581
+	forward only;
1d9581
+	forwarders { 10.53.0.10; };
1d9581
+};
1d9581
+
1d9581
+zone "attacksecuredomain.net3." {
1d9581
+	type forward;
1d9581
+	forward only;
1d9581
+	forwarders { 10.53.0.11; };
1d9581
+};
1d9581
+
1d9581
+zone "local.net." {
1d9581
+	type master;
1d9581
+	file "local.net.db";
1d9581
+	forwarders {};
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns9/named3.conf.in b/bin/tests/system/forward/ns9/named3.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..1e70d1ae51
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/named3.conf.in
1d9581
@@ -0,0 +1,48 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.9;
1d9581
+	notify-source 10.53.0.9;
1d9581
+	transfer-source 10.53.0.9;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.9; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	dnssec-validation no;
1d9581
+	edns-udp-size 1232;
1d9581
+	forward only;
1d9581
+	forwarders { 10.53.0.10; };
1d9581
+};
1d9581
+
1d9581
+key rndc_key {
1d9581
+	secret "1234abcd8765";
1d9581
+	algorithm hmac-sha256;
1d9581
+};
1d9581
+
1d9581
+controls {
1d9581
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.10 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+zone "." {
1d9581
+	type hint;
1d9581
+	file "root.db";
1d9581
+};
1d9581
+
1d9581
+zone "local.net." {
1d9581
+	type master;
1d9581
+	file "local.net.db";
1d9581
+	forwarders {};
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns9/named4.conf.in b/bin/tests/system/forward/ns9/named4.conf.in
1d9581
new file mode 100644
1d9581
index 0000000000..6f7b1075b5
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/named4.conf.in
1d9581
@@ -0,0 +1,45 @@
1d9581
+/*
1d9581
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+ *
1d9581
+ * This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+ *
1d9581
+ * See the COPYRIGHT file distributed with this work for additional
1d9581
+ * information regarding copyright ownership.
1d9581
+ */
1d9581
+
1d9581
+options {
1d9581
+	query-source address 10.53.0.9;
1d9581
+	notify-source 10.53.0.9;
1d9581
+	transfer-source 10.53.0.9;
1d9581
+	port @PORT@;
1d9581
+	pid-file "named.pid";
1d9581
+	listen-on { 10.53.0.9; };
1d9581
+	listen-on-v6 { none; };
1d9581
+	dnssec-validation no;
1d9581
+	edns-udp-size 1232;
1d9581
+};
1d9581
+
1d9581
+key rndc_key {
1d9581
+	secret "1234abcd8765";
1d9581
+	algorithm hmac-sha256;
1d9581
+};
1d9581
+
1d9581
+controls {
1d9581
+	inet 10.53.0.9 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
1d9581
+};
1d9581
+
1d9581
+server 10.53.0.10 {
1d9581
+	edns no;
1d9581
+};
1d9581
+
1d9581
+zone "." {
1d9581
+	type hint;
1d9581
+	file "root.db";
1d9581
+};
1d9581
+
1d9581
+zone "local.tld." {
1d9581
+	type master;
1d9581
+	file "local.tld.db";
1d9581
+};
1d9581
diff --git a/bin/tests/system/forward/ns9/root.db b/bin/tests/system/forward/ns9/root.db
1d9581
new file mode 100644
1d9581
index 0000000000..4f30322270
1d9581
--- /dev/null
1d9581
+++ b/bin/tests/system/forward/ns9/root.db
1d9581
@@ -0,0 +1,11 @@
1d9581
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1d9581
+;
1d9581
+; This Source Code Form is subject to the terms of the Mozilla Public
1d9581
+; License, v. 2.0. If a copy of the MPL was not distributed with this
1d9581
+; file, you can obtain one at https://mozilla.org/MPL/2.0/.
1d9581
+;
1d9581
+; See the COPYRIGHT file distributed with this work for additional
1d9581
+; information regarding copyright ownership.
1d9581
+
1d9581
+.			NS	a.root-servers.nil.
1d9581
+a.root-servers.nil.	A	10.53.0.1
1d9581
diff --git a/bin/tests/system/forward/prereq.sh b/bin/tests/system/forward/prereq.sh
1d9581
index d2ca8fc2bf..53fb5817df 100644
1d9581
--- a/bin/tests/system/forward/prereq.sh
1d9581
+++ b/bin/tests/system/forward/prereq.sh
1d9581
@@ -12,6 +12,20 @@
1d9581
 SYSTEMTESTTOP=..
1d9581
 . $SYSTEMTESTTOP/conf.sh
1d9581
 
1d9581
+if test -n "$PYTHON"
1d9581
+then
1d9581
+    if $PYTHON -c "import dns" 2> /dev/null
1d9581
+    then
1d9581
+        :
1d9581
+    else
1d9581
+        echo_i "This test requires the dnspython module." >&2
1d9581
+        exit 1
1d9581
+    fi
1d9581
+else
1d9581
+    echo_i "This test requires Python and the dnspython module." >&2
1d9581
+    exit 1
1d9581
+fi
1d9581
+
1d9581
 if $PERL -e 'use Net::DNS;' 2>/dev/null
1d9581
 then
1d9581
     :
1d9581
diff --git a/bin/tests/system/forward/setup.sh b/bin/tests/system/forward/setup.sh
1d9581
index 87452b9a88..18e81d277d 100644
1d9581
--- a/bin/tests/system/forward/setup.sh
1d9581
+++ b/bin/tests/system/forward/setup.sh
1d9581
@@ -18,3 +18,6 @@ copy_setports ns3/named.conf.in ns3/named.conf
1d9581
 copy_setports ns4/named.conf.in ns4/named.conf
1d9581
 copy_setports ns5/named.conf.in ns5/named.conf
1d9581
 copy_setports ns7/named.conf.in ns7/named.conf
1d9581
+copy_setports ns8/named.conf.in ns8/named.conf
1d9581
+copy_setports ns9/named1.conf.in ns9/named.conf
1d9581
+copy_setports ns10/named.conf.in ns10/named.conf
1d9581
diff --git a/bin/tests/system/forward/tests.sh b/bin/tests/system/forward/tests.sh
1d9581
index e3549c5bc7..ce9b309a27 100644
1d9581
--- a/bin/tests/system/forward/tests.sh
1d9581
+++ b/bin/tests/system/forward/tests.sh
1d9581
@@ -19,6 +19,10 @@ sendcmd() (
1d9581
 	"$PERL" ../send.pl 10.53.0.6 "$EXTRAPORT1"
1d9581
 )
1d9581
 
1d9581
+rndccmd() {
1d9581
+    "$RNDC" -c ../common/rndc.conf -p "$CONTROLPORT" -s "$@"
1d9581
+}
1d9581
+
1d9581
 root=10.53.0.1
1d9581
 hidden=10.53.0.2
1d9581
 f1=10.53.0.3
1d9581
@@ -223,5 +227,127 @@ if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
 status=$((status+ret))
1d9581
 
1d9581
 
1d9581
+#
1d9581
+# Check various spoofed response scenarios. The same tests will be
1d9581
+# run twice, with "forward first" and "forward only" configurations.
1d9581
+#
1d9581
+run_spooftests () {
1d9581
+    n=$((n+1))
1d9581
+    echo_i "checking spoofed response scenario 1 - out of bailiwick NS ($n)"
1d9581
+    ret=0
1d9581
+    # prime
1d9581
+    dig_with_opts @10.53.0.9 attackSecureDomain.net > dig.out.$n.prime || ret=1
1d9581
+    # check 'net' is not poisoned.
1d9581
+    dig_with_opts @10.53.0.9 diditwork.net. TXT > dig.out.$n.net || ret=1
1d9581
+    grep '^diditwork\.net\..*TXT.*"recursed"' dig.out.$n.net > /dev/null || ret=1
1d9581
+    # check 'sub.local.net' is not poisoned.
1d9581
+    dig_with_opts @10.53.0.9 sub.local.net TXT > dig.out.$n.sub || ret=1
1d9581
+    grep '^sub\.local\.net\..*TXT.*"recursed"' dig.out.$n.sub > /dev/null || ret=1
1d9581
+    if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+    status=$((status+ret))
1d9581
+
1d9581
+    n=$((n+1))
1d9581
+    echo_i "checking spoofed response scenario 2 - inject DNAME/net2. ($n)"
1d9581
+    ret=0
1d9581
+    # prime
1d9581
+    dig_with_opts @10.53.0.9 attackSecureDomain.net2 > dig.out.$n.prime || ret=1
1d9581
+    # check that net2/DNAME is not cached
1d9581
+    dig_with_opts @10.53.0.9 net2. DNAME > dig.out.$n.net2 || ret=1
1d9581
+    grep "ANSWER: 0," dig.out.$n.net2 > /dev/null || ret=1
1d9581
+    grep "status: NXDOMAIN" dig.out.$n.net2 > /dev/null || ret=1
1d9581
+    if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+    status=$((status+ret))
1d9581
+
1d9581
+    n=$((n+1))
1d9581
+    echo_i "checking spoofed response scenario 3 - extra answer ($n)"
1d9581
+    ret=0
1d9581
+    # prime
1d9581
+    dig_with_opts @10.53.0.9 attackSecureDomain.net3 > dig.out.$n.prime || ret=1
1d9581
+    # check extra net3 records are not cached
1d9581
+    rndccmd 10.53.0.9 dumpdb -cache 2>&1 | sed 's/^/ns9 /' | cat_i
1d9581
+    for try in 1 2 3 4 5; do
1d9581
+        lines=$(grep "net3" ns9/named_dump.db | wc -l)
1d9581
+        if [ ${lines} -eq 0 ]; then
1d9581
+                sleep 1
1d9581
+                continue
1d9581
+        fi
1d9581
+        [ ${lines} -eq 1 ] || ret=1
1d9581
+        grep -q '^attackSecureDomain.net3' ns9/named_dump.db || ret=1
1d9581
+        grep -q '^local.net3' ns9/named_dump.db && ret=1
1d9581
+    done
1d9581
+    if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+    status=$((status+ret))
1d9581
+}
1d9581
+
1d9581
+echo_i "checking spoofed response scenarios with forward first zones"
1d9581
+run_spooftests
1d9581
+
1d9581
+copy_setports ns9/named2.conf.in ns9/named.conf
1d9581
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+sleep 1
1d9581
+
1d9581
+echo_i "rechecking spoofed response scenarios with forward only zones"
1d9581
+run_spooftests
1d9581
+
1d9581
+#
1d9581
+# This scenario expects the spoofed response to succeed. The tests are
1d9581
+# similar to the ones above, but not identical.
1d9581
+#
1d9581
+echo_i "rechecking spoofed response scenarios with 'forward only' set globally"
1d9581
+copy_setports ns9/named3.conf.in ns9/named.conf
1d9581
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+sleep 1
1d9581
+
1d9581
+n=$((n+1))
1d9581
+echo_i "checking spoofed response scenario 1 - out of bailiwick NS ($n)"
1d9581
+ret=0
1d9581
+# prime
1d9581
+dig_with_opts @10.53.0.9 attackSecureDomain.net > dig.out.$n.prime || ret=1
1d9581
+# check 'net' is poisoned.
1d9581
+dig_with_opts @10.53.0.9 diditwork.net. TXT > dig.out.$n.net || ret=1
1d9581
+grep '^didItWork\.net\..*TXT.*"if you can see this record the attack worked"' dig.out.$n.net > /dev/null || ret=1
1d9581
+# check 'sub.local.net' is poisoned.
1d9581
+dig_with_opts @10.53.0.9 sub.local.net TXT > dig.out.$n.sub || ret=1
1d9581
+grep '^sub\.local\.net\..*TXT.*"if you see this attacker overrode local delegation"' dig.out.$n.sub > /dev/null || ret=1
1d9581
+if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+status=$((status+ret))
1d9581
+
1d9581
+n=$((n+1))
1d9581
+echo_i "checking spoofed response scenario 2 - inject DNAME/net2. ($n)"
1d9581
+ret=0
1d9581
+# prime
1d9581
+dig_with_opts @10.53.0.9 attackSecureDomain.net2 > dig.out.$n.prime || ret=1
1d9581
+# check that net2/DNAME is cached
1d9581
+dig_with_opts @10.53.0.9 net2. DNAME > dig.out.$n.net2 || ret=1
1d9581
+grep "ANSWER: 1," dig.out.$n.net2 > /dev/null || ret=1
1d9581
+grep "net2\..*IN.DNAME.net\.example\.lll\." dig.out.$n.net2 > /dev/null || ret=1
1d9581
+if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+status=$((status+ret))
1d9581
+
1d9581
+#
1d9581
+# This test doesn't use any forwarder clauses but is here because it
1d9581
+# is similar to forwarders, as the set of servers that can populate
1d9581
+# the namespace is defined by the zone content.
1d9581
+#
1d9581
+echo_i "rechecking spoofed response scenarios glue below local zone"
1d9581
+copy_setports ns9/named4.conf.in ns9/named.conf
1d9581
+rndccmd 10.53.0.9 reconfig 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+rndccmd 10.53.0.9 flush 2>&1 | sed 's/^/ns3 /' | cat_i
1d9581
+sleep 1
1d9581
+
1d9581
+n=$((n+1))
1d9581
+echo_i "checking sibling glue below zone ($n)"
1d9581
+ret=0
1d9581
+# prime
1d9581
+dig_with_opts @10.53.0.9 sibling.tld > dig.out.$n.prime || ret=1
1d9581
+# check for glue A record for sub.local.tld is not used
1d9581
+dig_with_opts @10.53.0.9 sub.local.tld TXT > dig.out.$n.sub || ret=1
1d9581
+grep "ANSWER: 1," dig.out.$n.sub > /dev/null || ret=1
1d9581
+grep 'sub\.local\.tld\..*IN.TXT."good"$' dig.out.$n.sub > /dev/null || ret=1
1d9581
+if [ $ret != 0 ]; then echo_i "failed"; fi
1d9581
+status=$((status+ret))
1d9581
+
1d9581
 echo_i "exit status: $status"
1d9581
 [ $status -eq 0 ] || exit 1
1d9581
diff --git a/bin/tests/system/ifconfig.sh b/bin/tests/system/ifconfig.sh
1d9581
index d0eb9fa61d..8b9212c3e0 100755
1d9581
--- a/bin/tests/system/ifconfig.sh
1d9581
+++ b/bin/tests/system/ifconfig.sh
1d9581
@@ -12,10 +12,10 @@
1d9581
 #
1d9581
 # Set up interface aliases for bind9 system tests.
1d9581
 #
1d9581
-# IPv4: 10.53.0.{1..10}				RFC 1918
1d9581
+# IPv4: 10.53.0.{1..11}				RFC 1918
1d9581
 #       10.53.1.{1..2}
1d9581
 #       10.53.2.{1..2}
1d9581
-# IPv6: fd92:7065:b8e:ffff::{1..10}		ULA
1d9581
+# IPv6: fd92:7065:b8e:ffff::{1..11}		ULA
1d9581
 #       fd92:7065:b8e:99ff::{1..2}
1d9581
 #       fd92:7065:b8e:ff::{1..2}
1d9581
 #
1d9581
@@ -65,7 +65,7 @@ case "$1" in
1d9581
 		  2) ipv6="00" ;;
1d9581
 		  *) ipv6="" ;;
1d9581
 		esac
1d9581
-		for ns in 1 2 3 4 5 6 7 8 9 10
1d9581
+		for ns in 1 2 3 4 5 6 7 8 9 10 11
1d9581
 		do
1d9581
 			[ $i -gt 0 -a $ns -gt 2 ] && break
1d9581
 			int=`expr $i \* 10 + $ns`
1d9581
@@ -165,7 +165,7 @@ case "$1" in
1d9581
 		  2) ipv6="00" ;;
1d9581
 		  *) ipv6="" ;;
1d9581
 		esac
1d9581
-		for ns in 10 9 8 7 6 5 4 3 2 1
1d9581
+		for ns in 11 10 9 8 7 6 5 4 3 2 1
1d9581
 		do
1d9581
 			[ $i -gt 0 -a $ns -gt 2 ] && continue
1d9581
 			int=`expr $i \* 10 + $ns - 1`
1d9581
-- 
1d9581
2.34.1
1d9581