I need to write 4 raw hex bytes to bash by using a Python 2.7 script. I've bumped into this thread that seemed promising: How to write a raw hex byte to stdout in Python 3? - but it only applied to Python 3. What's the equivalent of that method in Python 2.7?
Asked
Active
Viewed 447 times
1 Answers
0
You can use binascii.unhexlify:
import sys
from binascii import unhexlify as unhex
# Prints out the character 'N'
sys.stdout.write(unhex('4e'))
# ...
# Prints out Hello, world!
sys.stdout.write(''.join(map(unhex, [
'48', '65', '6c',
'6c', '6f', '2c',
'20', '77', '6f',
'72', '6c', '64',
'21'
])))

Matias Cicero
- 25,439
- 13
- 82
- 154
-
Yeah but this way I still print the characters in a Unicode string, I need to directly write the bytes without encoding..is that even possible? What I'm ultimately aiming to do is overwriting a 4 bytes canary via buffer overflow. – droidzero May 24 '18 at 12:51