
๐CTF pwn์ ์ํ ํ ๋ถ์ ๋๊ตฌ.
Pwnning์ ์์ ์ ๋๋ค.
HeapInspect๋ heap์ ํจ์ฌ ๋ ์์๊ฒ ๋ณด์ด๋๋ก ์ค๊ณ๋์์ต๋๋ค.
์ด์ ์ด ๋๊ตฌ๋ nadbg์ ํ๋ฌ๊ทธ์ธ์ ๋๋ค. ์ฌ์ฉํด๋ณด์ธ์!
HeapShower (์์ธํ)PrettyPrinter (์์, ์์ฝ)์ด ๋๊ตฌ์ ๋น ๋ฅธ ์ฌ์ฉ ์์.




๋ํ gdb ํ๋ฌ๊ทธ์ธ์ผ๋ก ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, pwndbg๋ ๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ์ด ํ ๋ถ์์ ์คํจํ์ ๋ ๋งค์ฐ ์ ์ฉํฉ๋๋ค.
sed -i "1i source `pwd`/gdbscript.py" ~/.gdbinit # alternatively, you can add that line manually
์ฐธ๊ณ



์ฌ์ฉํ๊ธฐ ๋งค์ฐ ์ฝ์ต๋๋ค. ๋์ค์ ํจํค์ง๋ก ๋ง๋ค ์์ ์ ๋๋ค.
from heapinspect.core import *
hi = HeapInspector(1234) #pid here
hs = HeapShower(hi)
print(hs.fastbins)
print(hs.smallbins)
print(hs.largebins)
print(hs.unsortedbins)
print(hs.tcache_chunks)
hs.relative = 1 #relative mode, check Quick shot
print(hs.fastbins)
sleep(10)
#now assume that the heap state has changed
hs.update() #use this to refresh
pp = PrettyPrinter(hi)
print(pp.all) #pretty printer
pp.update() #use this to update
๋ช ๊ฐ์ง ํ ์คํธ ์ผ์ด์ค๊ฐ ์์ต๋๋ค.
heapinspect/tests/ $ python test.py #this will run all test cases for you to check this tool.
......
......
test case unsortedbins64 at test/testcases/libc-2.27/64bit
pid:6704
========================= fastbins =========================
========================= unsortedbins =========================
chunk(0x7f9aae2e6720): prev_size=0x0 size=0xb1 fd=0x7f9aacdfbca0 bk=0x7f9aae2e6880
chunk(0x7f9aae2e6880): prev_size=0x0 size=0xb1 fd=0x7f9aae2e6720 bk=0x7f9aacdfbca0
========================= smallbins =========================
========================= largebins =========================
========================= tcache =========================
tcache[9]:
chunk(0x7f9aae2e6670): prev_size=0x0 size=0xb1 fd=0x7f9aae2e65d0 bk=0x0
chunk(0x7f9aae2e65c0): prev_size=0x0 size=0xb1 fd=0x7f9aae2e6520 bk=0x0
chunk(0x7f9aae2e6510): prev_size=0x0 size=0xb1 fd=0x7f9aae2e6470 bk=0x0
chunk(0x7f9aae2e6460): prev_size=0x0 size=0xb1 fd=0x7f9aae2e63c0 bk=0x0
chunk(0x7f9aae2e63b0): prev_size=0x0 size=0xb1 fd=0x7f9aae2e6310 bk=0x0
chunk(0x7f9aae2e6300): prev_size=0x0 size=0xb1 fd=0x7f9aae2e6260 bk=0x0
chunk(0x7f9aae2e6250): prev_size=0x0 size=0xb1 fd=0x0 bk=0x0
์์ธํ docstring์ด ์์ค ์ฝ๋์ ์์ฑ๋์ด ์์ต๋๋ค.
docs์ sphinx ๋ฌธ์๋ฅผ ๊ตฌ์ถํ์ต๋๋ค. ๋ธ๋ผ์ฐ์ ์์ docs/build/html/index.html์ ์ด๋ฉด ๋ฉ๋๋ค.
๋ฌธ์ ์ ๋ฐ์ดํธ.
๊ธฐ๋ฅ ์ ๋ฐ์ดํธ๋ ์๋๋๋ค.
์ฒซ ๋ฒ์งธ ๋ฆด๋ฆฌ์ค
๋ค์ ๋ฒ์ ์ ๋ฆด๋ฆฌ์ค๊ฐ ๋ ์์ ์ ๋๋ค.
์ด ๋ฒ์ ์ ์์ ์ ์ด์ง ์์ต๋๋ค. ๋ค๋ฅธ glibc๋ก ์ธํ ๋ฒ๊ทธ๋ฅผ ์์ ํ๋ ค๊ณ ๋ ธ๋ ฅ ์ค์ ๋๋ค. ํ ์คํธ์ ๋์์ด ํ์ํฉ๋๋ค.
๋ค์ ๋ฒ์ ์์๋ ๋ฉํฐ libc ์ง์์ด ์ถ๊ฐ๋ ์์ ์ ๋๋ค. heapdiff์ heap check๋ ๋์ค์ ์ถ๊ฐ๋ ๊ฒ์ ๋๋ค.
HeapShowerbins๋ ์ด์ glibc ๋ฐฉ์์ ๋ฐ๋ผ fd ๋์ bk๋ถํฐ ๊ฒ์HeapRecoder, heapdiff๋ฅผ ๋ง๋ค ์์ smallbins and largebinsfastbin prototypeunsortedbin prototypebins prototypetcache prototypeC_Struct ์ถ๊ฐclass HeapInspector ์ถ๊ฐarena์ ๋ ๋ง์ ์ ๋ณด๋ฅผ ํ์ฑํ๋ ค๊ณ ์๋proc_util์ class Proc ์ถ๊ฐtest.py์์ ์คํ์ ํ
์คํธ