代码如下:
程序使用粘滞位(属主uid为0)运行,我的任务是破解并以root身份运行
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)运行,我的任务是破解并以root身份运行
/bin/sh
。我知道如何使用fe
缓冲区溢出和strcpy
(shellcode)攻击方式破解程序,但不知道如何对这一程序使用格式化字符串攻击。可以看到有一个变量the_var
,如果它不等于50,则shell会运行(也许尝试通过某种方法更改它,进行一些“肮脏的魔法”?)。无论如何,存在一个printf (buf)
。