Here it is in Linux
avp@avp-ubu1:~/hashcode$ cat /etc/issue Ubuntu 12.04.2 LTS \n \l avp@avp-ubu1:~/hashcode$ uname -a Linux avp-ubu1 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux avp@avp-ubu1:~/hashcode$
it works (although I did not find /proc/self/comm
in man proc
, but it is "calculated")
avp@avp-ubu1:~/hashcode$ cat progname.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #define MY_NEW_NAME "new_prog_name" int main (int ac, char *av[]) { printf ("I want to change name from [%s] to [%s]\n", av[0], MY_NEW_NAME); fflush(stdout); system("ps"); puts ("Hit ENTER for continue..."); getchar(); int fd = open("/proc/self/comm",O_WRONLY); if (fd > 0) { write (fd,MY_NEW_NAME,strlen(MY_NEW_NAME)); close (fd); } else { perror("open"); } puts ("see result:"); system("ps"); return puts("End") == EOF; } avp@avp-ubu1:~/hashcode$ gcc progname.c avp@avp-ubu1:~/hashcode$ ./a.out I want to change name from [./a.out] to [new_prog_name] PID TTY TIME CMD 1919 pts/0 00:00:00 bash 2958 pts/0 00:00:00 a.out 2959 pts/0 00:00:00 sh 2960 pts/0 00:00:00 ps Hit ENTER for continue... see result: PID TTY TIME CMD 1919 pts/0 00:00:00 bash 2958 pts/0 00:00:00 new_prog_name 2961 pts/0 00:00:00 sh 2962 pts/0 00:00:00 ps End avp@avp-ubu1:~/hashcode$
I also want to add that the contents of /proc/self/cmdline
(the first element there is argv [0]) does not change, as well as the symbolic link /proc/self/exe
, which points to the executable file.
So, reliably deceiving the "serious" programs in this way (change the name for top, ps, ...) does not work.