c++ - I can not overflow buffer -


i have seen buffer overflow code can not on flow it. there gcc option compile that? or wrong code.

the code is:

#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 argument\n");      }       modified = 0;      strcpy(buffer, argv[1]);       if(modified == 0x61626364) {             printf("you have correctly got variable right value\n");      } else {             printf("try again, got 0x%08x\n", modified);      } } 

and trying run way:
perl -e 'print "a"x64 . "dcba"' | xargs ./main

you need know

  1. know stack memory layout , address difference between variable modified , buffer can solve finding offset between modified , buffer (char *)&modified - (char *)buffer
  2. your machine endianess. have used stack overflow answer purpose

the linked demonstrates how run modified code serves purpose of determining correct argument stack smashing. first demo provides argument can feed second demo


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -