I have been working on a project that uses PIDs, /proc and command line analysis to validate processes on a system. My code had to be checked by the security guys who manage to break it with a single line... embarrassing!
#!/usr/bin/env perl
$0="I am running wild"; # I had no clue you can do this!
system("cat /proc/$$/cmdline");
print("\n");
system("ps -ef | grep $$");
# do bad stuff here...
My questions:
I see some uses cases for the above, like hiding passwords given on the command line (also bad practice) but I see a lot more problems/issues when one can hide processes and spoof
cmdline. Is there a reason it is allowed? Isn't it a system vulnerability?How can I prevent or detect this? I have looked into
/procmount options. I also know that one can uselsofto identify spoofed processes based on unexpected behavior, but this won't work in my case. At the moment I am using a simple method to detect if thecmdlinecontains at least one null (\0) character which assumes that at least one argument is present. In the above code, spaces need to be replaced with nulls to bypass that check which is something I couldn't find how to implement in Perl - writes up to the first\0.