pwntools
pwntools copied to clipboard
Promote some functions from six to top-level, for ease of multi-Python exploit development
In order to ease the process of writing exploits that work on both Python2 and Python3, we should promote some functions from six
to the toplevel so they come in with from pwn import *
.
Here's a few candidates:
six.ensure_binary
as b
six.ensure_text
or ensure_str
as s
We should also probably run ensure_text
on anything passed as the first argument to a logger statement, like log.info
and friends.
This cuts down on the number of .encode()
and .decode()
calls, particularly when converting from a Python3 bytes
object to a printable string.
We should also probably apply ensure_binary
to all of the tubes
routines / return values as appropriate (and ensure_text
to the e.g. recvS
variants).
I seriously discourage using python 2 in anything new, unless it really really has to be python 2. Most people should be able to just develop their exploits in at least python 3.5+. The only reason I see for using python 2 over 3 is some ancient libraries that did not get ported (most notable is Jython, which I am upset that sticks to 2.7 and still lacks many __future__
features — it has a py3 port), and that's why I was in favor of supporting python 2 when I ported pwntools to py3.
I do it just to make sure the code base still works on Python2 and Python3 for testing purposes. Generally I write exploits in Py3 and then try to make them work in Py2.
In any case, the b
and s
routines as suggested here are mostly to make Python3 development easier and remove the .encode()
and .decode()
madness.