Pycharm – Use pwntools with remote interpreter on WSL
I use the remote interpreter on pycharm on WSL (configure it with this tutorial: https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html)
I was able to successfully run everything I needed, but when I tried to use pwntools ( https://github.com/Gallopsled/pwntools ), I was able to successfully import it on the WSL bash python interpreter, but not on Pycharm.
Here is what I ran :
from pwn import *
On Pycharm it got stuck, I interrupted it, here’s the trace of the anomaly (where it stucks):
ssh://shahar@localhost:22/usr/bin/python -u /tmp/pycharm_project_271/pwnablekr/fd.py
Traceback (most recent call last):
File "/tmp/pycharm_project_271/pwnablekr/fd.py", line 1, in <module>
from pwn import *
File "/home/shahar/.local/lib/python2.7/site-packages/pwn/__init__.py", line 6, in <module>
pwnlib.args.initialize()
File "/home/shahar/.local/lib/python2.7/site-packages/pwnlib/args.py", line 208, in initialize
term.init()
File "/home/shahar/.local/lib/python2.7/site-packages/pwnlib/term/__init__.py", line 74, in init
term.init()
File "/home/shahar/.local/lib/python2.7/site-packages/pwnlib/term/term.py", line 109, in init
c = os.read(fd.fileno(), 1)
KeyboardInterrupt
Process finished with exit code 1
enter code here
It works just fine on my WSL bash :
shahar@MYCOMPUTERNAME:/mnt/c/Users/shahar$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>>
When I look at that piece of code where it gets stuck (judging by the traces of the exception):
while True:
c = os.read(fd.fileno(), 1)
s += c
if c == 'R':
break
At the beginning of the script as a global variable:
fd = sys.stdout
I learned from the internet that this function (of which this loop is a part) has to do with taking over the terminal. Maybe it’s related to the fact that I’m not running from the terminal?
Has anyone seen this kind of problem before? Any helpful tips?
Thank you very much!
Solution
I also have a potential fix that is adding a PWNLIB_NOTERM to the environment.
import os
os.environ['PWNLIB_NOTERM'] = 'True' # Configuration patch to allow pwntools to be run inside of an IDE
import pwn
Screenshot showing it runs and we get an Encoder object instance