Skip to content

Commit

Permalink
cmd output tuning for multi target scan
Browse files Browse the repository at this point in the history
  • Loading branch information
juerkkil committed Dec 16, 2024
1 parent 83048dd commit b96ea0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion secheaders/cmd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_eval_output(warn, no_color):

def output_text(target_url, headers, https, no_color=False, verbose=False) -> str:
terminal_width = shutil.get_terminal_size().columns
output_str = f"Scanning target {target_url} ...\n\n"
output_str = f"Scanning target {target_url} ...\n"

# If the stdout is not going into terminal, disable colors
no_color = no_color or not sys.stdout.isatty()
Expand Down Expand Up @@ -66,4 +66,5 @@ def output_text(target_url, headers, https, no_color=False, verbose=False) -> st

output_str += output

output_str += '\n'
return output_str
28 changes: 18 additions & 10 deletions secheaders/secheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ def main():
asyncio.run(scan_multiple_targets(args))


scan_results = []


def async_scan_done(scan):
try:
res = scan.result()
print(cmd_utils.output_text(res['target'], res['headers'], res['https']))
print("========================\n")
res, args = scan.result()
print(cmd_utils.output_text(res['target'], res['headers'], res['https'], args.no_color, args.verbose))
except SecurityHeadersException as e:
print(e, file=sys.stderr)

Expand All @@ -81,22 +77,34 @@ def scan_target(url, args):
return {'target': header_check.get_full_url(), 'headers': headers, 'https': https}


def scan_target_wrapper(url, args):
# A bit of a dirty hack to pass args to the done callback
return scan_target(url, args), args


async def scan_multiple_targets(args):
with open(args.target_list, encoding='utf-8') as file:
targets = [line.rstrip() for line in file]

loop = asyncio.get_event_loop()
tasks = []
for t in targets:
task = loop.run_in_executor(None, scan_target, t, args)
task.add_done_callback(async_scan_done)
for target in targets:
if args.json:
task = loop.run_in_executor(None, scan_target, target, args)
else:
task = loop.run_in_executor(None, scan_target_wrapper, target, args)
task.add_done_callback(async_scan_done)
tasks.append(task)

res = []
for task in tasks:
await task

print("ALL COMPLETED!")
if args.json:
for t in tasks:
res.append(t.result())

print(str(res))

if __name__ == "__main__":
main()

0 comments on commit b96ea0f

Please sign in to comment.