pwntools icon indicating copy to clipboard operation
pwntools copied to clipboard

Process: Fix AttributeError when stdin, stdout, and stderr are redirected to files

Open jamestiotio opened this issue 2 years ago • 1 comments

This closes #2036.

This PR would allow users to redirect stdin, stdout, or/and stderr to files via 2 methods, even partially (i.e., the user can choose to redirect only stdin, only stdout, only stderr, or any combination of those 3):

  1. By using Python's built-in open() function:

    pwn.process("cat", stdin=open("some_file", "r"), stdout=open("some_other_file", "w"), stderr=open("yet_another_file", "w"))
    
  2. By using the os.open() function:

    pwn.process(["cat", "-"], stdin=os.open("some_file", os.O_RDWR), stdout=os.open("some_other_file", os.O_RDWR), stderr=os.open("yet_another_file", os.O_RDWR))
    

If the user passes in some raw integer(s) for stdin, stdout, or/and stderr, such as when they invoke os.open(), we only attempt to check whether they are valid file descriptors or not. Other than that, we trust the user that they know what they are doing.

jamestiotio avatar Aug 29 '22 16:08 jamestiotio

@Arusekk Could you kindly review this PR? Thank you!

jamestiotio avatar Sep 14 '22 06:09 jamestiotio

It looks like this code is overly complex. I think we do not want to do any file descriptor validation, as they are foreign objects to Python code, and validating them is inherently racy.

Arusekk avatar Dec 28 '22 22:12 Arusekk