I was trying to send a string to another application running on a server (which I do not have access to). The string includes null characters. Now I noticed that when I run the following code in a script,
print('abc\x00\x91\x11\x01123')
the output is: abc\x00\x91\x11123.
Athought when I run the same code in the terminal:
python -c 'print("abc\x00\x91\x11\x01123")'
I get as output: abc�123
Which is the desired output in my case. Why do both outputs differ? How do I get the second output when running the print function in a script?
EDIT: I figured out what was causing the difference. pwntools caused that behaviour. But I still can't really figure out why. The following code:
#!/usr/env/python
import pwn
print('abc\x00\x91\x11\x01123')
results in
abc\x00\x91\x11123
When I do not import pwn, the result is as expected: abc�123.
I hope this qualifies as answer in Stack Overflow standards.
If you play with grenade, treat is like grenade, not a toy. PWN tools seem to be some script-kiddies tools for exploitation. If you would read the first few paragraphs of the documentation, you would find the following:
As stated, we would also like to have the ability to get a lot of these side-effects by default. That is the purpose of this module. It does the following:
[...]Calls pwnlib.term.init() to put your terminal in raw mode and implements functionality to make it appear like it isn’t.
You have been warned, however you haven't RTFM. 😎