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 15, 2024
1 parent 83048dd commit 27b6b3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 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
17 changes: 9 additions & 8 deletions secheaders/secheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def main():

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 +80,24 @@ 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)
for target in targets:
task = loop.run_in_executor(None, scan_target_wrapper, target, args)
task.add_done_callback(async_scan_done)
tasks.append(task)

for task in tasks:
await task

print("ALL COMPLETED!")


if __name__ == "__main__":
main()

0 comments on commit 27b6b3c

Please sign in to comment.