Bash program:
user@root:~/Downloads# ./program
What is the password?
So it asks for an input, and if you get the right password it continues on with the program, else it will exit (for the sake of the question, the password is a number 0 to 1000).
I need to write a Python 2 script to brute force the password. I figure the pseudocode would be something like:
import subprocess
x = 0
while x <= 1000:
subprocess.Popen('./program', stdin=PIPE)
input x
if program exits:
continue
else:
break
x += 1
I have very basic knowledge of using Popen
to run a command in the terminal, however I'm not sure how to input a string using subprocess - any Googling I've done just leads me to people doing other stuff with other inputs.
I'm also stuck on how to check if the program has exited or not.
thank you :)