| 3 | import os, glob |
| 4 | |
| 5 | class Markdown(Report): |
| 6 | |
| 7 | def __init__(self): |
| 8 | super().__init__() |
| 9 | self.name = 'Markdown' |
| 10 | |
| 11 | async def run(self, targets): |
| 12 | if len(targets) > 1: |
| 13 | report = os.path.join(config['output'], 'report.md') |
| 14 | elif len(targets) == 1: |
| 15 | report = os.path.join(targets[0].reportdir, 'report.md') |
| 16 | else: |
| 17 | return |
| 18 | |
| 19 | os.makedirs(report, exist_ok=True) |
| 20 | |
| 21 | for target in targets: |
| 22 | os.makedirs(os.path.join(report, target.address), exist_ok=True) |
| 23 | |
| 24 | 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'))] |
| 25 | |
| 26 | if target.scans['ports']: |
| 27 | os.makedirs(os.path.join(report, target.address, 'Port Scans'), exist_ok=True) |
| 28 | for scan in target.scans['ports'].keys(): |
| 29 | if len(target.scans['ports'][scan]['commands']) > 0: |
| 30 | with open(os.path.join(report, target.address, 'Port Scans', 'PortScan - ' + target.scans['ports'][scan]['plugin'].name + '.md'), 'w') as output: |
| 31 | for command in target.scans['ports'][scan]['commands']: |
| 32 | output.writelines('```bash\n' + command[0] + '\n```') |
| 33 | for filename in files: |
| 34 | 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]): |
| 35 | output.writelines('\n\n[' + filename + '](file://' + filename + '):\n\n') |
| 36 | with open(filename, 'r') as file: |
| 37 | output.writelines('```\n' + file.read() + '\n```\n') |
| 38 | if target.scans['services']: |
| 39 | os.makedirs(os.path.join(report, target.address, 'Services'), exist_ok=True) |
| 40 | for service in target.scans['services'].keys(): |
| 41 | os.makedirs(os.path.join(report, target.address, 'Services', 'Service - ' + service.tag().replace('/', '-')), exist_ok=True) |
| 42 | for plugin in target.scans['services'][service].keys(): |
| 43 | if len(target.scans['services'][service][plugin]['commands']) > 0: |
| 44 | with open(os.path.join(report, target.address, 'Services', 'Service - ' + service.tag().replace('/', '-'), target.scans['services'][service][plugin]['plugin'].name + '.md'), 'w') as output: |
| 45 | for command in target.scans['services'][service][plugin]['commands']: |
| 46 | output.writelines('```bash\n' + command[0] + '\n```') |
| 47 | for filename in files: |
| 48 | 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]): |
| 49 | output.writelines('\n\n[' + filename + '](file://' + filename + '):\n\n') |
| 50 | with open(filename, 'r') as file: |
| 51 | output.writelines('```\n' + file.read() + '\n```\n') |
| 52 | |
| 53 | manual_commands = os.path.join(target.scandir, '_manual_commands.txt') |
| 54 | if os.path.isfile(manual_commands): |
| 55 | with open(os.path.join(report, target.address, 'Manual Commands' + '.md'), 'w') as output: |
| 56 | with open(manual_commands, 'r') as file: |
| 57 | output.writelines('```bash\n' + file.read() + '\n```') |
| 58 | |
| 59 | patterns = os.path.join(target.scandir, '_patterns.log') |
| 60 | if os.path.isfile(patterns): |
| 61 | with open(os.path.join(report, target.address, 'Patterns' + '.md'), 'w') as output: |
| 62 | with open(patterns, 'r') as file: |
nothing calls this directly
no outgoing calls
no test coverage detected