Buffer overflow - Copy
Buffer overflow - Copy
Heap-Based Overflows:
• Arise in dynamically allocated memory (malloc, calloc) where input can exceed
allocated space.
• Attackers can corrupt adjacent heap metadata, leading to arbitrary code execution or Crafting the Exploit Payload
manipulation of application behavior. Shellcode: Construct a payload that
executes desired commands (e.g.,
spawning a shell or escalating
privileges)..
Format String Vulnerabilities:
• Arise when user input is unsafely used in functions like printf, allowing attackers to
read memory and potentially write to arbitrary memory locations.
• This can lead to data leakage, arbitrary code execution, or control of the program's
flow
Overwriting the Return Address:
Overflow the buffer to overwrite the
Format String Vulnerabilities: saved return address on the stack,
redirecting execution to the shellcode or
• Arise when user input is unsafely used in functions like printf, allowing attackers to
a specific memory address.
read memory and potentially write to arbitrary memory locations.
• This can lead to data leakage, arbitrary code execution, or control of the program's
flow.
Basic Knowledge of gdb
Key Commands:
• run: Starts the program under gdb.
• break [function/line]: Sets breakpoints to pause execution.
• backtrace: Displays the call stack to see the flow of execution.
• info proc mappings: Shows memory layout for understanding buffer locations.
• print: Inspects variable values and memory addresses.
Key Features :
• Breakpoints: Pause execution at lines/functions to inspect variables and control flow.
• Stepping: Execute code line by line (step or next) to monitor behavior.
• Inspecting: Use print for variable values and x for memory examination.
• Backtrace: Use backtrace (or bt) to see function calls leading to the current point.
• Memory Mapping: Use info proc mappings to view memory layout and buffer
locations.
Buffer Overflow Vulnerability
Fuzzer loop with integrated G :
We Start with 1000 "A" characters to fill up space up to where we expect the overflow to
occur..
The output showed a segmentation fault with EIP set to 0x45454545, which
corresponds to EEEE in ASCII. This confirms our overflow successfully reached and
overwrote EIP, pinpointing where we control program execution.
Reverse shellcode
Bind
ESP Register
The ESP (Extended Stack Pointer) register points to the top of the stack in x86
architecture (32-bit systems), tracking the current stack location where temporary
data, such as local variables and return addresses, are stored. In buffer overflow
attacks, excess data can overwrite critical information, allowing attackers to control
program flow. NOP sleds help ensure that ESP lands on the malicious code.
EBP Register
The EBP (Base Pointer) register manages the stack frame of a function, keeping
track of local variables and function arguments. Buffer overflows can overwrite
EBP, enabling attackers to manipulate the stack frame and redirect execution flow
to an arbitrary memory address.
NOP Sled.
NOP sled is a sequence of NOP (No Operation) instructions in
memory, used in buffer overflow exploits to enhance the
chances of redirecting program execution to a target payload,
such as shellcode. The NOP instruction allows the CPU to skip
over it, making the sled a useful "landing zo
Why Use a NOP Sled?
• Margin of Error: In buffer overflows, targeting the exact
memory address of the payload can be difficult due to
variations in the environment (e.g., stack alignment, buffer
sizes).
• Landing Zone for EIP: Instead of aiming for the payload's
start, the EIP register is directed to the NOP sled. If EIP lands
within the sled, the CPU will execute NOPs until it reaches the
Finding the NOP sled in RAM
•Debugging and Testing: Locating the NOP sled aids in debugging, allowing attackers to
assess and refine the exploit's effectiveness.
•Increasing Success Rate: Knowing the sled's address increases the likelihood that the
EIP will land within it, facilitating successful payload execution.
We use the identified address of the NOP sled to adjust the exploit code, ensuring
that the EIP register points to this address. This increases the likelihood of landing in
the NOP sled during the exploit.
After obtaining the address of the NOP sled, we set a breakpoint at that location and
execute the shellcode. Subsequently, we use GDB to examine the register values with the
info registers command to verify the state of the registers during execution
Completing The Exploit Code & Reverse Shell
Connection on Other VM
Thank You