1

I want to know how to format a string as raw bytes in python3 just like it was in python2.

To clarify my Question, I have to following shellcode:

x = b"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x62\x61\x73\x68\x68\x62\x69\x6e\x2f\x68\x2f\x2f\x2f\x2f\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80"

and I want to pass this code to radare2 in python.

r.cmd("doo %s"%x)

Now is there a way that python passes my code as "real" bytes not as Unicode? I know it is possible to print it with

 sys.stdout.buffer.write(x)

but I want to pass it to the programm. Right now I am getting c290 not just 90. Why is the output of print in python2 and python3 different with the same string? has already explained this behavior but it does not give a solution for my problem

Thank you

  • 1
    Hey Benedict, checkout my answer to a similar question here: https://stackoverflow.com/a/59649426/12378826 The OP in that case asking about hex input, but you should consider using the `-e` flag with your `doo` command and using a hex string with additional escape characters instead of raw bytes. – Kuma Jun 03 '20 at 16:02

0 Answers0