#!/usr/bin/perl -w # This hackish script will examine each running process (ala /proc) an +d # try to determine if the program modified it's process name. # This is a common trick with 'malware': programs with malicious or hi +dden # intent. Of course, this script is not fool proof. # There are several publically available script kiddie tools (scanners +, sniffers # and the like) that this should detect. # --rpc <rpc@lilo.org> use strict; die 'this script has only been tested on linux.' unless $^O eq 'linux' +; for my $proc (</proc/*>) { next unless $proc =~ /(\d+)/; my $pid = $1; next if $pid == 1; # there's bigger problems if init is munged. open CMDLINE, "$proc/cmdline" or next; my $ret = sysread CMDLINE, (my $cmdline), 256; close CMDLINE; next if $ret == 0; # most kernel daemons have no cmdline. my($procname, $args) = $cmdline =~ m!^([^\0]+)\0(.*)$!; # User processes can NULL their process names, but they can't make + it # 0 bytes, like kernel daemons. If $procname is null yet we read m +ore # than 0 bytes from sysread, something's fishy. print "WARNING: PID $pid has NULL proccess name!\n" and next unles +s $procname; # Get the real name the process was invoked with. open STATUS, "$proc/status" or next; my($status) = <STATUS> or next; close STATUS; my($realname) = $status =~ m/Name:\s+(.*)/ or next; $procname =~ s!.*/([^/]+)$!$1!; if($procname !~ /$realname/) { my $matched = 0; for my $arg(split /\0/, $args) { if($arg =~ /$realname/) { print "PID $pid has MODIFIED process name, but may be +a script.($realname)\n"; $matched = 1; last; } } unless($matched) { print "WARNING: PID $pid has MODIFIED process name but doe +sn't look like a script ($realname)\n"; } } }

In reply to detect sneaky processes which modify their process name. by rpc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.