๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿฆพ ๋ณด์•ˆ ๐Ÿฆพ/๋ฆฌ๋ฒ„์‹ฑ

[๋ฆฌ๋ฒ„์‹ฑ] kali - pwndbg ์„ธํŒ… & ๊ธฐ๋ณธ ๋ช…๋ น์–ด

๋ฐ˜์‘ํ˜•

 

ELF๋ถ„์„์„ ์œ„ํ•ด์„œ kali์— gdb ํ™˜๊ฒฝ์„ ์„ธํŒ…ํ•˜๊ณ  pwndbg ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•˜๊ณ ์ž ํ•œ๋‹ค.

ํ™˜๊ฒฝ ์„ธํŒ…

๋ชจ๋‘ ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์ด ์žˆ๋Š” ์ƒํƒœ์—์„œ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค. ๊ถŒํ•œ ์—†์ด ์‹คํ–‰ํ–ˆ๋‹ค๊ฐ€ pwndbg ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ๋™์ž‘ํ•˜์ง€ ์•Š์•„์„œ ์• ๋ฅผ ๋จน์—ˆ๋‹ค.

  • gdb ์„ค์น˜
$ sudo su
$ apt-get install update 
$ apt-get install upgrade -y
$ apt-get install gdb -y
  • pwndbg ์„ค์น˜
$ apt-get install python3.12 python3.12-venv python3-pip python3-dev git libssl-dev libffi-dev build-essential -y
$ python3 -m pip install --upgrade pip
$ python3 -m pip install --upgrade pwntools

$ git clone <https://github.com/pwndbg/pwndbg>
$ cd pwndbg
$ ./setup.sh

 

gdb๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ, ์•„๋ž˜์™€ ๊ฐ™์ด ๋œจ๋ฉด ์„ฑ๊ณต์ ์œผ๋กœ ์„ค์น˜๊ฐ€ ๋˜์—ˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

pwndbg ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฐฉ๋ฒ•

01. pwndbg ์‹œ์ž‘ํ•˜๊ธฐ

  • GDB ์‹คํ–‰:
$ gdb ./your_binary
  • Breakpoints ์„ค์ •:
$ break main  # main ํ•จ์ˆ˜์— ๋ธŒ๋ ˆ์ดํฌํฌ์ธํŠธ ์„ค์ •
$ run         # ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰
  • context ์กฐํšŒ : ํ˜„์žฌ์˜ ๋ ˆ์ง€์Šคํ„ฐ, ์Šคํƒ, ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ, ์†Œ์Šค ์ฝ”๋“œ ๋“ฑ์„ ํ•œ ๋ฒˆ์— ๋ณด์—ฌ์คŒ
$ context

 

02. ๋ฉ”๋ชจ๋ฆฌ ๊ฐ’ ์กฐํšŒ

  • x (Examine Memory): ๋ฉ”๋ชจ๋ฆฌ์˜ ํŠน์ • ์ฃผ์†Œ๋ฅผ ๋””์Šคํ”Œ๋ ˆ์ดํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์–‘ํ•œ ํฌ๋งท๊ณผ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
$ x/<count><format><size> <address>

count: ์ถœ๋ ฅํ•  ํ•ญ๋ชฉ ์ˆ˜ format: ์ถœ๋ ฅ ํ˜•์‹ (x - 16์ง„์ˆ˜, d - 10์ง„์ˆ˜, i - ์–ด์…ˆ๋ธ”๋ฆฌ ์ฝ”๋“œ ๋“ฑ) size: ๋ฉ”๋ชจ๋ฆฌ ํ•ญ๋ชฉ ํฌ๊ธฐ (b - ๋ฐ”์ดํŠธ, h - ํ•˜ํ”„์›Œ๋“œ, w - ์›Œ๋“œ, g - Giant) address: ํ™•์ธํ•  ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ

# ์˜ˆ์‹œ
x/10xb 0x080484d2
x/5i $pc           # ํ˜„์žฌ PC๋ถ€ํ„ฐ ์ถœ๋ ฅ
x/s 0x080484d2     # ๋ฌธ์ž์—ด๋กœ ์ถœ๋ ฅ

 

03. ๋ฉ”๋ชจ๋ฆฌ ๊ฐ’ ๋ณ€์กฐ

๋ฉ”๋ชจ๋ฆฌ ํŒจ์น˜:

patch byte 0x080484d2 0xEB

ํŠน์ • ์ฃผ์†Œ ๊ฐ’ ํŒจ์น˜ :

set *0x080484d2 = 0xEB
๋ฐ˜์‘ํ˜•