
[Reversing] 1์ฃผ์ฐจ dreamhack stage 2
2022. 4. 7. 23:05
DreamHack/Reversing (Dreamhack)
1. ํ๋ก๊ทธ๋จ๊ณผ ์ปดํ์ผ โ ํ๋ก๊ทธ๋จ (Program)๐ : ์ฐ์ฐ ์ฅ์น๊ฐ ์ํํด์ผ ํ๋ ๋์์ ์ ์ํ ์ผ์ข
์ ๋ฌธ์์ด๋ค. ํ๋ก๊ทธ๋จ์ ์ฐ์ฐ ์ฅ์น์ ์ ๋ฌํ๋ฉด, CPU๋ ์ ํ์๋ ๋ช
๋ น๋ค์ ์ฒ๋ฆฌํ์ฌ ํ๋ก๊ทธ๋๋จธ๊ฐ ์๋ํ ๋์์ ์ํํ๋ค. * ์ฌ์ฉ์๊ฐ ์ ์ํ ํ๋ก๊ทธ๋จ์ ํด์ํ์ฌ ๋ช
๋ น์ด๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ ์ฐ์ฐ ์ฅ์น๋ฅผ programmableํ๋ค๊ณ ํ๋ค. ํ๋์ ์ปดํจํฐ๊ฐ ๋ํ์ ์ธ programmable ์ฐ์ฐ ์ฅ์น, ์ผ๋ฐ ๊ณ์ฐ๊ธฐ ๋ํ์ ์ธ non-programmable ์ฐ์ฐ์ฅ์น โ · ๊ณผ๊ฑฐ์๋ ๋ด๋ถ ์ ์ฅ ์ฅ์น์ ์ ์ฅํ ์ ์์ด์ ์ฌ๋์ด ์ ์ ์ ์ฐ๊ฒฐํ์ฌ ์ปดํจํฐ์ ์ ๋ฌํจ - ์ ๋์
(ENIAC) --> ๋งค์ฐ ๋นํจ์จ์ ์ด๋ฉฐ, ํฌ๊ธฐ๊ฐ ํฐ ํ๋ก๊ทธ๋จ์ ์ฌ์ฉํ๊ธฐ๋ ์ด๋ ค์ ๋ค. โถ ์ด๋ฌํ ๋จ์ ์ ํด๊ฒฐํ Stored-Program Computer๊ฐ..

[Reversing] 1์ฃผ์ฐจ dreamhack stage 1
2022. 4. 7. 22:21
DreamHack/Reversing (Dreamhack)
๋ฆฌ๋ฒ์ค ์์ง๋์ด๋ง (๋ฆฌ๋ฒ์ฑ)์ด๋ ๐ : ์์ง๋์ด๋ง์ ๊ฑฐ๊พธ๋ก ํ๋ ํ์ - ์์ฑ๋ ์ ํ์ ํด์ฒดํ๊ณ ๋ถ์ํ์ฌ ๊ตฌ์กฐ์ ๊ธฐ๋ฅ, ๋์์ธ์ ํ์
ํ๋ค. * ์์ง๋์ด๋ง : ์์ฑํ๊ณผ ์ด๋ฅผ ๊ตฌ์ฑํ๋ ๋ถํ๋ค์ ๊ธฐ๋ฅ๊ณผ ์ค๊ณ๋ฅผ ๊ณ ์ํ๊ณ , ์ ์ํ๋ ๊ณผ์ โ โ โ ๋ฆฌ๋ฒ์ฑ์ ์ฉ๋ case 1) Good case ํ๋งค๋ ์ง ๋๋ฌด ์ค๋๋์ด ์ ์์ฌ๊ฐ ์ด๋ฏธ ๊ฐ๋ฐ์ ์ค๋จํ ํ๋ก๊ทธ๋จ์ ๋ํ ํจ์น๊ฐ ํ์ํ ๋ ๋ฆฌ๋ฒ์ฑ์ ๋งค์ฐ ํจ๊ณผ์ ์ด๋ค. ์ค์ ๋ก 1996๋
์ ๋ฐ๋งค๋ ‘๋์๋ธ๋ก1’์ด ๋ฆฌ๋ฒ์ฑ์ ๊ฑฐ์ณ ๋ชจ๋ฉ๋ ๋ฒ์ ์ด ๊ณต๊ฐ๋ ๋ฐ ์๋ค. ๋ํ, ๊ฐ์ข
ํ๋ก๊ทธ๋จ์ ๋ณด์์ฑ์ ํ๊ฐํ๊ฑฐ๋ ์
์ฑ์ฝ๋๋ฅผ ๋ถ์ํ ๋๋ ๋ฆฌ๋ฒ์ฑ์ด ๋๋ฆฌ ์ฐ์
๋๋ค. ๋ฆฌ๋ฒ์ฑ์ ํตํด ๋์ ํ๋ก๊ทธ๋จ์ด ์ผ๋ง๋ ์์ ํ๊ฒ ์ค๊ณ๋์๋์ง, ํน์ ๋์ ์
์ฑ์ฝ๋๊ฐ ์ด๋ค ๋ฐฉ์์ผ๋ก ๋์ํ๊ณ ์์คํ
์ ํผํด๋ฅผ ์
ํ๋์ง ..

