代码:
void doit() { system("/bin/sh"); exit(0); } int main(int argc, char **argv) { static int the_var; char buf[512]; the_var = 20; strncpy (buf, argv[1], sizeof(buf) - 1); printf (buf); if (the_var != 20) { doit(); } else { printf ("\nthe_var @ 0x%08x = %d 0x%08x\n", &the_var, the_var, the_var); } }
程序运行使用粘滞位(所有者uid 0)我所要做的就是破解它并以/ bin / sh为根运行.
我知道如何用fe破解程序.缓冲区溢出和strcpy(shellcode),但是如何在这一个上使用’format string attack’.
正如你所看到的,有一个var the_var,如果它不等于50那么shell正在运行(也许试着以某种方式改变它,一些肮脏的魔法?).无论如何,有一个printf(buf)
你控制buf.传递%x格式字符串以转储堆栈,并传递%n以覆盖堆栈中的对象the_var.如果对象the_var被覆盖,则从程序中调用doit函数并执行/ bin / sh.
精彩评论