본문 바로가기

Layer7/CTF & Wargame

Write-Up: [고등해커3][Pwnable] BOF

코드는 아래와 같다.

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
32
33
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
void setup()
{
    setvbuf(stdin,0,2,0);
    setvbuf(stdout,0,2,0);
    setvbuf(stderr,0,2,0);
}
 
int main(void
{
    setup();
    
    char buf[0x30= {0, };
 
    printf("Input : ");
    gets(buf);
 
    if(strlen(buf) > sizeof(buf))
    {
        puts("This is Buffer Overflow !");
        system("cat /home/BOF/flag");
    exit(1);
    }
 
    else
    {
        puts("If you trigger Buffer Overflow, you can get flag!");
        exit(1);
    }
}
cs

문자를 0x30초과 입력하면 sizeof(buf)사용자 입력값가 strlen(buf)buf길이 0x30보다 더 커지므로 flag를 출력하게 된다.

0x30은 십진수로 48이다.