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