我不能溢出缓冲区

I can not overflow buffer

我看到了缓冲区溢出代码,但我不能溢出它。是否有任何 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. 知道栈内存布局和变量modifiedbuffer的地址区别 您可以通过找到修改和缓冲区之间的偏移量来解决它 (char *)&modified - (char *)buffer
  2. 你的机器字节顺序。为此,我使用了 stack overflow 答案

链接演示了如何 运行 用于确定正确参数和堆栈粉碎的修改代码。第一个Demo provides you with the argument that you can feed to your second Demo