Example of how to overwrite argv in C

31. January 2012 08:00

 

A short code example to show how to overwrite the contents of argv. It is useful for when a password is passed on the command line and it should not be visible in the process list to other users on the same machine.

 

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

int main(int argc, char **argv) {
	int i = 0;
	int len = 0;

	if (argc < 2) {
		printf("Usage: %s <some argument>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	len = strlen(argv[1]);
	for(i=0;i<len;i++) {
		argv[1][i] = 'x';
	}

	system("ps f");

	return 0;
}

 

E-mail Kick it! DZone it! del.icio.us Permalink


Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading