text stringlengths 0 1.99k |
|---|
Let's update our payload. We have two ROP gadgets: |
1. 0x0015b456 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret |
2. 0x0015c456 : ret |
the ROP chain if second gadget is hit ----+ |
| |
the program return address --+ | |
V V |
+--------------------------------------------------------------------------+ |
| 0x41414141 | .......... | 0xf015c456 | 0xDEAD | 0xDEAD | 0xDEAD | 0xDEAD | |
|--------------------------------------------------------------------------| |
| 0xBEEF | 0xBEEF | 0xBEEF | 0xBEEF | .......... | .......... | .......... | |
+--------------------------------------------------------------------------+ |
^ |
| |
+ The ROP chain if first gadget is triggered |
Now, let's see what happens when the second gadget is triggered. Since the |
second gadget is just a ret, it immediately transfers control to the first |
0xDEAD - the start of the next ROP in our chain. If this happens, we know |
that libc is mapped at 0xf0000000. |
stack pointer after the second gadget-----+ |
V |
+--------------------------------------------------------------------------+ |
| 0x41414141 | .......... | 0xf015c456 | 0xDEAD | 0xDEAD | 0xDEAD | 0xDEAD | |
|--------------------------------------------------------------------------| |
| 0xBEEF | 0xBEEF | 0xBEEF | 0xBEEF | .......... | .......... | .......... | |
+--------------------------------------------------------------------------+ |
Now, if instead the first ROP gadget is executed then the stack will look |
as follows: |
+--------------------------------------------------------------------------+ |
| 0x41414141 | .......... | 0xf015c456 | 0xDEAD | 0xDEAD | 0xDEAD | 0xDEAD | |
|--------------------------------------------------------------------------| |
| 0xBEEF | 0xBEEF | 0xBEEF | 0xBEEF | .......... | .......... | .......... | |
+--------------------------------------------------------------------------+ |
^ |
| |
+ stack pointer after the first gadget |
This time, because the gadget does four pops before returning, the return |
lands somewhere deeper in the payload - in our case, on the first 0xBEEF. |
Since this only happens if libc was mapped at 0xf0001000, we have just |
confirmed the base address. In either case, we can continue the ROP chain |
with the corresponding libc base address. |
Quantum ROP offers a simple yet powerful way to boost the success rate of |
ret-to-libc attacks under ASLR. By carefully selecting two ROP gadgets |
spaced X-pages apart in libc, we effectively create a dual-path exploit. |
One gadget triggers if our initial guess is correct, and the other triggers |
if it is off by their difference. This method multiplies our chances for |
success with a constant payload - and thanks to the subtle difference in |
stack adjustments between gadgets, we can detect which one executed and |
deduce the actual libc base address in each corresponding exploit. |
Let's call each of these gadgets a qgadget, as they serve the purpose of |
potentially existing at the same address, but only one may exist at this |
address when you actually run the program. We shall also name the actual |
guessed address in the return address as qaddress, for obvious reasons. |
The method does not stop here: this technique isn't limited to just two |
qgadgets. By adding more qgadgets that share the same offset within their |
page, we can stack multiple fallback paths into the same payload, increasing |
our odds of success per attempt. It is likely to be able to produce a |
payload abusing not only two, but eight gadgets, reducing the 8 bits of ASLR |
to effectively 5 bits. |
In our example, we carefully chose the qgadgets that fit perfectly. Using |
one_gadget [3], we were able to produce a working four-gadget-long exploit |
that fit exactly with our chosen qgadgets. For cases where you require |
longer ROP chains, you can resolve this by using an add/sub esp |
gadget, allowing you to create more space for each ROP chain and continue |
the chain elsewhere. |
4 Qgadget collisions - going further and beyond |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Until now, I only showed how to make it work when qgadgets differ in the |
amount by which they move the stack pointer. Now what if I found three |
gadgets, but two of them move the stack pointer by the exact same amount? |
Am I forced to give up on one of them? |
Well, using the same technique as before, we can distinguish between the |
two gadgets. Let us assume that the two gadgets are simple "ret" gadgets. |
This means that the next pointer after the return address is the next |
gadget executed. Consider this real example from my libc: |
0x00194063 : pop ebp ; ret |
0x00195063 : ret |
0x0019d063 : ret |
The first gadget's stack shift is unique, but the next two are the same. |
We can observe that the difference between the two identical qgadgets is 8 |
pages. Now, if we find two gadgets of the same difference that move the |
stack pointer by a different amount, we can split those two cases: |
0x00125417 : pop ebp ; ret |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.