https://dreamhack.io/wargame/challenges/1111
Buffer overflowย is one of the basics of pwnable ๐ฑ
The path of the flag file isย /home/bof/flag.
/home/bof/flag.
meow? ๋ ๊ธ์ด ๋ ์ ๊ทธ๋๋ก ์ ๋ ฅ์ ํ์๋๋โฆ ์ ๋ฐ ๊ท์ฌ์ด ๊ทธ๋ฆผ์ด ๋จ๋ฉฐ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ธ์ ๊ทธ๋๋ก ๋ฐํํ๋ ๊ฒ์ ํ์ธํ ์ ์์์ต๋๋ค.
dof ๋ ๋ฐ์ด๋๋ฆฌ ํ์ผ์ด ์กด์ฌํจ์ ์ ์ ์์๊ณ , ์ด๋ฅผ IDA๋ผ๋ ๋์ค์ด์
๋ธ ํด๋ก ์ด์ด๋ณด์์ต๋๋ค.
์ด ์ํ์์๋ ๋ณด๊ธฐ ์ด๋ ค์ฐ๋, ๋์ปดํ์ผ ๊ณผ์ ์ ํตํด ๋ฐ์ด๋๋ฆฌ๋ฅผ .์ฐ๋ฆฌ๊ฐ ์ดํดํ ์ ์๋ ๊ณ ๊ธ์ธ์ด๋ก ๋ณํํด์ค๋๋ค. ์์ ํ๋ฉด์์ F5๋ฅผ ๋๋ฅด๋ฉด ๋ณํ ๊ฐ๋ฅํฉ๋๋ค.

C์ฝ๋์ ๋๋ค. ์ค์ ์ฝ๋๋ฅผ ํด์ํด๋ณด๊ฒ ์ต๋๋ค.
char v4[128]; // ์ฌ์ฉ์ ์
๋ ฅ ๋ฐ์ ๋ฒํผ
char v5[16]; // "./cat" ๋ฌธ์์ด ์ ์ฅ ๋ฒํผ
v4 : ํฌ๊ธฐ 128์ง๋ฆฌ ๋ฌธ์์ด ๋ฐฐ์ด (์
๋ ฅ ๋ฐ์ ๊ณณ)v5 : ํฌ๊ธฐ 16์ง๋ฆฌ ๋ฌธ์์ด ๋ฐฐ์ด (ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์ธ ๋ช
๋ น ์ ์ฅ)printf("meow? ");
__isoc99_scanf("%144s", v4);
"meow? " ์ถ๋ ฅํ๊ณ ์ฌ์ฉ์ ์
๋ ฅ์ v4์ ์ ์ฅ.%144s ํฌ๋งท์ ์ต๋ 144๊ธ์ ๋ฌธ์์ด์ ์ฝ๋๋ค๋ ์๋ฏธ. โ v4์ ๋ฐฐ์ดํฌ๊ธฐ๋ 128์ธ๋ฐ ์ต๋ 144๋ฐ์ดํธ๋ฅผ ๋ฐ์ ์ ์์ต๋๋ค > ๋ฒํผ ์ค๋ฒํ๋ก์ฐ ๋ฐ์ ๊ฐ๋ฅ!]v4 ๋ค์์ v5์์ ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์ธ ๋ช
๋ น์ ์ ์ฅํ๊ณ ์๊ธฐ์ ๋งค์ฐ ์ํํฉ๋๋ค.v4 ์, 128byte๋ ์๋ฌด ๊ฐ์ผ๋ก ์ฑ์ฐ๊ณ , ์ถ๊ฐ๋ก ํ๋๊ทธ๊ฐ ์๋ ๊ฒฝ๋ก์ธ /home/bof/flag๋ฅผ ์
๋ ฅํ์ฌ v5๋ฅผ ๋ฎ์ด๋ฒ๋ฆด ์ ์๊ฒ ํฉ๋๋ค./home/bof/flag ๋ฅผ ์
๋ ฅํฉ๋๋ค. ์ฑ๊ณต์ ์ผ๋ก ํ๋๊ทธ๊ฐ์ ํ๋ํ ์ ์์์ต๋๋ค.
meow?; the program echoed the user input back.dof and opened it in IDA; used the decompiler (F5) to view C-like code.char v4[128]; char v5[16]; printf("meow? "); __isoc99_scanf("%144s", v4); โ v4 is 128 bytes but scanf allows 144 bytes, enabling a stack buffer overflow.v5 (16 bytes) is placed after v4 on the stack and holds the command string, overflowing v4 can overwrite v5./home/bof/flag to overwrite v5; the program then uses that overwritten command/path and prints the flag.fgets or correct width specifiers), cross-check decompiled code with assembly, inspect stack layout with a debugger for accurate offsets, and perform exploitation only in authorized CTF/VM environments.