0xRyN
0xRyN

Reputation: 872

Python print bytes

I'm using a python3 program for binary exploitation, but it's not printing bytes correctly.

My program :

import struct

padding = b"AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRRSSSSTTTTUUUUVVVVWWWWXXXXYYYYZZZZ"
ret = struct.pack("I", 0x55619d84)
payload = b"\xCC"
print (padding+ret+payload, sep="", end="")

but hexdump gives me this

00000000  62 27 41 41 41 41 42 42  42 42 43 43 43 43 44 44  |b'AAAABBBBCCCCDD|
00000010  44 44 45 45 45 45 46 46  46 46 47 47 47 47 48 48  |DDEEEEFFFFGGGGHH|
00000020  48 48 49 49 49 49 4a 4a  4a 4a 4b 4b 4b 4b 4c 4c  |HHIIIIJJJJKKKKLL|
00000030  4c 4c 4d 4d 4d 4d 4e 4e  4e 4e 4f 4f 4f 4f 50 50  |LLMMMMNNNNOOOOPP|
00000040  50 50 51 51 51 51 52 52  52 52 53 53 53 53 54 54  |PPQQQQRRRRSSSSTT|
00000050  54 54 55 55 55 55 56 56  56 56 57 57 57 57 58 58  |TTUUUUVVVVWWWWXX|
00000060  58 58 59 59 59 59 5a 5a  5a 5a 5c 78 38 34 5c 78  |XXYYYYZZZZ\x84\x|
00000070  39 64 61 55 5c 78 63 63  27                       |9daU\xcc'|
00000079

As you can see, it's not encoded properly. Starts with b ', address is not properly encoded etc...

What's wrong with my code ? Thank you

Upvotes: 0

Views: 1169

Answers (1)

0xRyN
0xRyN

Reputation: 872

Solved. Had to use sys.stdout.buffer.write(x) instead of print(x). Thank you @ChrisB

Upvotes: 1

Related Questions