Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSUBNET address logging #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add --csubnet param
J-Run authored Jun 28, 2022

Verified

This commit was signed with the committer’s verified signature.
edalzell Erin Dalzell
commit fd5adba443c77b1f87cce2ab99b11e03b181160c
39 changes: 19 additions & 20 deletions dnschef.py
Original file line number Diff line number Diff line change
@@ -123,28 +123,26 @@ def parse(self, data):

# Create a custom response to the query
response = DNSRecord(DNSHeader(id=d.header.id, bitmap=d.header.bitmap, qr=1, aa=1, ra=1), q=d.q)
#==============================================
for rdata in d.ar[0].rdata:
if rdata.code == 8:
# for m in rdata.data:
# print(m)
# print("========")

netmask = rdata.data[2]
# print(netmask)
client_subnet = ""
for i in range(4, len(rdata.data)):
client_subnet += str(rdata.data[i])
if i < len(rdata.data) - 1:
client_subnet += "."

# print(client_subnet)
log.info(f"{self.client_address[0]} [{client_subnet}/{netmask}]: cooking the response of type '{qtype}' for {qname} to {fake_record}")
# log.info(f"{rdata.data}")

#=================================================

if options.csubnet:
if len(d.ar):
for rdata in d.ar[0].rdata:
if rdata.code == 8:
netmask = rdata.data[2]
client_subnet = ""
for i in range(4, len(rdata.data)):
client_subnet += str(rdata.data[i])
if i < len(rdata.data) - 1:
client_subnet += "."
for m in range(i, 7):
client_subnet += ".0"
log.info(f"{self.client_address[0]} [{client_subnet}/{netmask}]: cooking the response of type '{qtype}' for {qname} to {fake_record}")

log.info(f"{self.client_address[0]}: cooking the response of type '{qtype}' for {qname} to {fake_record}")




# IPv6 needs additional work before inclusion:
if qtype == "AAAA":
ipv6_hex_tuple = list(map(int, ip_address(fake_record).packed))
@@ -492,6 +490,7 @@ def start_cooking(interface, nametodns, nameservers, tcp=False, ipv6=False, port
rungroup.add_argument("-6","--ipv6", action="store_true", default=False, help="Run in IPv6 mode.")
rungroup.add_argument("-p","--port", metavar="53", default="53", help='Port number to listen for DNS requests.')
rungroup.add_argument("-q", "--quiet", action="store_false", dest="verbose", default=True, help="Don't show headers.")
rungroup.add_argument("--csubnet", action="store_true", default=False, help="Log CSUBNET addr.")

options = parser.parse_args()