缓冲区溢出不起作用 [英] Buffer Overflow not working

查看:88
本文介绍了缓冲区溢出不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在需要密码的简单程序上进行缓冲区溢出(我正在使用Linux)。程序代码如下:

I was trying to do a buffer overflow (I'm using Linux) on a simple program that requires a password. Here's the program code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check_authentication(char *password){

int auth_flag = 0;
char password_buffer[16];

strcpy(password_buffer, password);

if(strcmp(password_buffer, "pass1") == 0)
    auth_flag = 1;
if(strcmp(password_buffer, "pass2") == 0)
    auth_flag = 1;

return auth_flag;

}

int main(int argc, char **argv)
{

if(argc < 2){

    printf("\t[!] Correct usage: %s <password>\n", argv[0]);
    exit(0);

}

if(check_authentication(argv[1])){

    printf("\n-=-=-=-=-=-=-=-=\n");
    printf("  Access granted.\n");
    printf("-=-=-=-=-=-=-=-=\n");

} else {

    printf("\nAccess Denied.\n");

}


   return 0;

}

确定,现在我编译了,没有错误,并保存了

OK, now I compiled it, no errors, and saved it as overflow.c.

现在打开终端,进入文件目录(桌面),然后写:

Now I opened the Terminal, I moved into the file directory (Desktop) and then wrote:

./overflow.c AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

终端说:检测到堆栈被砸(或类似的东西),然后退出程序执行。

The Terminal said: "Stack smashing detected" (or something like that) and then quit the program execution.

现在,我正在读一本书,叫做 Hacking-The剥削的艺术,乔恩·埃里克森(Jon Erickson)。在一个章节中,他解释了这种类型的攻击(我从书中获取了代码),并执行了相同的命令。内存溢出,程序显示访问权限已授予。现在,为什么我的操作系统检测到我正在尝试利用该程序?我做错了什么?

Now, I'm reading a book, called "Hacking - The Art Of Exploitation" by Jon Erickson. In a chapter, he explains this type of exploit (I took the code from the book) and does the same command I've done. The memory overflows and the program prints "Access granted.". Now, why my OS is detecting I'm trying to exploit the program? I've done something wrong?

我也尝试在Mac OS X上利用该漏洞。发生了同样的事情。拜托,有人可以帮我吗?

I also tried the exploit on Mac OS X. Same thing happened. Please, can someone help me? Thanks in advance.

推荐答案

在现代linux发行版中,检测到缓冲区溢出并杀死了进程。为了禁用该模式,只需使用以下标志(gcc)编译您的应用程序:

In modern linux distributions buffer overflow is detected and the process is killed. In order to disable that mode simply compile your application with such flags (gcc):

-fno-stack-protector -fno-stack-protector -全部

这篇关于缓冲区溢出不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