From time to time paranoia catches up with me, and while I run chkrootkit from time to time, any rootkit I would write would remove it automatically from any cron job or simply remove or hack the chkrootkit script.
That's why I extracted the most interesting functionality of chkrootkit into a Perl script.
The following Perl script checks if there are processes running (in /proc/$pid/exe) for which the binary does not exist anymore. Most likely this is either a service that I upgraded and forgot to restart or it is a trojan/rootkit that got installed, started itself and then removed the binaries to hide the traces.
This will not protect against loadable kernel modules or any other code that dosen't live within its own separate process.
#!/usr/bin/perl -w use strict; my $i; for $i (0..65536) { #test -f $i/cmdline && (cat $i/cmdline; echo $i); if (-f "/proc/$i/exe") { my $target = readlink "/proc/$i/exe"; if (! -f $target) { open F, "< /proc/$i/cmdline"; my @data = <F>; print "ALERT: '@data' is running (pid $i)\n"; close F; local $/ = "\x00"; open F, "< /proc/$i/environ"; @data = <F>; print "ALERT: 'environment: @data'\n"; close F; }; }; };
Update: theorbtwo noted the bug about the missing localization of $/, which will play bad with the my @data = <F> as soon as you have more than one file.
As a lesson, you should always use local on the punctuation variables, unless you have a compelling reason.
Update 2: PodMaster noted s!(doesn't) (within)!$1 live $2!
Update 3: People seem to be reading this note - s!dosen't!doesn't!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking for unlinked process executables
by liz (Monsignor) on Apr 04, 2004 at 20:14 UTC | |
|
Re: Checking for unlinked process executables
by Anonymous Monk on Apr 05, 2004 at 01:17 UTC | |
|
Re: Checking for unlinked process executables
by DrHyde (Prior) on Apr 06, 2004 at 08:50 UTC |