我不能溢出缓冲区

时间:2015-04-29 11:06:48

标签: c++ buffer-overflow

我看过一个缓冲区溢出代码,但我不能过度流动它。有编译的gcc选项吗?或者该代码有任何问题。

代码是:

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

int main(int argc, char **argv)
{
     volatile int modified;
     char buffer[64];

     if(argc == 1) {
          errx(1, "please specify an argument\n");
     }

     modified = 0;
     strcpy(buffer, argv[1]);

     if(modified == 0x61626364) {
            printf("you have correctly got the variable to the right value\n");
     } else {
            printf("Try again, you got 0x%08x\n", modified);
     }
}

我试图以这种方式运行它:
perl -e 'print "A"x64 . "dcba"' | xargs ./main

1 个答案:

答案 0 :(得分:1)

你需要知道

  1. 了解堆栈内存布局以及变量modifiedbuffer之间的地址差异 您可以通过查找已修改和缓冲区之间的偏移量(char *)&modified - (char *)buffer
  2. 来解决此问题
  3. 您的机器endianess。我为此目的使用了stack overflow答案
  4. 链接演示了如何运行修改后的代码,该代码用于确定正确的参数以及堆栈粉碎。第一个Demo为您提供了可以提供给第二个Demo

    的参数
相关问题