RE: Why does buffer overflow work one way but not the other? 10-04-2015, 06:16 PM
#4
This is actually pretty simple.
When you do it by printing the values using the Python interpreter, note that some of it is binary - unprintable characters. In this instance, what is being printed out and passed to the program is binary-data. This is handled as an invalid memory address pointing to 0xdeadbeef when it overwrites the register.
Now, when you just paste in the characters, you are passing it the invalid memory address not as binary, but as a set of ASCII characters, and it doesn't see it as an address pointing to 0xdeadbeef, it sees it as whatever the fuck else.
This is binary exploitation 101, yo. Learn how different data types are treated differently and you will succeed.
Bonus round: you can do this with echo as well.
Enjoy learning.
When you do it by printing the values using the Python interpreter, note that some of it is binary - unprintable characters. In this instance, what is being printed out and passed to the program is binary-data. This is handled as an invalid memory address pointing to 0xdeadbeef when it overwrites the register.
Code:
$ python -c 'print "A"*20 + "\xef\xeb\xad\xde"'
AAAAAAAAAAAAAAAAAAAA���Now, when you just paste in the characters, you are passing it the invalid memory address not as binary, but as a set of ASCII characters, and it doesn't see it as an address pointing to 0xdeadbeef, it sees it as whatever the fuck else.
This is binary exploitation 101, yo. Learn how different data types are treated differently and you will succeed.
Bonus round: you can do this with echo as well.
Code:
$ echo -ne 'AAAAAAAAAAAAAAAAAAAA\xef\xeb\xad\xde'
AAAAAAAAAAAAAAAAAAAA���Enjoy learning.


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)