Ret2lib + Printf leak - arm64
Ret2lib - 通过ROP绕过NX(无ASLR)
#include <stdio.h>
void bof()
{
char buf[100];
printf("\nbof>\n");
fgets(buf, sizeof(buf)*3, stdin);
}
void main()
{
printfleak();
bof();
}编译时不使用canary:
寻找偏移量
x30 偏移量
使用 pattern create 200 创建模式,使用它,并使用 pattern search $x30 检查偏移量,我们可以看到偏移量为 108 (0x6c)。

查看反汇编的主函数,我们可以看到我们希望跳转到直接跳转到 printf 的指令,其偏移量从二进制文件加载的位置为 0x860:

寻找 system 和 /bin/sh 字符串
/bin/sh 字符串由于 ASLR 已禁用,地址将始终相同:

寻找 Gadgets
我们需要在 x0 中有指向字符串 /bin/sh 的地址并调用 system。
使用 rooper 找到了一个有趣的 gadget:
攻击
这个工具将从**$sp + 0x18加载x0,然后从sp加载地址x29和x30,最后跳转到x30。因此,利用这个工具,我们可以控制第一个参数,然后跳转到system**。
Ret2lib - 利用从栈中泄漏的printf绕过NX、ASLR和PIE
编译无 Canary:
PIE and ASLR but no canary
Round 1:
Leak of PIE from stack
Abuse bof to go back to main
Round 2:
Leak of libc from the stack
ROP: ret2system
Printf leaks
Setting a breakpoint before calling printf it's possible to see that there are addresses to return to the binary in the stack and also libc addresses:

Trying different offsets, the %21$p can leak a binary address (PIE bypass) and %25$p can leak a libc address:

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.
x30 offset
See the previous example as the bof is the same.
Find Gadgets
Like in the previous example, we need to have in x0 the address to the string /bin/sh and call system.
Using rooper another interesting gadget was found:
这个工具将从**$sp + 0x78加载x0,然后从sp加载地址x29和x30,最后跳转到x30。因此,利用这个工具,我们可以控制第一个参数,然后跳转到system**。
攻击Exploit
最后更新于