r/HowToHack • u/OwlSad7532 • Mar 05 '26
How does a buffer overflow work
Ye ive been struggling with this for a while so can someone pls explain it to me in a simple manner
7
Upvotes
r/HowToHack • u/OwlSad7532 • Mar 05 '26
Ye ive been struggling with this for a while so can someone pls explain it to me in a simple manner
View all comments
8
u/cant_pass_CAPTCHA Mar 05 '26
How much do you understand memory? It's kind of important so I'll lay it out in case you aren't clear.
So the way a program works you have a section of memory called "the stack". There is a register (like a variable in cache) called the "instruction pointer", this is a way for the computer to keep track of the current location and so it can advance to the next instruction to be executed. When you call a new function, a "return pointer" is added to the stack. This is like a bookmark in memory to return to after completing a function call. When you call a function, parameters are passed to the function by being placed on the stack. If too much information is added to the stack which is uncountered for, it can overwrite the return pointer. When the program wants to return it's normal execution after a function call, it will take the return pointer off of the stack and replace the current instruction pointer with that value. However, during a buffer overflow we have written data which has replaced the return pointer with a memory location of our choosing. The computer will jump to that memory location and resume what it expects to be normal execution. The classic way this gives us control of execution is by writing our own instructions which does whatever we want.
So to break it down: