0

I'm trying to close the process if the process has stopped writing lines (meaning the program has crashed, in this specific case because the process will always be printing lines).

but when I do line = proc.stdout.readline().decode("utf-8") and then the process is hanging not printing anything to stdout, stderr, then my while loop isn't getting looped over.. I would like to do this so I can detect when ffuf is hanging, and then after 10 seconds of the process continuously hanging I will kill the process

tl;dr #If there is no more lines being printed by ffuf, the while loop will not get hit even if go_next_domain is True

with open("riot.txt") as f:
    for f_line in f:
        f_line = f_line.rstrip("\n\r")
        proc = subprocess.Popen(['ffuf', f_line], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        go_next_domain = False
        start_time = time.time()
        last_line_recieved = time.time()

        print("Bruteforcing", f_line)

        while not go_next_domain:
            print(proc.stdout.readable())
            line = proc.stdout.readline().decode("utf-8")
noobyy
  • 123
  • 9

1 Answers1

0

This isn't the answer i'm looking for or want, more of a fix until I find out a better answer or someone provides one. Just updates a variable with the current time when stdoud/stderr receives a string, It will kill the program if it doesn't receive a string for 5 seconds.

proc = None
last_line_recieved = time.time()
go_next_domain = None

def kill_process():
    global go_next_domain
    while not go_next_domain:
        if time.time() - last_line_recieved > 5:
            proc.kill()
            print("Killing proccess...")
            go_next_domain = True

threading.Thread(target=kill_process).start()

with open("riot.txt") as f:
    for f_line in f:
        f_line = f_line.rstrip("\n\r")
        proc = subprocess.Popen(['ffuf', f_line], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        go_next_domain = False
        start_time = time.time()
        last_line_recieved = time.time()

        print("Bruteforcing", f_line)

        while not go_next_domain:
            line = proc.stdout.readline().decode("utf-8")
noobyy
  • 123
  • 9