Search code examples
pythoncprintingstackexploit

Confused by a python -c printing command "\xef\xbe\xad\xde" what does it mean?


I am reading the "Hacker's Playbook 2" and was reading a bit about binary exploitation, and trying out an ssh game with some C code, and if you exploit these you get the password to the next level. However I was very confused by a python printing command used by the owner of the book hoping you guys would explain. Check it out:

the C code and requirements of the game

the confusing python printing statement

I tried to explain it the best I could by adding the two pictures, and as you can se the part which confuses me is: "\xef\xbe\xad\xde"

I hope I was clear, and thanks in return :)


Solution

  • In Python strings, you can specify characters by giving their ASCII, ISO Latin-1 or Unicode ordinal values in hexadecimal (base-16) notation. To do this, you include substrings of the form "\xHH" in your string, where HH is a number in hexadecimal. For instance, to include the carriage return (CR) and line feed (LF) characters in a string, you would write "My string\x0D\x0A". 0D in hexadecimal corresponds to 13 decimal, which is the ASCII code for a carriage return, and 0A corresponds to 10, which is a line feed.

    In this case, the book author is specifying the Latin-1 code points "\xEF" (hex EF = decimal 239), "\xBE" (190), "\xAD" (173) and "\xDE" (222). They are apparently chosen for comic value so that the result of his shenanigans can be shown as "DEADBEEF".