1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

add axfr support

This commit is contained in:
Kelly Brazil
2020-03-26 16:22:53 -07:00
parent 8ec8cd6294
commit cd8d38f2a1

View File

@ -324,7 +324,7 @@ import jc.utils
class info(): class info():
version = '1.0' version = '1.1'
description = 'dig command parser' description = 'dig command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -402,6 +402,14 @@ def process(proc_data):
except (ValueError): except (ValueError):
entry[key] = None entry[key] = None
if 'axfr' in entry:
for ax in entry['axfr']:
try:
ttl_int = int(ax['ttl'])
ax['ttl'] = ttl_int
except (ValueError):
ax['ttl'] = None
if 'answer' in entry: if 'answer' in entry:
for ans in entry['answer']: for ans in entry['answer']:
try: try:
@ -507,6 +515,24 @@ def parse_answer(answer):
'ttl': answer_ttl, 'ttl': answer_ttl,
'data': answer_data} 'data': answer_data}
def parse_axfr(axfr):
#; <<>> DiG 9.11.14-3-Debian <<>> @81.4.108.41 axfr zonetransfer.me +nocookie
#; (1 server found)
#;; global options: +cmd
#zonetransfer.me. 7200 IN A 5.196.105.14
axfr = axfr.split(maxsplit=4)
axfr_name = axfr[0]
axfr_ttl = axfr[1]
axfr_class = axfr[2]
axfr_type = axfr[3]
axfr_data = axfr[4]
return {'name': axfr_name,
'ttl': axfr_ttl,
'class': axfr_class,
'type': axfr_type,
'data': axfr_data}
def parse(data, raw=False, quiet=False): def parse(data, raw=False, quiet=False):
""" """
@ -534,10 +560,24 @@ def parse(data, raw=False, quiet=False):
question = False question = False
authority = False authority = False
answer = False answer = False
axfr = False
output_entry = {} output_entry = {}
for line in cleandata: for line in cleandata:
if line.startswith('; <<>> ') and line.lower().find(' axfr ') != -1:
question = False
authority = False
answer = False
axfr = True
axfr_list = []
continue
if line.find(';') == -1 and axfr:
axfr_list.append(parse_axfr(line))
output_entry.update({'axfr': axfr_list})
continue
if line.find(';; ->>HEADER<<-') == 0: if line.find(';; ->>HEADER<<-') == 0:
output_entry = {} output_entry = {}
output_entry.update(parse_header(line)) output_entry.update(parse_header(line))
@ -551,6 +591,7 @@ def parse(data, raw=False, quiet=False):
question = True question = True
authority = False authority = False
answer = False answer = False
axfr = False
continue continue
if question: if question:
@ -558,12 +599,14 @@ def parse(data, raw=False, quiet=False):
question = False question = False
authority = False authority = False
answer = False answer = False
axfr = False
continue continue
if line.find(';; AUTHORITY SECTION:') == 0: if line.find(';; AUTHORITY SECTION:') == 0:
question = False question = False
authority = True authority = True
answer = False answer = False
axfr = False
authority_list = [] authority_list = []
continue continue
@ -576,6 +619,7 @@ def parse(data, raw=False, quiet=False):
question = False question = False
authority = False authority = False
answer = True answer = True
axfr = False
answer_list = [] answer_list = []
continue continue
@ -604,6 +648,11 @@ def parse(data, raw=False, quiet=False):
if line.find(';; MSG SIZE rcvd:') == 0: if line.find(';; MSG SIZE rcvd:') == 0:
output_entry.update({'rcvd': line.split(':')[1].lstrip()}) output_entry.update({'rcvd': line.split(':')[1].lstrip()})
if output_entry:
raw_output.append(output_entry)
elif line.startswith(';; XFR size:'):
output_entry.update({'size': line.split(':')[1].lstrip()})
if output_entry: if output_entry:
raw_output.append(output_entry) raw_output.append(output_entry)