Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

C - Example Buffer OverFlow

/*
*
* Esempio di Buffer Overflow ...
*/

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