【发布时间】:2018-12-04 11:40:06
【问题描述】:
希望有人能帮助我了解我在大学学习的一个漏洞。
在c代码中有一个未绑定的strcat
strcat(buffer, argv[1]);
目的是将此缓冲区溢出到保存的 EIP 中,并让它显示在以下函数中调用的“魔术”字符串。
if (geteuid() == 0) {
printf("%s\n", magic);
} else {
printf("Forget it. You do not have access to the magic string.\n");
return (-1);
}
缓冲区与保存的 EIP 之间的差异是 52 个字节,我的想法是使用 printf 函数的地址溢出缓冲区,该函数将显示魔术字符串但无法使其工作我不断收到内存地址的 Seg 错误与我输入的不同。
非常感谢任何帮助。
编辑:下面的完整代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
enum { SIZE = 40 };
/* The magic string */
char *magic = "This is the magic string";
int
main(int argc, char *argv[])
{
char buffer[SIZE];
if (argc != 2) {
printf("Usage: %s name\n", argv[0]);
return (-1);
}
snprintf(buffer, sizeof (buffer), "%s", "Hello ");
strcat(buffer, argv[1]);
printf("%s\n", buffer);
if (geteuid() == 0) {
printf("%s\n", magic);
} else {
printf("Access Denied \n");
return (-1);
}
return (0);
}
【问题讨论】:
-
如果没有特定的系统,讨论这个是没有意义的。我们还需要minimal reproducible example 来重现该错误。最后,为什么您认为您的特定系统将字符串存储在 52 字节偏移地址上?
-
道歉@Lundin,堆栈溢出的新手:/ 这是一个 32 位 linux 系统,现在添加完整的代码来提问。在 GDB 中,我获取了保存的 EIP 寄存器的地址和缓冲区的地址,并使用 p/d x-y 得到了 52
-
最大的问题在于标题。没有 BSS。
-
好吧,事实证明我比我想象的更迷茫,谁能指出我如何找到魔法线的正确方向?
-
总的来说,像这样研究一些人为的“漏洞”是非常无用的做法。在现实世界的黑客攻击中,您不会拥有可执行文件的源代码或内存映射。
标签: c buffer-overflow