Added Markdown Report Plugin

Markdown Report Plugin made default.
Added check to ensure that reports aren't generated twice.
This commit is contained in:
Tib3rius 2021-09-08 22:00:48 -04:00
parent bc2c8afe18
commit 35b5647f4d
2 changed files with 113 additions and 36 deletions

View File

@ -1297,26 +1297,28 @@ async def main():
keyboard_monitor.cancel() keyboard_monitor.cancel()
for plugin in autorecon.plugin_types['report']: # If there's only one target we don't need a combined report
plugin_tag_set = set(plugin.tags) if len(autorecon.completed_targets) > 1:
for plugin in autorecon.plugin_types['report']:
plugin_tag_set = set(plugin.tags)
matching_tags = False matching_tags = False
for tag_group in autorecon.tags: for tag_group in autorecon.tags:
if set(tag_group).issubset(plugin_tag_set): if set(tag_group).issubset(plugin_tag_set):
matching_tags = True matching_tags = True
break break
excluded_tags = False excluded_tags = False
for tag_group in autorecon.excluded_tags: for tag_group in autorecon.excluded_tags:
if set(tag_group).issubset(plugin_tag_set): if set(tag_group).issubset(plugin_tag_set):
excluded_tags = True excluded_tags = True
break break
if matching_tags and not excluded_tags: if matching_tags and not excluded_tags:
pending.add(asyncio.create_task(generate_report(plugin, autorecon.completed_targets))) pending.add(asyncio.create_task(generate_report(plugin, autorecon.completed_targets)))
while pending: while pending:
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED, timeout=1) done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED, timeout=1)
if timed_out: if timed_out:
cancel_all_tasks(None, None) cancel_all_tasks(None, None)

View File

