【问题标题】:Why too much data fails to overwrite instruction pointer?为什么太多数据无法覆盖指令指针?
【发布时间】:2021-04-24 06:41:25
【问题描述】:

最近我在一个简单的 c 代码上尝试缓冲区溢出,该代码已在 opensecuritytraining 的漏洞利用类 1 中显示。这是代码

#include<stdio.h>
char *secret ="hello";
void go_shell()
{
        printf("This is go_shell\n");
}
int authorize()
{
        char password[64];
        printf("Enter the password: ");
        gets(password);
        if(!strcmp(password,secret))
        {
                return 1;
        }
        else
                return 0;
}
int main ()
{
        if (authorize())
        {
                printf("Login ok!\n");
                go_shell();
        }
        else
                printf("Incorrect\n");
}

当我输入超过 72 个 'A' 时,它开始覆盖堆栈的 rip 部分。 This is the stack when i enter 73 'A' 。其中 rip 保存在 0x7ffffffee308 并被覆盖。 This is the result on the overflow。但问题是当我输入超过 78 'A' This is the stack when i give 78 'A' as input。这是Successfully overwritten rip This is when 79 'A' are given as input。虽然 stack 被成功覆盖,但 rip 指向正确的位置。为什么会这样? 我在wsl中使用ubuntu。

【问题讨论】:

  • 请查看您的帖子。显然没有人可以阅读您发布的代码,因为它都在一条长线上。请重新格式化,使其可读。见Editing help
  • 欢迎来到 Stack Overflow。请阅读the help pages,接受SO tour,阅读How to Ask,以及this question checklist。最后请学习如何创建minimal reproducible example
  • @Anurag Kashyap - 在您的堆栈图像中,您假定保存的 RIP 位于 0x7ffffffee308,但您写 该 RIP 保存在 0x7ffffffee350
  • 谢谢@Armali,我更正了。顺便说一句,你知道为什么会这样吗?
  • 我是 tcc 的,所以没有优化。

标签: c buffer-overflow exploit


【解决方案1】:

我可以重现观察结果。确实有两种行为案例:

  1. 损坏的返回地址被加载到 RIP 中,并且在损坏的指令指针处发生段错误。
  2. 在加载到 RIP 之前检测到损坏的返回地址,并且在 retq 指令指针处发生了段错误。

我仍然需要深入研究处理器文档,但似乎早期检测错误的返回地址取决于它的“错误程度”——当只有一些 LSB 错误时,返回被采取,而当只有一个 MSB 仍然正确,则不返回。

【讨论】:

  • 你更喜欢哪本书来参考这些事情。请告诉我,以便我也可以随时参考。
  • 我没有找到明确的参考。值得注意的是/proc/cpuinfo 包含address sizes : 46 bits physical, 48 bits virtual,case 1 出现在返回地址 0x7FFFFFFFFFFF,case 2 从 0x800000000000 开始,如果符号扩展,超过了 48 位地址空间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-23
  • 2013-12-29
  • 1970-01-01
相关资源
最近更新 更多