[英]-fno-stack-protector is not working
I have written the following C program to see the working of buffer overflows.我编写了以下 C 程序来查看缓冲区溢出的工作情况。 I have saved this program file with name bo.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;
}
But I am not able to see the effect of buffer overflow because the stack is protected.但是我看不到缓冲区溢出的影响,因为堆栈是受保护的。 But when I am compiling it with the -fno-stack-protector flag, it is showing that it is an unrecognized option.
但是当我使用 -fno-stack-protector 标志编译它时,它表明它是一个无法识别的选项。
What is the problem here?这里有什么问题? Am I doing something wrong in the usage of the gcc command?
我在使用gcc命令时做错了什么吗?
You are correctly doing the command but it is unrecgonized due to your configuration.您正在正确执行该命令,但由于您的配置而无法识别。
gcc -fno-stack-protector bo.c
I would recommend reinstalling gcc or trying in another linux distro.我建议重新安装 gcc 或尝试使用另一个 linux 发行版。 Also feel free to look at this article on the use of -fno-stack-protector as it gives some insight as to why it may be disabled.
也可以随意查看这篇关于-fno-stack-protector 使用的文章,因为它提供了一些关于为什么它可能被禁用的见解。 (Do to possible configurations with Makefile disabling the flag)
(使用 Makefile 禁用标志对可能的配置进行处理)
--------Edit---------- - - - - 编辑 - - - - -
After looking further into this, I would recommend looking at: -fstack-protector-all
or -fstack-protector
在进一步研究之后,我建议查看:
-fstack-protector-all
或-fstack-protector
I was messing around with your code and found this might be what you're trying to do and your current setup may allow it.我正在处理您的代码,发现这可能是您正在尝试执行的操作,并且您当前的设置可能允许这样做。
我认为正确的命令是这样的:
gcc -o bo bo.c -fno-stack-protector
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.