我正在学习缓冲区溢出,并尝试制作一个。我有这段代码:
#include <stdio.h>
char *secret = "password";
void go_shell() {
char *shell = "/bin/sh";
char *cmd[] = { "/bin/sh", 0 };
setreuid(0);
execve(shell,cmd,0);
}
int authorize() {
char password[64];
printf("Enter Password: ");
gets(password);
if (!strcmp(password,secret)) {
return 1;
}
else {
return 0;
}
}
int main() {
if (authorize()) {
printf("login successful\n");
go_shell();
} else {
printf("Incorrect password\n");
}
return 0;
}
我使用gcc编译,然后在gdb中运行它。
我输入了大约100个"A"作为密码,程序崩溃了。
问题是没有任何寄存器被覆盖为
0x4141414141414141
。我在谷歌上搜索了这个问题,并在
gcc
中添加了-fno-stack-protector
标志,这使得RBP可以被覆盖为0x4141414141414141
,但其他的仍然不行。我想知道是否有一种方法可以编译代码,以便RIP可以被覆盖。
-fomit-frame-pointer
选项),那么帧指针也可能被覆盖。因此这些可能会被拉回到寄存器中,但这是因为堆栈先被覆盖了,而不是直接覆盖寄存器。 - Jonathan Leffler