FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Stack_buffer_overflow

Stack buffer overflow

Contents
Platform-related differences
    Stacks that grow up
    Stack canaries

In software, a stack buffer overflow or stack buffer overrun occurs when a program writes to a memory address on the program's call stack outside of the intended data structure, which is usually a fixed-length buffer. Stack buffer overflow bugs are caused when a program writes more data to a buffer located on the stack than what is actually allocated for that buffer. This almost always results in corruption of adjacent data on the stack, and in cases where the overflow was triggered by mistake, will often cause the program to crash or operate incorrectly. Stack buffer overflow is a type of the more general programming malfunction known as buffer overflow (or buffer overrun). Overfilling a buffer on the stack is more likely to derail program execution than overfilling a buffer on the heap because the stack contains the return addresses for all active function calls.

A stack buffer overflow can be caused deliberately as part of an attack known as stack smashing. If the affected program is running with special privileges, or accepts data from untrusted network hosts (e.g. a webserver) then the bug is a potential security vulnerability. If the stack buffer is filled with data supplied from an untrusted user then that user can corrupt the stack in such a way as to inject executable code into the running program and take control of the process. This is one of the oldest and more reliable methods for attackers to gain unauthorized access to a computer.

#include<stdio.h> #include<string.h> voidfoo(char*bar){ floatmyFloat=10.5;// Addr = 0x0023FF4C charc[28];// Addr = 0x0023FF30 // Will print 10.500000 printf("myFloat value = %f\n",myFloat); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Memory map: @ : c allocated memory # : myFloat allocated memory *c *myFloat 0x0023FF30 0x0023FF4C | | @@@@@@@@@@@@@@@@@@@@@@@@@@@@##### foo("my string is too long !!!!! XXXXX"); memcpy will put 0x1010C042 (little endian) in myFloat value. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ memcpy(c,bar,strlen(bar));// no bounds checking... // Will print 96.031372 printf("myFloat value = %f\n",myFloat); } intmain(intargc,char*argv[]){ foo("my string is too long !!!!! \x10\x10\xc0\x42"); return0; }

There are typically two methods that are used to alter the stored address in the stack - direct and indirect. Attackers started developing indirect attacks, which have fewer dependencies, in order to bypass protection measures that were made to reduce direct attacks.

Platform-related differences

edit

A number of platforms have subtle differences in their implementation of the call stack that can affect the way a stack buffer overflow exploit will work. Some machine architectures store the top-level return address of the call stack in a register. This means that any overwritten return address will not be used until a later unwinding of the call stack. Another example of a machine-specific detail that can affect the choice of exploitation techniques is the fact that most RISC-style machine architectures will not allow unaligned access to memory. Combined with a fixed length for machine opcodes, this machine limitation can make the technique of jumping to the stack almost impossible to implement (with the one exception being when the program actually contains the unlikely code to explicitly jump to the stack register).

Stacks that grow up

edit

Within the topic of stack buffer overflows, an often-discussed-but-rarely-seen architecture is one in which the stack grows in the opposite direction. This change in architecture is frequently suggested as a solution to the stack buffer overflow problem because any overflow of a stack buffer that occurs within the same stack frame cannot overwrite the return pointer. However, any overflow that occurs in a buffer from a previous stack frame will still overwrite a return pointer and allow for malicious exploitation of the bug. For instance, in the example above, the return pointer for foo will not be overwritten because the overflow actually occurs within the stack frame for memcpy. However, because the buffer that overflows during the call to memcpy resides in a previous stack frame, the return pointer for memcpy will have a numerically higher memory address than the buffer. This means that instead of the return pointer for foo being overwritten, the return pointer for memcpy will be overwritten. At most, this means that growing the stack in the opposite direction will change some details of how stack buffer overflows are exploitable, but it will not reduce significantly the number of exploitable bugs.

Over the years, a number of control-flow integrity schemes have been developed to inhibit malicious stack buffer overflow exploitation. These may usually be classified into three categories:

Stack canaries

edit
  1. 1 2 Fithen, William L.; Seacord, Robert (2007-03-27). "VT-MB. Violation of Memory Bounds". US CERT.
  2. 1 2 3 Pincus, J.; Baker, B. (July–August 2004). "Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns" (PDF). IEEE Security & Privacy. 2 (4): 20–27. Bibcode:2004ISPri...2d..20P. doi:10.1109/MSP.2004.36. S2CID 6647392.
  3. ↑ "},"title":{"wt":"Stack Overflows"},"url":{"wt":"http://www.securityforest.com/downloads/educationtree/stack_overflows.pdf"},"url-status":{"wt":"dead"},"archive-url":{"wt":"https://web.archive.org/web/20070928100343/http://www.securityforest.com/downloads/educationtree/stack_overflows.pdf"},"archive-date":{"wt":"September 28, 2007"}},"i":0}}]}'/>Burebista. "Stack Overflows" (PDF). Archived from the original (PDF) on September 28, 2007.
  4. ↑ pr1. "Exploiting SPARC Buffer Overflow vulnerabilities".{{cite web}}: CS1 maint: numeric names: authors list (link)
  5. ↑ Nergal (2001-12-28). "The advanced return-into-lib(c) exploits: PaX case study". Phrack. 11 (58): 4.
  6. ↑ Butt, Muhammad Arif; Ajmal, Zarafshan; Khan, Zafar Iqbal; Idrees, Muhammad; Javed, Yasir (January 2022). "An In-Depth Survey of Bypassing Buffer Overflow Mitigation Techniques". Applied Sciences. 12 (26): 6702. doi:10.3390/app12136702. ISSN 2076-3417.
  7. 1 2 Butt, Muhammad Arif; Ajmal, Zarafshan; Khan, Zafar Iqbal; Idrees, Muhammad; Javed, Yasir (January 2022). "An In-Depth Survey of Bypassing Buffer Overflow Mitigation Techniques". Applied Sciences. 12 (16): 6702. doi:10.3390/app12136702. ISSN 2076-3417.
  8. ↑ "Twilight Hack - WiiBrew". wiibrew.org. Retrieved 2018-01-18.
  9. ↑

View original on Wikipedia | Back | FazBrowse Home