-fno-stack-protector 不工作
-fno-stack-protector is not working
我编写了以下 C 程序来查看缓冲区溢出的工作原理。我已将此程序文件保存为 bo.c
#include<stdio.h>
#include<string.h>
int authentication(char *key)
{
int auth=0;
char pass[10];
strcpy(pass, key);
if(strcmp(pass, "hello")==0)
auth=1;
else
auth=0;
return auth;
}
int main(int argc, char *argv[])
{
if(authentication(argv[1]))
{
printf("----------------------------------\nACCESS GRANTED\n---------------------------------");
}
else
{
printf("Access Denied! Wrong password!");
}
return 0;
}
但是我看不到缓冲区溢出的影响,因为堆栈是受保护的。但是当我用 -fno-stack-protector 标志编译它时,它显示它是一个无法识别的选项。
这里有什么问题?我在使用 gcc 命令时做错了什么吗?
您正确地执行了命令,但由于您的配置而无法识别。
gcc -fno-stack-protector bo.c
我建议重新安装 gcc 或尝试另一个 linux 发行版。也可以随意查看 the use of -fno-stack-protector 上的这篇文章,因为它提供了一些关于为什么它可能被禁用的见解。 (使用禁用标志的 Makefile 进行可能的配置)
--------编辑----------
进一步研究后,我建议您查看:-fstack-protector-all
或 -fstack-protector
我正在研究你的代码,发现这可能是你想要做的,而且你当前的设置可能允许这样做。
My CMD Output
我认为正确的命令是这样的:
gcc -o bo bo.c -fno-stack-protector
我编写了以下 C 程序来查看缓冲区溢出的工作原理。我已将此程序文件保存为 bo.c
#include<stdio.h>
#include<string.h>
int authentication(char *key)
{
int auth=0;
char pass[10];
strcpy(pass, key);
if(strcmp(pass, "hello")==0)
auth=1;
else
auth=0;
return auth;
}
int main(int argc, char *argv[])
{
if(authentication(argv[1]))
{
printf("----------------------------------\nACCESS GRANTED\n---------------------------------");
}
else
{
printf("Access Denied! Wrong password!");
}
return 0;
}
但是我看不到缓冲区溢出的影响,因为堆栈是受保护的。但是当我用 -fno-stack-protector 标志编译它时,它显示它是一个无法识别的选项。
这里有什么问题?我在使用 gcc 命令时做错了什么吗?
您正确地执行了命令,但由于您的配置而无法识别。
gcc -fno-stack-protector bo.c
我建议重新安装 gcc 或尝试另一个 linux 发行版。也可以随意查看 the use of -fno-stack-protector 上的这篇文章,因为它提供了一些关于为什么它可能被禁用的见解。 (使用禁用标志的 Makefile 进行可能的配置)
--------编辑----------
进一步研究后,我建议您查看:-fstack-protector-all
或 -fstack-protector
我正在研究你的代码,发现这可能是你想要做的,而且你当前的设置可能允许这样做。
My CMD Output
我认为正确的命令是这样的:
gcc -o bo bo.c -fno-stack-protector