[System Hacking] 2์ฃผ์ฐจ dreamhack stage 12
2022. 4. 7. 18:54
DreamHack/SystemHacking
ptmalloc2๋ ์ด๋ค ๋ฉ๋ชจ๋ฆฌ๊ฐ ํด์ ๋๋ฉด ํด์ ๋ ๋ฉ๋ชจ๋ฆฌ์ ํน์ง์ ๊ธฐ์ตํ๊ณ ์๋ค๊ฐ ๋น์ทํ ๋ฉ๋ชจ๋ฆฌ์ ํ ๋น ์์ฒญ์ด ๋ฐ์ํ๋ฉด ์ด๋ฅผ ๋น ๋ฅด๊ฒ ๋ณํํด์ค๋ค. --> ๋ฉ๋ชจ๋ฆฌ ํ ๋น์ ์๋๋ฅผ ๋์ผ ์ ์๊ณ , ๋ถํ์ํ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ์ ๋ง์ ์ ์๋ค. - ptmalloc2๋ ๋์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ด๋ฆฌํ๋ ๋ฆฌ๋
์ค์ ํต์ฌ ์๊ณ ๋ฆฌ์ฆ โ โ 1. ptmalloc2 (pthread malloc 2) : Wolfram Gloger๊ฐ ๊ฐ๋ฐํ Memory Allocater๋ก, Doug Lea์ dlmalloc์ ๊ฐ์ ํ ptmalloc์ ๋ ๋ฒ์งธ ๋ฒ์ ์ด๋ค. ptmalloc์ ๊ตฌํ ๋ชฉํ๋ ๋ฉ๋ชจ๋ฆฌ์ ํจ์จ์ ์ธ ๊ด๋ฆฌ์ด๋ค. โ ์ธ๋ถ ๋ชฉํ 1) ๋ฉ๋ชจ๋ฆฌ ๋ญ๋น ๋ฐฉ์ง 2) ๋น ๋ฅธ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฌ์ฉ 3) ๋ฉ๋ชจ๋ฆฌ ๋จํธํ ๋ฐฉ์ง * ์ฒญํฌ : ptmalloc2๊ฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋นํ๋..

[System Hacking] 1์ฃผ์ฐจ dreamhack stage 11 - (2)
2022. 4. 7. 17:37
DreamHack/SystemHacking
Use After Free ์ฃผ์ด์ง ์ฝ๋ uaf_overwrite.c๋ ์๋์ ๊ฐ๋ค. // Name: uaf_overwrite.c // Compile: gcc -o uaf_overwrite uaf_overwrite.c #include #include #include #include struct Human { char name[16]; int weight; long age; }; struct Robot { char name[16]; int weight; void (*fptr)(); }; struct Human *human; struct Robot *robot; char *custom[10]; int c_idx; void print_name() { printf("Name: %s\n", robot->name);..

[System Hacking] 1์ฃผ์ฐจ dreamhack stage 11 - (1)
2022. 4. 7. 17:33
DreamHack/SystemHacking
Use After Free ์ต์คํ๋ก์ ์์ // Name: uaf_overwrite.c // Compile: gcc -o uaf_overwrite uaf_overwrite.c #include #include #include #include struct Human { char name[16]; int weight; long age; }; struct Robot { char name[16]; int weight; void (*fptr)(); }; struct Human *human; struct Robot *robot; char *custom[10]; int c_idx; void print_name() { printf("Name: %s\n", robot->name); } void menu() { printf..

[System Hacking] 1์ฃผ์ฐจ Dreamhack stage 11
2022. 4. 7. 17:15
DreamHack/SystemHacking
ptmalloc2 (๋ฆฌ๋
์ค glibc 2.23 ์์ ํ ๋ฉ๋ชจ๋ฆฌ ํ ๋น์ ํ ๋, ptmalloc2 ๋ผ๋ ๋ฉ๋ชจ๋ฆฌ ํ ๋น์๋ฅผ ์ฌ์ฉ) 1. Use-After-Free : ๋ฉ๋ชจ๋ฆฌ ์ฐธ์กฐ์ ์ฌ์ฉํ ํฌ์ธํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ ํด์ ํ์ ์ ์ ํ ์ด๊ธฐํํ์ง ์์์, ๋๋ ํด์ ํ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ด๊ธฐํํ์ง ์๊ณ ๋ค์ ์ฒญํฌ์ ์ฌํ ๋นํด์ฃผ๋ฉด์ ๋ฐ์ํ๋ ์ทจ์ฝ์ โ Dangling Pointer : ์ ํจํ์ง ์์ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ - ํ๋ก๊ทธ๋จ์ด ์์์น ๋ชปํ ๋์์ ํ ๊ฐ๋ฅ์ฑ์ ํค์ - ๊ณต๊ฒฉ์์๊ฒ ๊ณต๊ฒฉ ์๋จ์ผ๋ก ํ์ฉ๋ ์๋ ์์ โ * malloc ํจ์๋ ํ ๋นํ ๋ฉ๋ชจ๋ฆฌ์ ์ฃผ์๋ฅผ ๋ฐํํ๋ ํจ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋์ ํ ๋นํ ๋์ ํฌ์ธํฐ๋ฅผ ์ ์ธํ๊ณ , ๊ทธ ํฌ์ธํฐ์ mallocํจ์๊ฐ ํ ๋นํ ๋ฉ๋ชจ๋ฆฌ์ ์ฃผ์๋ฅผ ์ ์ฅ -> ์ ๊ทผ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํด์ ํ ๋ freeํจ์ ์ฌ..