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

interactive() readline history chokes on UTF-8 characters #1004

Closed
rofl0r opened this issue Jul 27, 2017 · 6 comments
Closed

interactive() readline history chokes on UTF-8 characters #1004

rofl0r opened this issue Jul 27, 2017 · 6 comments
Labels
Milestone

Comments

@rofl0r
Copy link

rofl0r commented Jul 27, 2017

test.py (doesn't work from inside REPL):

from pwn import *
r = process('cat', shell=True)
r.interactive()
  • enter a string containing UTF-8 characters such löl <ENTER>.
  • hit cursor-up to access readline history
  • encounter exception:
  File "/lib/python2.7/site-packages/pwnlib/term/readline.py", line 131, in set_buffer
    buffer_left = unicode(left)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
@zachriggle
Copy link
Member

zachriggle commented Sep 14, 2017

Yup. Welcome to Python2! If you are sending unicode you need to perform the appropriate encode / decode magic to turn it into a bytes object.

Alternately, I recommend setting a default encoding for your system, and setting an appropriate header.

https://stackoverflow.com/questions/2276200/changing-default-encoding-of-python
https://stackoverflow.com/questions/3170211/why-declare-unicode-by-string-in-python

@rofl0r
Copy link
Author

rofl0r commented Sep 14, 2017

so you don't think that pwntools should catch this error ?

zachriggle added a commit to zachriggle/pwntools that referenced this issue Sep 14, 2017
Technically this introduces issues with e.g. 'unhex ffdf | python foo.py' if
foo.py uses .interactive().  However, that was already broken for other reasons.

Fixes Gallopsled#1004
@zachriggle
Copy link
Member

After some sleep, I see that the issue you're reporting is different than I was expecting.

@zachriggle zachriggle reopened this Sep 14, 2017
zachriggle added a commit that referenced this issue Sep 17, 2017
Technically this introduces issues with e.g. 'unhex ffdf | python foo.py' if
foo.py uses .interactive().  However, that was already broken for other reasons.

Fixes #1004
@rofl0r
Copy link
Author

rofl0r commented Sep 17, 2017

great, ty !

zachriggle added a commit to zachriggle/pwntools that referenced this issue Sep 26, 2017
Technically this introduces issues with e.g. 'unhex ffdf | python foo.py' if
foo.py uses .interactive().  However, that was already broken for other reasons.

Fixes Gallopsled#1004

(cherry picked from commit ebbe917)
@TethysSvensson
Copy link
Contributor

I haven't tried replicating this, but from the commit log, it seems to have only been fixed for dev?

@TethysSvensson
Copy link
Contributor

Hmm, nope. It just didn't go through a PR when pushed into stable.

@zachriggle zachriggle added the bug label Oct 12, 2017
@zachriggle zachriggle added this to the 3.9.0 milestone Oct 12, 2017
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

3 participants