Buffer Overflow - Easy to understand primer
Every week, there are security vulnerabilities reported in widely deployed softwares. Many of these threats are buffer-overflow exploitation using which a malicious user could gain control of a computer system by crafting a special input data. These buffer overflows are found in web-browsers, web-servers and all other types of programs and services. No doubt, buffer overflow is a serious threat to system and data integrity.
Could someone please describe in simple terms what buffer overflow exactly means with some examples like the recent heapspray vulnerability and other recent exploits ?
Thanks in Advance.
286 views
Basic Process & Memory Information
Most modern systems can run multiple programs and perform multi-tasking. The operating system provide access points ( known as system calls ) to these programs to execute properly. Now these processes which are running on the system generally consist of :
An executing program is made up of three main memory areas :
Buffer overflows generally occur on the on the heap or the stack. But, since data on heap does not control information flow there is it rarely used in coding exploits.
Understanding Function Call & Memory Stack
I will try to explain what happens, when a function is called. Consider the code below for this example
void function (int a, int b, int c) {char buffer1[6];
char buffer2[20];
}
int main() {
function(1,2,3);
}
For easier follow up, i have broken the process into 11 steps :
So when you are on Step 6 , the stack looks like this ...
At last, What is Buffer Overflow ?
Now, consider a case where the function is expecting a string of max length of 100 characters but your pass a string parameter which is more than 100 characters(lets say 140 characters). In such a case, if not properly handled the system will try to push a 140character string on a 100character allocated buffer - hence, the extra characters will run past the buffer and overwrite the space allocated for EBP, EIP and so on. ( Not good )
This, in turn, will corrupt the process stack. So a properly crafted buffer overflow can overwrite a function's return address (EIP), which in turn can alter the program's execution path. EIP is the address of the next instruction in memory, which is executed immediately after the function returns.
Once a hacker can overwrite a function's return address, he will want to spawn a shell (with root permissions) by jumping the execution path to such code. But, lets say there is no such code in the buggy program which has root permissions then what ?
If thats the case, then the hacker would place the code he is trying to execute in the buffer's overflowing area. Then he has to overwrite the return address so it points back to the buffer and executes the intended code. Such code can be inserted into the program using environment variables or program input parameters.
Hope this helps...
Post new comment