C - Example Buffer OverFlow


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.