I am trying to make a program in python to brute force a ctf C program where you have to find a fruit salad recipe in order to get the flag.
what I want to do : I want to be able to write on the stdin of the C program in python.
Problem : the stdin of the process returned by Popen has a none value while stdout and stderr are correct.
output from my program :
start bruteforce...
<_io.BufferedReader name=3>
<_io.BufferedReader name=5>
None
code :
as you can see I am using print then exit before the loop to debug the process std, I don't understand why I get None
when I print print(process.stdin)
!/usr/bin/python3
import random
import os
import sys
from subprocess import *
from contextlib import contextmanager
from io import StringIO
fruit = ["banana", "raspberry", "orange", "lemon"]
comb = ""
found = False
print("start bruteforce...")
process = Popen(['./fruit'], stdout=PIPE, stderr=PIPE)
print(process.stdout)
print(process.stderr)
print(process.stdin)
sys.exit(1)
while True:
for i in range(4):
pick = random.choice(fruit)
inp, output = process.stdin, process.stdout
comb += pick
comb += " "
inp.write(pick)
inp.write("\n")
out = output.read().decode('utf-8')
if "flag" in out:
found = True
break
if found == True:
print("found : " + com)
break
print(comb + " : is not valid")
comb = ""
os.kill(p.pid, signal.CTRL_C_EVENT)
thanks you !