I have browsed the internet a lot and still could not understand the way it works
No success with this link either: How does a NOP sled work?
Okay, let's say we have a buffer char a[8];
in the function foo()
and the stack frame for foo()
looks like this (32-bit):
Now, what we want to do, is to overwrite 'return' value, saved on the stack when foo()
was called
They say that the problem is, we cannot predict the location of saved 'return' value
But why? For example, if function foo()
has the buffer defined prior to all other local variables, like in the picture above, then we always know that we need to fill 8 bytes allocated for buffer, then 4 bytes of saved EBP and then we got 'return'
Alternatively, if there are other local variables defined before the buffer, say 2 ints, then we consider 8 bytes allocated for buffer, then 8 bytes of those 2 local ints, then 4 bytes of saved EBP and then we got 'return'
We always know how far is the saved 'return' from our overflown buffer, don't we ? :/
If we don't, please explain. That's my question 1.
My question 2 is, okay, let's assume that we don't know where the value for 'return' is saved. Then if we have a large array of NOPs coming before the shellcode, we have a high chance of writing NOP (i.e. 0x90) value into location of 'return', hence overwriting the original value
Now, when the function foo()
returns, the value of 0x90 is loaded into EIP (instruction pointer) and instead of resuming its normal flow, the program is going to be executed from address 0x90, isn't it?
I think I've misunderstood something here
Please, don't close my question, even though there is a similar question that I've provided the link to, at the very beginning, I guess this question will be far more comprehensive and clearer