Binary Exploitation with Buffer Overflow
Buffer overflow occurs when a program attempts to write more data to a buffer, or temporary data storage area, than it can hold. This can result in overwriting adjacent memory locations, potentially c
Investigation
Functions Lead to Buffer Overflow
If the binary uses the following functions, Buffer Overflow may occurs.
Basic Buffer Overflow
Try to find what values lead to segmentation fault.
Exploitation
Abuse input/output by typing a lot of characters more than the program expects..
Exploitation using Pwntools
Overriding Variables
The program executes input/output by gets() or scanf(), and limit the buffer size of the variable, we can modify the variable then lead to unexpected behavior. For instance, assume the program is as follow.
First find the distance from the stack pointer to rbp-0x4 (0x04).
Exploitation using Pwntools
Overriding the Next Call
If the program uses get() or scanf(), we can specify the address of the desired calls by overwriting the address. Assume the program has the above two functions.
For instance, if we want to call the “vuln_fn” function, override the address of the next call using buffer overflow.
Exploitation 1
Exploitation 2
Shellcode
We can create the crafted shell code and override the address to execute the shell code. Use Pwntools to create the shell code.
Integer Overflow
If the program processes integer values with input/output, we can abuse it by overflow of integer. The range of 32-bit integer is -2147483647 to 2147483647, so if we type the max value +1 in input for instance, the result is -1. This is because
Last updated