Ch03.4.3-Buffer Overflow Attack
Ch03.4.3-Buffer Overflow Attack
Ch03.4.3-Buffer Overflow Attack
● Stack
○ Stores arguments data of function call
○ Stores local variables of function
○ Stores return address of the parent
function
○ By default non-executable
Program Memory Layout
Stack and Function Invocation
Stack and Function Invocation
Stack and Function Invocation
Buffer Overflow
Other vulnerable functions like gets() which copy user input without checking its length.
Buffer Overflow
Buffer Overflow Attack
● Second, the address may be mapped to a physical address, but the address space is
protected, such as those used by the operating system kernel; the jump will fail, and the
program will crash.
● Third, the address may be mapped to a physical address, but the data in that address is not
a valid machine instruction (e.g. it may be a data region); the return will again fail and the
program will crash.
● Fourth, the data in the address may happen to be a valid machine instruction, so the program
will continue running, but the logic of the program will be different from the original one.
Buffer Overflow : NOP Sledding
Conducting Buffer Overflow
Attack With Unknown Buffer Size
Goal of Buffer-Overflow Attack
● Our goal is to exploit the buffer
overflow vulnerability in the
vulnerable program stack.c,
○ which runs with the root privilege.
Steps:
● Fill the content with NOPs
● Put the shellcode at the end
● Put the address at an offset
● Write the content to a file
Solution/Measures to avoid the attack
The safer strncpy() function should be used, instead of strcpy()