basic_exploitation_002
basic_exploitation_002
๋ฌธ์ ํ์ด
๋ x86..์ด๋ค์ ์ด๊ฑฐ ์ด์ ์ต์ํด์ง๊ฒ ๋ค ์ข๋ค
NX์ Partial RELRO.. ๊ทธ๋ฌ๋ FSB๋ก ํ์ด์ผํ๋ ๋ฌธ์ ๋๊น C์ฝ๋๋ฅผ ๋ณด์๋ฉด
buf(0x80) ๋งํผ ํ ๋น read()์์ ๊ทธ๋งํผ ์
๋ ฅ๋ฐ๊ธฐ์ BOF๋ ๋ฐ์ X
๊ทธ๋ฌ๋ printf(buf)๋ก FSB๋ ๋๋ค๋ ์ ๊ณผ get_shell() ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋๋๋ ์ !
FSB : Format String Bug ๋ก ๊ฐ๋ฐ์์ ์ค์๋ก ๋น์ด์ง ๋ฒ๊ทธ
Exploit ์ค๊ณ
FSB๋ %p %x %n %hn %N$FSB ๋ฑ์ด ํต์ฌ์ผ๋ก์จ
์คํ์ ์์ด๊ธฐ ๋๋ฌธ์ ์๋ง ๋ ๋์ ๋ณ์์ ์กด์ฌํ ๊ฐ๋ฅ์ฑ์ด ์์ฃ ๊ทธ๋ผ 10๋ณด๋ค ํฐ ๊ฐ์ ์ ๋นํ ๋ฃ๋๋ค๋ฉด
์ธ์ ๊ฐ name์ ๋ณ์์ ๋ฟ๊ณ name์ "/bin/sh"๋ฅผ ์
๋ ฅํ์ฌ ๊ทธ ๊ฐ์ ๋ฃ๋๋ค๋ฉด?
๊ทธ๋ผ command์ name ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ง ๊ตฌํ๋ฉด exploit code๊ฐ ์๋๋๊ฒ ๋ค์
๊ทธ๋ผ ๋ฐ๋ก ์์ํด๋ณผ๊น์?
Exploit
์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์กด์ฌํ๋ฉฐ ์ฌ๊ธฐ์ ์์์ ์ธ ๋ฐฉ๋ฒ์ ์ ๊ฐ ๊ทธ์ ์๋ ์คํจํ ๊ฒฝํ์ด..
์๋ ์ฝ๋๋ฅผ ๋ณด์๋ฉด ์์์ ์ธ ๋ฐฉ์์ผ๋ก ํ ์ ์์ ๊ฒ์
๋๋ค.
HackerSchool_level11
keyword : strcpy bof keyword : printf Format String keyword : NOP level11 - Write Up(NOP) ํํธ๊ฐ ์ฝ๋๋ค์... ์ ์ฝ๋๋ฅผ ๋ณด๋ฉด argv๋ผ๋ main์ธ์์ ๊ฐ์ ๋ฐ์์ ์ถ๋ ฅํ๋ค์ setreuid๊ฐ ์๊ธฐ์ level12๋ก..
dystopia050119.tistory.com
์ ๋ pwn์์ ์ ๊ณตํ๋ fsb๋ฅผ ์ฝ๊ฒํ๋ fmtstr_payload๋ฅผ ์ฌ์ฉํ ๊ฒ ์ ๋๋ค.
pwnlib.fmtstr — Format string bug exploitation tools — pwntools 4.8.0 documentation
A tuple (score, value, mask) where score equals the number of matching bytes between the returned value and target.
docs.pwntools.com
์์ ๋งํฌ์์ ์ฌ์ฉ๋ฐฉ๋ฒ์ ์๋ ค์ค๋๋ค
fmtstr_payload(offset, writes)
* writes = {addr:value, addr2:value2}
์ด๋ฐ ๋๋์ ๋๋ค
๊ทธ๋ผ ์ ํฌ๋ bof๊ฐ ๋ฐ์์ด ๋ถ๊ฐํ๊ธฐ์ main์ฝ๋๊ฐ ๋๊น์ง ์คํ๋๋ฉด ๋ง๋ฌด๋ฆฌ๋๋
exit()์์ get_shell()๊น์ง์ ๊ธธ์ด๋ฅผ ์๋ฉด ๋๊ฒ ๊ตฐ์
12345678910 from pwn import *p = remote('host3.dreamhack.games', 22371)elf = ELF('./basic_exploitation_002')payload = fmtstr_payload(1, {elf.got['exit'] : elf.symbols['get_shell']})p.send(payload)p.interactive()cs
์ฝ๋.. ์ค๋ช
์ด๋๊ฒ ์๋ค์.. fmtstr_payload์ ๋ํ์ฌ ์์๋ณด์๋ค?
pwntools๊ฐ ์ ๋ง ์ข๊ตฌ๋.. ๋ผ๊ณ ๋ง๋ฌด๋ฆฌ ํ๊ฒ ์ต๋๋ค
์ฐธ๊ณ ์๋ฃ
์ฐธ๊ณ ์ด๋ฏธ์ง