Posted By

whitetiger on 11/09/06


Tagged

math buffer String c example variable bug dynamic binary integer char world lines bof bufferoverflow hello memory manager block allocator reallocator interseccion palindrome plotter pascal triangle change invert


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

yuconner
copyleft
yarvin


C - Example Buffer OverFlow


 / Published in: C++
 

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. char *buffer1 = (char *)calloc(5, sizeof(char));
  7. char *buffer2 = (char *)calloc(15, sizeof(char));
  8. char *tmp;
  9.  
  10. strcpy(buffer2, "ls -a --color");
  11. strcpy(buffer1, argv[1]);
  12.  
  13. // Indirizzi di memoria...
  14. printf("%p <-- buffer1\n", buffer1);
  15. printf("%p <-- buffer2\n", buffer2);
  16. printf("\n\n");
  17.  
  18. // Stampa indirizzi...
  19. printf("Start code....\n");
  20. tmp=buffer1;
  21. while(tmp<buffer2+15)
  22. {
  23. printf("%p: %c (0x%x)\n", tmp, *tmp, *(unsigned int *)tmp);
  24. tmp++;
  25. }
  26.  
  27. printf("\n");
  28. system(buffer2);
  29. return 0;
  30. }

Report this snippet  

You need to login to post a comment.