c - 为什么我无法禁用堆栈保护?

标签 c buffer buffer-overflow exploit

我目前使用的操作系统是64位Ubuntu 14.04,gcc版本是4.8.4。

我写了一个如下所示的简单程序,做了一些与缓冲区溢出相关的测试,不知怎的,我发现我无法正确溢出本地字符串。

/*test.c*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int bof(char *str)
{
    char buffer[4];
    strcpy(buffer, str);
    return 1;
}

int main()
{
    char str[]="123456789012345'; 

    /* This is the maximum length the string
     can be, which is 16 bytes including the null character at the end, and 
    any strings that are longer than this would result in a segmentation fault */

    bof(str);
}

该程序是用命令编译的

gcc -o test -fno-stack-protector test.c

因此应该禁用堆栈保护。

根据我的观察,任何长度小于或等于 16 个字符(包括空字符)的字符串都可以;否则,会导致段错误。

有什么想法为什么以及如何让它发挥作用吗?提前致谢!

最佳答案

你可以使用GNU Debug来找到距离,这里有一个教程http://www.cs.umd.edu/~srhuang/teaching/cmsc212/gdb-tutorial-handout.pdf

关于c - 为什么我无法禁用堆栈保护?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34629918/

相关文章:

Python字节缓冲区对象?

c - 预期的缓冲区溢出并不总是导致程序崩溃

security - 远程服务器上的缓冲区溢出

c - 在 OpenCV 中显示一个非常简单的图像

通过 fifo 队列 linux 进行通信

c++ - 为什么 getline() 跳过输入,即使在 cin.clear() 之后?

C# 文件流 : Optimal buffer size for writing large files?

在 C 中导致缓冲区溢出以强制条件为真

c - 如何使用 JSCH 发送 CTRL+C?

c - 64位精度 sleep 功能?