@ -8,12 +8,13 @@ class CherryTree(Report):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.name = 'CherryTree' self.name = 'CherryTree'
self.tags = []
async def run(self, targets): async def run(self, targets):
if len(targets) > 1: if len(targets) > 1:
report = os.path.join(config['outdir'], 'cherrytree.xml.ctd') report = os.path.join(config['outdir'], 'report.xml.ctd')
elif len(targets) == 1: elif len(targets) == 1:
report = os.path.join(targets[0].reportdir, 'cherrytree.xml.ctd') report = os.path.join(targets[0].reportdir, 'report.xml.ctd')
else: else:
return return
@ -27,24 +28,9 @@ class CherryTree(Report):
if target.scans['ports']: if target.scans['ports']:
output.writelines('<node name="Port Scans" custom_icon_id="2">\n') output.writelines('<node name="Port Scans" custom_icon_id="2">\n')
for scan in target.scans['ports'].keys(): for scan in target.scans['ports'].keys():
output.writelines('<node name="PortScan: ' + escape(scan) + '" custom_icon_id="21">\n') if len(target.scans['ports'][scan]['commands']) > 0:
for command in target.scans['ports'][scan]['commands']: output.writelines('<node name="PortScan: ' + escape(target.scans['ports'][scan]['plugin'].name) + '" custom_icon_id="21">\n')
output.writelines('<rich_text>' + escape(command[0])) for command in target.scans['ports'][scan]['commands']:
for filename in files:
if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]):
output.writelines('\n\n' + escape(filename) + ':\n\n')
with open(filename, 'r') as file:
output.writelines(escape(file.read()) + '\n')
output.writelines('</rich_text>\n')
output.writelines('</node>\n')
output.writelines('</node>\n')
if target.scans['services']:
output.writelines('<node name="Services" custom_icon_id="2">\n')
for service in target.scans['services'].keys():
output.writelines('<node name="Service: ' + escape(service.tag()) + '" custom_icon_id="3">\n')
for plugin in target.scans['services'][service].keys():
output.writelines('<node name="' + escape(target.scans['services'][service][plugin]['plugin'].slug) + '" custom_icon_id="21">\n')
for command in target.scans['services'][service][plugin]['commands']:
output.writelines('<rich_text>' + escape(command[0])) output.writelines('<rich_text>' + escape(command[0]))
for filename in files: for filename in files:
if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]): if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]):
@ -53,6 +39,23 @@ class CherryTree(Report):
output.writelines(escape(file.read()) + '\n') output.writelines(escape(file.read()) + '\n')
output.writelines('</rich_text>\n') output.writelines('</rich_text>\n')
output.writelines('</node>\n') output.writelines('</node>\n')
output.writelines('</node>\n')
if target.scans['services']:
output.writelines('<node name="Services" custom_icon_id="2">\n')
for service in target.scans['services'].keys():
output.writelines('<node name="Service: ' + escape(service.tag()) + '" custom_icon_id="3">\n')
for plugin in target.scans['services'][service].keys():
if len(target.scans['services'][service][plugin]['commands']) > 0:
output.writelines('<node name="' + escape(target.scans['services'][service][plugin]['plugin'].name) + '" custom_icon_id="21">\n')
for command in target.scans['services'][service][plugin]['commands']:
output.writelines('<rich_text>' + escape(command[0]))
for filename in files:
if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]):
output.writelines('\n\n' + escape(filename) + ':\n\n')
with open(filename, 'r') as file:
output.writelines(escape(file.read()) + '\n')
output.writelines('</rich_text>\n')
output.writelines('</node>\n')
output.writelines('</node>\n') output.writelines('</node>\n')
output.writelines('</node>\n') output.writelines('</node>\n')
@ -86,3 +89,75 @@ class CherryTree(Report):
output.writelines('</node>\n') output.writelines('</node>\n')
output.writelines('</cherrytree>') output.writelines('</cherrytree>')
class Markdown(Report):
def __init__(self):
super().__init__()
self.name = 'Markdown'
async def run(self, targets):
if len(targets) > 1:
report = os.path.join(config['outdir'], 'report.md')
elif len(targets) == 1:
report = os.path.join(targets[0].reportdir, 'report.md')
else:
return
os.makedirs(report, exist_ok=True)
for target in targets:
os.makedirs(os.path.join(report, target.address), exist_ok=True)
files = [os.path.abspath(filename) for filename in glob.iglob(os.path.join(target.scandir, '**/*'), recursive=True) if os.path.isfile(filename) and filename.endswith(('.txt', '.html'))]
if target.scans['ports']:
os.makedirs(os.path.join(report, target.address, 'Port Scans'), exist_ok=True)
for scan in target.scans['ports'].keys():
if len(target.scans['ports'][scan]['commands']) > 0:
with open(os.path.join(report, target.address, 'Port Scans', 'PortScan - ' + target.scans['ports'][scan]['plugin'].name + '.md'), 'w') as output:
for command in target.scans['ports'][scan]['commands']:
output.writelines('```bash\n' + command[0] + '\n```')
for filename in files:
if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]):
output.writelines('\n\n[' + filename + '](file://' + filename + '):\n\n')
with open(filename, 'r') as file:
output.writelines('```\n' + file.read() + '\n```\n')
if target.scans['services']:
os.makedirs(os.path.join(report, target.address, 'Services'), exist_ok=True)
for service in target.scans['services'].keys():
os.makedirs(os.path.join(report, target.address, 'Services', 'Service - ' + service.tag().replace('/', '-')), exist_ok=True)
for plugin in target.scans['services'][service].keys():
if len(target.scans['services'][service][plugin]['commands']) > 0:
with open(os.path.join(report, target.address, 'Services', 'Service - ' + service.tag().replace('/', '-'), target.scans['services'][service][plugin]['plugin'].name + '.md'), 'w') as output:
for command in target.scans['services'][service][plugin]['commands']:
output.writelines('```bash\n' + command[0] + '\n```')
for filename in files:
if filename in command[0] or (command[1] is not None and filename == command[1]) or (command[2] is not None and filename == command[2]):
output.writelines('\n\n[' + filename + '](file://' + filename + '):\n\n')
with open(filename, 'r') as file:
output.writelines('```\n' + file.read() + '\n```\n')
manual_commands = os.path.join(target.scandir, '_manual_commands.txt')
if os.path.isfile(manual_commands):
with open(os.path.join(report, target.address, 'Manual Commands' + '.md'), 'w') as output:
with open(manual_commands, 'r') as file:
output.writelines('```bash\n' + file.read() + '\n```')
patterns = os.path.join(target.scandir, '_patterns.log')
if os.path.isfile(patterns):
with open(os.path.join(report, target.address, 'Patterns' + '.md'), 'w') as output:
with open(patterns, 'r') as file:
output.writelines(file.read())
commands = os.path.join(target.scandir, '_commands.log')
if os.path.isfile(commands):
with open(os.path.join(report, target.address, 'Commands' + '.md'), 'w') as output:
with open(commands, 'r') as file:
output.writelines('```bash\n' + file.read() + '\n```')
errors = os.path.join(target.scandir, '_errors.log')
if os.path.isfile(errors):
with open(os.path.join(report, target.address, 'Errors' + '.md'), 'w') as output:
with open(errors, 'r') as file:
output.writelines('```\n' + file.read() + '\n```')