The called program can change its command line by simply overwriting argv as follows:
#include <stdlib.h> #include <string.h> int main(int argc, char** argv) { int arglen = argv[argc-1]+strlen(argv[argc-1])+1 - argv[0]; memset(argv[0], arglen, 0); strncpy(argv[0], "secret-program", arglen-1); sleep(100); }
Testing:
$ ./a.out mySuperPassword & $ ps -f UID PID PPID C STIME TTY TIME CMD me 20398 18872 0 11:26 pts/3 00:00:00 bash me 20633 20398 0 11:34 pts/3 00:00:00 secret-program me 20645 20398 0 11:34 pts/3 00:00:00 ps -f $
UPD: I know that it is not completely safe and can cause racial conditions, but many programs that accept a password from the command line do this trick.
source share