-1

I have a problem with subprocesses in python: my script opens an ELF file that executes a fopen() on a file in the same directory of the ELF. The ELF works fine if I open it directly (no "file not found" error) but when running it from the python script, it cannot find the file. The script is in another directory and the code is this:

from pwn import *
from subprocess import *

proc = subprocess.Popen("/home/m876650/mission3/mission3",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

ret_addr = 0x00000000004007d8

print proc.stdout.readline()

payload = "A"*374 + p64(ret_addr)

proc.stdin.write(payload + '\n')

It is for a security challenge, nothing illegal! Thanks for the help!

1 Answers1

0

If your process is loading the file with a relative path, then it expects the current working directory to be the same as where your script is located.

You'll need to set the current working directory for the process, by passing in the right directory to the cwd option to subprocess.Popen():

proc = subprocess.Popen(
    ["/home/m876650/mission3/mission3"],
    cwd="/home/m876650/mission3",
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

Note that the first argument to Popen() is the command and its arguments, so you want that to be a sequence.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343