Skip to content

Commit 2c63476

Browse files
authored
Merge pull request #116 from amm3/master
Base64 fix to httpdump, and feature update to dns
2 parents be3b374 + 86aaf7f commit 2c63476

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

decoders/dns/dns.py

100644100755
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ def decode_q(self, dns):
2222
queried = ""
2323
if dns.qd[0].type == dpkt.dns.DNS_A:
2424
queried = queried + "A? %s" % (dns.qd[0].name)
25-
if dns.qd[0].type == dpkt.dns.DNS_CNAME:
25+
elif dns.qd[0].type == dpkt.dns.DNS_CNAME:
2626
queried = queried + "CNAME? %s" % (dns.qd[0].name)
27-
if dns.qd[0].type == dpkt.dns.DNS_AAAA:
27+
elif dns.qd[0].type == dpkt.dns.DNS_AAAA:
2828
queried = queried + "AAAA? %s" % (dns.qd[0].name)
29-
if dns.qd[0].type == dpkt.dns.DNS_PTR:
29+
elif dns.qd[0].type == dpkt.dns.DNS_SOA:
30+
queried = queried + "SOA? %s" % (dns.qd[0].name)
31+
elif dns.qd[0].type == dpkt.dns.DNS_PTR:
3032
if dns.qd[0].name.endswith('.in-addr.arpa'):
3133
query_name = '.'.join(
3234
reversed(dns.qd[0].name.split('.in-addr.arpa')[0].split('.')))
@@ -39,11 +41,11 @@ def decode_q(self, dns):
3941

4042
if dns.qd[0].type == dpkt.dns.DNS_NS:
4143
queried = queried + "NS? %s" % (dns.qd[0].name)
42-
if dns.qd[0].type == dpkt.dns.DNS_MX:
44+
elif dns.qd[0].type == dpkt.dns.DNS_MX:
4345
queried = queried + "MX? %s" % (dns.qd[0].name)
44-
if dns.qd[0].type == dpkt.dns.DNS_TXT:
46+
elif dns.qd[0].type == dpkt.dns.DNS_TXT:
4547
queried = queried + "TXT? %s" % (dns.qd[0].name)
46-
if dns.qd[0].type == dpkt.dns.DNS_SRV:
48+
elif dns.qd[0].type == dpkt.dns.DNS_SRV:
4749
queried = queried + "SRV? %s" % (dns.qd[0].name)
4850

4951
return queried
@@ -65,7 +67,7 @@ def DNSHandler(self, conn, request, response, **kwargs):
6567
conn.info(query=self.decode_q(dns))
6668

6769
# DNS Answer with data and no errors
68-
elif (dns.qr == dpkt.dns.DNS_A and dns.rcode == dpkt.dns.DNS_RCODE_NOERR and len(dns.an) > 0):
70+
elif (dns.rcode == dpkt.dns.DNS_RCODE_NOERR and len(dns.an) > 0):
6971

7072
queried = self.decode_q(dns)
7173

@@ -108,6 +110,16 @@ def DNSHandler(self, conn, request, response, **kwargs):
108110
if queried != '':
109111
anstext = 'NXDOMAIN'
110112

113+
#SOA response
114+
elif dns.qd[0].type == dpkt.dns.DNS_SOA and len(dns.ns):
115+
queried = self.decode_q(dns)
116+
answers = []
117+
for ns in dns.ns:
118+
if ns.type == dpkt.dns.DNS_SOA:
119+
answers.append('SOA: '+ ns.mname)
120+
anstext = ", ".join(answers)
121+
122+
111123
# did we get an answer?
112124
if anstext and not self.only_noanswer and not self.only_norequest:
113125
self.alert(

decoders/http/httpdump.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def HTTPHandler(self, conn, request, response, requesttime, responsetime):
7676
request.method, response.status, host, uri_location, util.getHeader(response, 'content-type'))
7777
urlParams = util.URLDataToParameterDict(uri_data)
7878
postParams = util.URLDataToParameterDict(request.body)
79+
# If URLData parser only returns a single element with null value, it's probably an eroneous evaluation. Most likely base64 encoded payload ending in an '=' character.
80+
if len(postParams)==1 and postParams[postParams.keys()[0]] == '\x00':
81+
postParams = None
7982

8083
clientCookies = self._parseCookies(util.getHeader(request, 'cookie'))
8184
serverCookies = self._parseCookies(

0 commit comments

Comments
 (0)