pry0cc / axiom

The dynamic infrastructure framework for everybody! Distribute the workload of many different scanning tools with ease, including nmap, ffuf, masscan, nuclei, meg and many more!
MIT License
3.91k stars 615 forks source link

running axiom-scan command using subprocess python3, axiom-scan did not stop and process hang at #803

Closed yanzifan021 closed 1 month ago

yanzifan021 commented 1 month ago

Hi guys, I am using subprocess to automate axiom-scan. It is fine when i run it directly throughpython3 automation.py. However, when i run it with 'nohup python3 automation.py &'. After it output to nabuu_result.txt, the axiom-scan process didnt stop and hang there(tested by running pgrep -af "axiom-scan", and i can see the proecss). the code is below ` import subprocess import sys import config import os current_dir = os.path.dirname(os.path.abspath(file)) from utilities import mysqldb,common_function,discordBot import logging

env_copy = os.environ.copy() current_path = env_copy['PATH'] env_copy["PATH"] = os.pathsep.join([ config.GOBIN, # go bin path current_path, config.AXIOM_PATH # axiom path ])

cmd = f"axiom-scan {current_dir}/subdomains.txt -m naabu -c 10000 -j -o {current_dir}/nabuu_result.txt --fleet scanist"

process = subprocess.Popen(cmd.split(' '), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE,env=env_copy) stdout, stderr = process.communicate() ` Thanks in advance for the help. I am sorry if i asked in the wrong place.

command I used to run the script nohup python3 automation.py &

yanzifan021 commented 1 month ago

I think axiom-scan will read stdin for the sake of resume scan if ctrl +c, which makes the process hang, after i run process = subprocess.Popen(cmd.split(' '), shell=False,stdin=open(os.devnull), preexec_fn=os.setsid), it is solved.

reference: https://stackoverflow.com/questions/33277452/prevent-unexpected-stdin-reads-and-lock-in-subprocess