Thanks for your answer,
WormKill.
Hmm, seems a bit weird, cause in the book I'm reading, the RIP was overwritten with a fixed address of another function, to control the execution-flow of another example-program, but probably the stack-size varies more with a complex program, and therefore you should always avoid the use of hardcoded addresses.
To that JMP/Call-trick:
Considering the following situation (c&p from Smashing the Stack..., pastebin is more readable):
http://pastebin.com/dQpcgrwfAssuming the stack starts at address 0xFF, and that S
stands for the code we want to execute the stack would then look like this:
bottom of DDDDDDDDEEEEEEEEEEEE EEEE FFFF FFFF FFFF FFFF top of
memory 89ABCDEF0123456789AB CDEF 0123 4567 89AB CDEF memory
buffer sfp ret a b c
<------ [SSSSSSSSSSSSSSSSSSSS][SSSS][0xD8][0x01][0x02][0x03]
^ |
|____________________________|
top of bottom of
stack stack
That's how I'd have done it before I got to know that the stack-size can vary.
The following is how it
is done correctlyhttp://pastebin.com/VxUE7vbuThe CALL instruction can simply call the
start of our code above. Assuming now that J stands for the JMP instruction,
C for the CALL instruction, and s for the string, the execution flow would
now be:
bottom of DDDDDDDDEEEEEEEEEEEE EEEE FFFF FFFF FFFF FFFF top of
memory 89ABCDEF0123456789AB CDEF 0123 4567 89AB CDEF memory
buffer sfp ret a b c
<------ [JJSSSSSSSSSSSSSSCCss][ssss][0xD8][0x01][0x02][0x03]
^|^ ^| |
|||_____________||____________| (1)
(2) ||_____________||
|______________| (3)
top of bottom of
stack stack
How you can see, the return address (or RIP, that's how it's called in my book), still contains the
absolute address of the buffer's first element. So that JMP/CALL instructions are useless.