

The address of the next instruction after the called function returns.Arguments to the called function (in reverse order).This data is pushed onto the stack in the following order: When a function is called by another function, information is pushed onto the stack to provide that function with the data that it needs to execute. As data is added to or removed from the stack, the stack pointer is updated as well.Īs shown in the image above, the stack contains several different types of variables. The current position in the stack is indicated by a variable (the stack pointer) that points to the current top of the stack. The stack grows “down” from high memory addresses to lower ones. Both the stack and the heap can be exploited by a buffer overflow attack, but the structure of the stack makes it extremely susceptible.Īs its name suggests, the stack is organized as a stack of memory. The stack is commonly used for function arguments and local variables, and the heap stores dynamic memory (allocated using the new command in C++).
#Buffer overflow attack on website code#
However, the structure of the stack means that a well-designed buffer overflow exploit can do much more, allowing an attacker to control execution flow and run malicious code on the system.Īn application can allocate memory on the stack or on the heap. Overflowing a buffer with meaningless or random input is likely to just cause a segmentation fault or an error in the program. This vulnerability can be exploited by a hacker simply by providing more input to the application than the allocated buffer is capable of holding. If a program incorrectly allocates memory for user input or insecurely reads data into that memory space, a buffer overflow vulnerability exists. Due to the structure of how memory is allocated within a computer, this can be extremely useful to an attacker since it allows them to control the execution of the program.Įxploitation of a buffer overflow vulnerability is fairly simple. Regardless of the reason, if an application tries to write to memory beyond the range of its allocated buffer, this means that it is writing to the memory allocated for other purposes within the application. Input lengths that cause an integer overflow.

