在Windows 10上创建缓冲区溢出

问题描述 投票:0回答:1

很快,我要在我的课堂上做一个演讲(攻读计算机科学学位),在这里我想举一个缓冲区溢出及其原因的基本示例。但是,我无法使缓冲区溢出正常工作。

问题是,即使导致崩溃,该进程也会终止,即使该进程已附加到xdbg之类的调试器上(在VS中,也会引发异常)。我认为这是Windows 10内置的一种保护引起的。我阅读了以下文章,尝试禁用它们,并确保在项目属性中禁用/GS的情况下编译项目,但是问题仍然存在。

Exploit protections disabled

下面的代码:

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string input;
    char overflow[5];
    cin >> input;
    strcpy(overflow, input.c_str());
}
c++ windows-10 buffer-overflow windows-security
1个回答
-1
投票

这里是缓冲区溢出的一个例子

#include <iostream>
#include <string>
#include <string.h>
using namespace std;

struct Buffers {
    char buffer1[6];
    char buffer2[6];
};

int main(int argc)
{
    string input;
    cin >> input;

    Buffers b = {};
    strcpy(b.buffer2, "Hello");
    cout << b.buffer2 << endl;

    strcpy(b.buffer1, input.c_str());

    cout << b.buffer2 << endl;
}

尽管我想您甚至不需要输入,但我使用testing作为输入。我认为这是您的演示文稿的一部分,用户输入是缓冲区溢出的常见地方。

© www.soinside.com 2019 - 2024. All rights reserved.