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