gpt4 book ai didi

c - 通过 xinetd 的简单缓冲区溢出

转载 作者:行者123 更新时间:2023-11-30 15:06:18 24 4
gpt4 key购买 nike

我正在尝试制作一个简单的缓冲区溢出教程,通过 xinetd 将下面的程序作为端口 8000 上的服务运行。代码是使用

编译的
gcc -o bof bof.c -fno-stack-protector 

ubuntu 也关闭了堆栈保护。

本地利用,即

python -c ---snippet--- | ./bof 

成功,隐藏函数被执行,显示文本文件内容。

但是,将其作为服务运行并执行

python -c ---snippet--- | nc localhost 8000

利用时不返回任何内容。我在这里遗漏了什么吗?

#include <stdio.h>

void secret()
{
int c;
FILE *file;
file = fopen("congratulations.txt", "r");
if (file) {
while ((c= getc(file)) !=EOF)
putchar(c);
fclose(file);


}

void textdisplay()
{
char buffer[56];

scanf("%s", buffer);
printf("You entered: %s\n", buffer);
}

int main()
{
textdisplay();

return 0;
}

最佳答案

默认情况下输出是缓冲的。要禁用此功能,您可以在 main 顶部执行以下操作:

setbuf(stdin, NULL);

这应该可以解决您的问题。

关于c - 通过 xinetd 的简单缓冲区溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39198274/

24 4 0
文章推荐: c - 用 C 读/写大文件
文章推荐: javascript - 用 Jasmine 测试异步函数的错误处理
文章推荐: javascript - 禁用