text stringlengths 0 1.99k |
|---|
0x0012d417 : pop edi ; pop ebp ; ret |
Adding the difference between the two pairs of gadgets to the qaddress |
allows the qgadgets to be chained. |
libc 0xf0000000 | libc 0xf0008000 |
+--------------+ | +--------------+ |
qaddress --> | 0xf019d063 |---+ | qaddress --> | 0xf019d063 |---+ |
+--------------+ | | +--------------+ | |
+---| 0xf012d417 |---+ | +---| 0xf012d417 |---+ |
| +--------------+ | | +--------------+ |
| | .......... | | | | .......... | |
| +--------------+ | | +--------------+ |
| | .......... | | +---| stackpivot | |
| +--------------+ | +--------------+ |
+---| stackpivot | | | .......... | |
+--------------+ | +--------------+ |
Here, stackpivot is an add/sub esp gadget which can already assume one |
deterministic libc address, and jump to its corresponding ROP chain in the |
stack. In each case, the addresses are the same, but the gadgets differ, |
which makes them distinguishable. |
Now, when collisions are not a problem anymore, I estimate that even 16 |
qgadgets are possible, making 8 bits of randomization effectively 4 bits! |
This is a huge deal. ASLR is not as effective as we used to think. |
5 More randomized bits, more potential qgadgets |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Let us examine the case where more bits are randomized, and how that affects |
the exploit. |
In the case of 8 bits of randomization, where libraries are loaded aligned |
to page size, we have (2 ^ 8) * 0x1000 = 0x100000 = 1MB randomization range. |
This means that any randomized executable range of 1MB is effectively a |
candidate in which we can search for qgadgets. |
Since libc is around 2MB nowadays, imported in every ELF, and contains |
plenty of gadgets, it's the most natural choice for implementing such |
a technique. But technically any other library would work as well. |
If there were for example, 9-bits of randomization, it would have two major |
effects on the probability of hitting a quantum gadget. |
1. Every additional bit of randomization makes it twice as hard to hit |
the same amount of quantum gadgets. For example, 5 gadgets with |
8-bits of randomization are the same as 10 gadgets with 9-bits. |
2. The randomization range increases to 2MB, which allows us to look for |
gadgets in a larger range. We can use gadgets from libc, and from the |
library loaded right before/after libc, for example. This doubles |
the range in which we can search for gadgets. But it does not mean |
that we are likely to find a group of quantum gadgets double in size. |
Further exploring the natural behavior of such a problem, it can actually |
be shown that the first effect will always cut the chances by two, and the |
second is upper-bounded to double the chances, therefore upper-bounded |
to balance out. |
We can turn this problem into a probability problem: |
K - chunk size (page size) |
N - number of chunks in bits (bits of randomization) |
P - the probability of an address being a usable quantum gadget |
A - An array of 2^N arrays, each of size K, where A[i,j] has P probability |
to be 1 and 1-P probability to be 0. i being chunk index, j being offset |
The question would be what is the expected value of the maximum sum of |
A[0,j] + A[1,j] + ... A[2^N,j] for every possible j. These sums follow a |
binomial distribution, and their expected maximum value can be calculated |
using the CDF method. |
Substituting K = 0x1000, N = 8, and P = 0.025 it is possible to get a good |
approximation of how the expected maximum grows as N increases. |
I chose P to be the ratio between the number of gadgets found in my libc and |
the number of valid executable addresses in libc, roughly halving the result |
to account for many unusable gadgets. |
+----+--------------------+--------------------+ |
| N | Approx. QGadgets | Hit chances | |
+----+--------------------+--------------------+ |
| 8 | 17.159036642229488 | 0.0670274868837089 | |
+----+--------------------+--------------------+ |
| 9 | 27.368423952770550 | 0.0534539530327549 | |
+----+--------------------+--------------------+ |
| 10 | 45.520201172796410 | 0.0444533214578089 | |
+----+--------------------+--------------------+ |
| 11 | 78.659547111384850 | 0.0384079819879808 | |
+----+--------------------+--------------------+ |
| 12 | 140.49855876896643 | 0.0343014059494546 | |
+----+--------------------+--------------------+ |
NOTE: I'm not a mathematician, take these values with a grain of salt. |
Here is the extremely rough estimation I was able to produce. |
Note that the hit chances without using QROP, with 8 bits of randomization, |
is 1/256 = 0.00390625. This means that with QROP, even going up to 11 bits |
of randomization, it can still be ten times more efficient than 8 bits. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.