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 ...
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	char *buffer1 = (char *)calloc(5, sizeof(char));
	char *buffer2 = (char *)calloc(15, sizeof(char));
	char *tmp;
	
	strcpy(buffer2, "ls -a --color");
	strcpy(buffer1, argv[1]);

	// Indirizzi di memoria...
	printf("%p <-- buffer1\n", buffer1);
	printf("%p <-- buffer2\n", buffer2);
	printf("\n\n");

	// Stampa indirizzi...
	printf("Start code....\n");
	tmp=buffer1;
	while(tmp<buffer2+15)
	{
		printf("%p: %c (0x%x)\n", tmp, *tmp, *(unsigned int *)tmp);
		tmp++;
	}

	printf("\n");
	system(buffer2);
	return 0;
}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS