【发布时间】: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