I'm executing the following subprocess...
p.call(["./hex2raw", "<", "exploit4.txt", "|", "./rtarget"])
...and it hangs.
But if I execute kmwe236@kmwe236:~/CS485/prog3/target26$ ./hex2raw < exploit4.txt | ./rtarget
then it executes fine. Is there something wrong with using the input or piping operator?
I also tried sp.call(["./hex2raw", "<", "exploit4.txt", "|", "./rtarget"], shell=True)
The entire code looks like this UPDATED WITH SUGGESTIONS
import subprocess as sp
import pdb
for i in range(4201265,4201323):
pdb.set_trace()
d = hex(i)[2:]
output = " "
for i in range(len(d),0,-2):
output = output + d[i-2:i] + " "
out_buffer = "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + output + "00 00 00 00"
text_file = open("exploit4.txt", "w")
text_file.write("%s" % out_buffer)
# sp.call(["./hex2raw", "<", "exploit4.txt", "|", "./rtarget"], shell=True)
with open("exploit4.txt") as inhandle:
p = sp.Popen("./hex2raw",stdin=inhandle,stdout=sp.PIPE)
p2 = sp.Popen("./rtarget",stdin=p.stdout,stdout=sp.PIPE)
[output,error] = p2.communicate()
I'm getting an error is
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
After debugging it occurs at the fire subprocess call p = sp.Popen("./hex2raw",stdin=inhandle,stdout=sp.PIPE)