140 likes | 365 Views
What is a buffer overflow?. Memoryglobal staticheapmalloc( ) , newStacknon-static local variabledvalue parametersBuffer is a contiguously allocated chunk of memory Anytime we put more data into a data structure than it was designed for.. Side Effects. The side effects of a buffer overflow
E N D
1. <cstring> problems CS-240
Dick Steflik
2. What is a buffer overflow? Memory
global static
heap
malloc( ) , new
Stack
non-static local variabled
value parameters
Buffer is a contiguously allocated chunk of memory
Anytime we put more data into a data structure than it was designed for.
3. Side Effects The side effects of a buffer overflow may:
cause the program to work strangely
cause the program to fail
cause no noticeable problems.
the program may continue without any noticeable problems
4. Side Effects Depend on: How much data was written past the end of the buffer
What data (if any) are overwritten
Whether the program attempts to read data that are overwritten
What data ends up replacing the memory that gets overwritten
5. Three Basic Attacks Overrun a static buffer
hurts data but little to no exposure for loss of control
Stack smashing
place attack code in memory, find some sloppy use of the runtime stack, use stack to transfer control to attack code
Heap overflow
much harder to exploit as there isnt usually a mechanism to gain control
6. Defensive Programming The C Standard library has a number of highly susceptible function calls:
gets( ) - reads data from stdin until eof or a newline character
strcpy( ) - copies a string into a buffer, number of chars copied depend on length of source string
7. strcpy()
8. strcat( )
9. sprintf( ) & vsprintf( )
10. sprintf( ) & vsprintf( )
11. scanf( ), sscanf( ), fscanf( ), vfscanf( )
12. streadd( ) , strecpy( )
13. strtrns( )
14. functions to be wary of: