It appears that a common exploit trick is to use stack overflow to overwrite the instruction pointer such that it points to a jmp esp
instruction somewhere in the code segment which then executes the arbitrary code of the attacker's choice.
However, I have a hard time understanding what use legitimate programs (which to my understanding are usually not self-modifying and have all of their executable code stored in the code segment) would have in including such jmp esp
instructions in the first place.
jmp esp
is encoded asFF E4
. You don’t need to find an existingjmp
, you just need to find these bytes in the middle of any other instruction. This is the basis for a lot of exploit techniques, notably return oriented programming (ROP).