gpt4 book ai didi

c - 如何使用缓冲区溢出执行 "printf string attack"?

转载 作者:太空狗 更新时间:2023-10-29 15:30:05 25 4
gpt4 key购买 nike

代码:

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),但不知道如何在这一个上使用“格式字符串攻击”。

如您所见,有一个 var the_var,如果它不等于 50,则 shell 正在运行(也许尝试以某种方式更改它,一些肮脏的魔法?)。反正有一个printf(buf)

最佳答案

你控制buf。传递 %x 格式字符串转储堆栈和 %n 覆盖堆栈中的对象 the_var。从您的程序中,如果对象 the_var 被覆盖,将调用 doit 函数并执行 /bin/sh

关于c - 如何使用缓冲区溢出执行 "printf string attack"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com