From 133f2a73bc6a0c4ae4d7d2e45ecd5ef1ffb44962 Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Mon, 7 Oct 2024 11:14:13 -0600 Subject: [PATCH 1/2] Add resolved ip addresses from dns queries to dns module report --- modules/test/dns/python/src/dns_module.py | 32 +++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/test/dns/python/src/dns_module.py b/modules/test/dns/python/src/dns_module.py index c04e289d3..1be69d59a 100644 --- a/modules/test/dns/python/src/dns_module.py +++ b/modules/test/dns/python/src/dns_module.py @@ -97,6 +97,7 @@ def generate_module_report(self): Source Destination + Resolved IP Type URL Count @@ -105,16 +106,16 @@ def generate_module_report(self): ''' # Count unique combinations - counter = Counter( - (row['Source'], row['Destination'], row['Type'], row['Data']) - for row in dns_table_data) + counter = Counter((row['Source'], row['Destination'], row['ResolvedIP'], + row['Type'], row['Data']) for row in dns_table_data) # Generate the HTML table with the count column - for (src, dst, typ, dat), count in counter.items(): + for (src, dst, res_ip, typ, dat), count in counter.items(): table_content += f''' {src} {dst} + {res_ip} {typ} {dat} {count} @@ -166,23 +167,38 @@ def extract_dns_data(self): # 'qr' field indicates query (0) or response (1) dns_type = 'Query' if dns_layer.qr == 0 else 'Response' - # Check for the presence of DNS query name - if hasattr(dns_layer, 'qd') and dns_layer.qd is not None: + # Check if 'qd' (query data) exists and has at least one entry + if hasattr(dns_layer, 'qd') and dns_layer.qdcount > 0: qname = dns_layer.qd.qname.decode() if dns_layer.qd.qname else 'N/A' else: qname = 'N/A' + resolved_ip = 'N/A' + # If it's a response packet, extract the resolved IP address + # from the answer section + if dns_layer.qr == 1 and hasattr(dns_layer, + 'an') and dns_layer.ancount > 0: + # Loop through all answers in the DNS response + for i in range(dns_layer.ancount): + answer = dns_layer.an[i] + # Check for IPv4 (A record) or IPv6 (AAAA record) + if answer.type == 1: # Indicates an A record (IPv4 address) + resolved_ip = answer.rdata # Extract IPv4 address + break # Stop after finding the first valid resolved IP + elif answer.type == 28: # Indicates an AAAA record (IPv6 address) + resolved_ip = answer.rdata # Extract IPv6 address + break # Stop after finding the first valid resolved IP + dns_data.append({ 'Timestamp': float(packet.time), # Timestamp of the DNS packet 'Source': source_ip, 'Destination': destination_ip, + 'ResolvedIP': resolved_ip, # Adding the resolved IP address 'Type': dns_type, 'Data': qname[:-1] }) # Filter unique entries based on 'Timestamp' - # DNS Server will duplicate messages caught by - # startup and monitor filtered_unique_dns_data = [] seen_timestamps = set() From 744077b49b85e418880bb036a1f6fcbb113db8d9 Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Mon, 7 Oct 2024 11:43:08 -0600 Subject: [PATCH 2/2] update dns report --- .../unit/dns/reports/dns_report_local.html | 99 ++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/testing/unit/dns/reports/dns_report_local.html b/testing/unit/dns/reports/dns_report_local.html index f62357a95..d107c66b1 100644 --- a/testing/unit/dns/reports/dns_report_local.html +++ b/testing/unit/dns/reports/dns_report_local.html @@ -1 +1,98 @@ -

DNS Module

Requests to local DNS server Requests to external DNS servers Total DNS requests Total DNS responses
71 0 71 84
Source Destination Type URL Count
10.10.10.14 10.10.10.4 Query mqtt.googleapis.com 64
10.10.10.4 10.10.10.14 Response mqtt.googleapis.com 76
10.10.10.14 10.10.10.4 Query pool.ntp.org 7
10.10.10.4 10.10.10.14 Response pool.ntp.org 8
\ No newline at end of file +

DNS Module

+ + + + + + + + + + + + + + + + +
Requests to local DNS serverRequests to external DNS serversTotal DNS requestsTotal DNS responses
7107184
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SourceDestinationResolved IPTypeURLCount
10.10.10.1410.10.10.4N/AQuerymqtt.googleapis.com64
10.10.10.410.10.10.14173.194.195.206Responsemqtt.googleapis.com38
10.10.10.410.10.10.142607:f8b0:4001:c11::ceResponsemqtt.googleapis.com32
10.10.10.1410.10.10.4N/AQuerypool.ntp.org7
10.10.10.410.10.10.14N/AResponsepool.ntp.org4
10.10.10.410.10.10.145.78.89.3Responsepool.ntp.org2
10.10.10.410.10.10.14199.68.201.234Responsepool.ntp.org2
10.10.10.410.10.10.142607:f8b0:4001:c08::ceResponsemqtt.googleapis.com6
+ \ No newline at end of file