Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to exit interactive() when EOF received? #2106

Open
gsingh93 opened this issue Sep 5, 2022 · 2 comments
Open

How to exit interactive() when EOF received? #2106

gsingh93 opened this issue Sep 5, 2022 · 2 comments
Labels

Comments

@gsingh93
Copy link
Contributor

gsingh93 commented Sep 5, 2022

If I call process.interactive() and the process terminates, I get a message about an EOFError but the interactive prompt still stays open. How can I break from this prompt when an error is received?

@gsingh93
Copy link
Contributor Author

Here's an example I'm using to test:

#!/usr/bin/env python3

from pwn import *

def check_connection(p):
    print('p.proc.stdin.closed:', p.proc.stdin.closed)
    print('p.proc.stdout.closed:', p.proc.stdout.closed)
    print("p.connected('send'):", p.connected('send'))
    print("p.connected('recv')", p.connected('recv'))
    print("p.can_recv()", p.can_recv())
    print('')

p = process('/bin/ls')

check_connection(p)

p.interactive()

check_connection(p)

try:
    p.send(b'A')
except:
    pass

check_connection(p)

Output:

$ ./test-interactive.py
[+] Starting local process '/bin/ls': pid 2131696
p.proc.stdin.closed: False
p.proc.stdout.closed: False
p.connected('send'): True
p.connected('recv') True
p.can_recv() True

[*] Switching to interactive mode
[*] Process '/bin/ls' stopped with exit code 0 (pid 2131696)
a.out  aslr.c  test-interactive.py  test.py
[*] Got EOF while reading in interactive
$
[*] Interrupted
p.proc.stdin.closed: False
p.proc.stdout.closed: True
p.connected('send'): True
p.connected('recv') False
p.can_recv() False

p.proc.stdin.closed: False
p.proc.stdout.closed: True
p.connected('send'): True
p.connected('recv') False
p.can_recv() False

Traceback (most recent call last):
  File "/home/gsgx/.local/lib/python3.10/site-packages/pwnlib/tubes/process.py", line 746, in close
    fd.close()
BrokenPipeError: [Errno 32] Broken pipe

So the EOFError happened in the middle of interactive() on the recv side, so I can't check for this before calling it. Essentially, I'd like interactive() to end if the recv end disconnects, without waiting for the send end to disconnect.

@gsingh93
Copy link
Contributor Author

This hacky patch seems to fix the issue: gsingh93@4873414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant