You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
30
30
```
31
31
32
+
- Recent toolchains may emit **PAC/BTI** instrumentation by default on some ARM64 targets. If you are building a lab binary for practice, **`-mbranch-protection=none`** keeps the classic ret2lib flow reproducible.
33
+
- You can quickly verify whether the binary carries branch-protection notes with:
> If the target was compiled with return-address signing (`pac-ret` / `standard`) a naive overwrite of the saved **`x30`** may fail during the function epilogue. In real targets, confirm first whether PAC/BTI is present before assuming a vanilla ROP chain will work.
42
+
43
+
### AArch64 ROP reminders
44
+
45
+
-**`x0`** to **`x7`** hold the first 8 function arguments, so a ret2libc chain must place the pointer to **`/bin/sh`** in **`x0`** before branching to **`system`**.
46
+
-**`ret`** jumps to the address stored in **`x30`**. In practice, the saved return address is usually restored by an epilogue such as **`ldp x29, x30, [sp], #0x10; ret;`**.
47
+
- Keep **`sp` 16-byte aligned** at function boundaries. Misaligned stacks can crash in epilogues or inside libc before the chain reaches **`system`**.
48
+
- On AArch64, very useful gadgets often look like **`ldr x0, [sp, #imm]; ldp x29, x30, [sp], #off; ret;`** because they both set the first argument and advance the ROP chain.
49
+
32
50
### Find offset - x30 offset
33
51
34
52
Creating a pattern with **`pattern create 200`**, using it, and checking for the offset with **`pattern search $x30`** we can see that the offset is **`108`** (0x6c).
@@ -49,7 +67,7 @@ As the ASLR is disabled, the addresses are going to be always the same:
49
67
50
68
We need to have in **`x0`** the address to the string **`/bin/sh`** and call **`system`**.
@@ -144,6 +172,9 @@ Trying different offsets, the **`%21$p`** can leak a binary address (PIE bypass)
144
172
145
173
Subtracting the libc leaked address with the base address of libc, it's possible to see that the **offset** of the **leaked address from the base is `0x49c40`.**
146
174
175
+
> [!IMPORTANT]
176
+
> The exact format-string positions are **build-dependent**. The values **`%21$p`** and **`%25$p`** are valid for this binary/libc combination, but different compilers, optimization levels or libc versions can move the interesting pointers. On AArch64 this is especially visible because **`printf`** receives its first arguments in registers first, and only later consumes stack values. In a new target, brute-force several **`%p`** positions or inspect the state right before the **`printf`** call to re-discover the correct offsets.
177
+
147
178
### x30 offset
148
179
149
180
See the previous example as the bof is the same.
@@ -152,7 +183,7 @@ See the previous example as the bof is the same.
152
183
153
184
Like in the previous example, we need to have in **`x0`** the address to the string **`/bin/sh`** and call **`system`**.
154
185
155
-
Using rooper another interesting gadget was found:
186
+
Using ropper another interesting gadget was found:
-[ARM64 Reversing And Exploitation Part 7 – Bypassing ASLR and NX - 8kSec](https://8ksec.io/arm64-reversing-and-exploitation-part-7-bypassing-aslr-and-nx/)
0 commit comments