text stringlengths 0 1.99k |
|---|
code located within the stack, the vulnerable function should return into a |
memory area occupied by a dynamic library. This can be achieved by |
overflowing a stack buffer with the following payload: |
<- stack grows this way |
addresses grow this way -> |
+------------------------------------------------------------------+ |
| buffer fill-up(*)| function_in_lib | dummy_int32 | arg_1 | arg_2 | ... |
+------------------------------------------------------------------+ |
^ |
| |
+ this int32 should overwrite saved return address |
of a vulnerable function |
(*) buffer fill-up should overwrite the saved %ebp as well, if it is used. |
When the function containing the overflown buffer returns, the |
execution will resume at function_in_lib, which should be the address of a |
library function. From this function's point of view, dummy_int32 will be |
the return address, and arg_1, arg_2 and the following words will be the |
arguments. Typically, function_in_lib will be the libc system() function |
address, and arg_1 will point to "/bin/sh". |
2 The difficulty with overcoming ASLR (And PIE) |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This section is heavily based on [1]. |
ASLR and PIE are two security mitigations that randomize a process' memory |
layout. Without these, exploiting a BOF using ROP is rather easy since |
gadget addresses are deterministic. With ASLR and PIE present, brute forcing |
the libc base address is the trivial way to bypass these mitigations. |
In 32-bit the default randomization bits are 8 bits (not always), which |
gives 256 options for the libc base address, making it fairly possible to |
brute force. While in 64-bit the default value is 28-bit, which makes it |
exponentially harder to brute force. |
In local exploits, failed attempts will probably cause a SEGFAULT, and |
continuous attempts are possible. However, in remote exploits, there are |
many variables that affect the duration of each attempt. For example, |
network speed, watchdog configuration, program state and exploitation |
complexity. These occasionally make exploitation nontrivial or infeasible, |
because of the time it takes to reach a reliable exploitation chance |
(which we will further examine later). |
There are other known ways to overcome ASLR without having to brute force. |
Information leaks are commonly used to defeat ASLR. For example, local |
attackers have often been able to leak information from /proc/<pid> to |
bypass ASLR [6]. |
In the following chapter I will describe a new method to dramatically |
reduce exploitation time for brute force attacks. |
3 Quantum ROP |
~~~~~~~~~~~~~~~ |
For the purpose of this chapter we will be using this C code: |
#include <stdlib.h> |
#include <stdio.h> |
void foo() { |
char bar[10] = {0}; |
printf("%s", gets(bar)); |
} |
int main() { |
foo(); |
return 0; |
} |
compile command: |
gcc -m32 -fno-stack-protector foo.c -o foo |
A normal ret-to-libc exploit would look like this: |
Overflowing the buffer and changing the return address into our ret-to-libc |
gadget, turning this: |
+----------------------------------------+ |
| buffer | some data | ret addr | |
+----------------------------------------+ |
into this: |
+----------------------------------------+ |
| AAAAAAAAAA | AAAAAAAAAAAA | libc addr | |
+----------------------------------------+ |
And using good old ROP to execute arbitrary code. |
But since the libc base address is randomized - thanks to ASLR - we are |
forced to guess the libc address and exploit until libc happens to land |
exactly where we guessed. Let's speed things up. |
First, let's look for ROP gadgets. I used ROPgadget by Jonathan Salwan to |
find a solid set of useful gadgets from our libc file. Using the libc |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.