#!/usr/bin/perl # $Source$ # # By Dave Dittrich - dittrich@cac.washington.edu # http://www.washington.edu/People/dad/ # # This program relies on the following programs: # o Hobbit's "netcat" program (a.k.a. "nc") # # o Safe finger # # o nmap # # # Gather as much information as possible about an intruder's system # as long as (s)he stays online. (I guess there is also an opportunity # to fight back to defend yourself, but I'll leave that as an excercise # for the reader at this point). chop($ZERO=`basename $0`); # Default constants. $DEFLOG = "$ZERO.log"; $DEFSLEEP = 60; $FINGER="finger"; $NMAP="/usr/local/bin/nmap"; $NC="/usr/local/bin/nc"; require "newgetopt.pl"; sub usage { print STDERR < 0 && $ARGV[0] =~ /^-+[^-]+/; @ARGV = ("-") unless @ARGV > 0; $host = shift(@ARGV); &usage() if ($opt_help || $host eq "-"); $SEP= "============================================================================"; # Keep track of what services we obtained the first time, so we don't # keep trying unavailable ones. $finger = $netstat = $systat = 1; ($target,$aliases,$addrtype,$length,@addrs) = gethostbyname($host); select(STDERR); $| = 1; select(STDOUT); $| = 1; $SIG{'HUP'} = 'handler'; $log = ($opt_log) ? $opt_log : $DEFLOG; $sleep = ($opt_sleep > 0) ? $opt_sleep : $DEFSLEEP; $opt_repeat = (defined $opt_repeat) ? $opt_repeat : 1; $repeat = ($opt_repeat > 0) ? $opt_repeat : 1; open(O, ">$log") || die "can't open $log: $!"; select(O); $| = 1; select(STDOUT); print STDOUT "This process is $$\n"; print STDOUT "Log file is $log\n" unless $opt_quiet; print O <&1", O); do { # Get dynamic data, and keep on getting it while the system is # alive. unless (!$finger) { print STDERR "Fingering \@$target\n" unless $opt_quiet; $finger = &getnreport("finger", "echo \"\" | $NC $target 79", O); } unless (!$netstat) { print STDERR "Getting netstat\n" unless $opt_quiet; $netstat = &getnreport("netstat", "$NC $target 15", O); } unless (!$systat) { print STDERR "Getting systat\n" unless $opt_quiet; $systat = &getnreport("systat", "$NC $target 11", O); } --$repeat unless ($opt_repeat == 0); if ($repeat && &alive($target)) { print STDERR "sleeping $sleep seconds..." unless $opt_quiet; sleep($sleep); print STDERR "(yawn)\n" unless $opt_quiet; } else { $die++; } } while ($repeat && ! $die); close(O); exit(0); sub alive { my($t) = @_; my($p) = `$NMAP -P $target | grep -n "appears to be up"`; return ($p); } sub handler { $die++; return; } sub getnreport { my($title,$cmd,$fh) = @_; my($lines) = 0; open(I,"$cmd |") || die "can't open pipe for \"$cmd\": $!\n"; print $fh "$title [command: $cmd]\n", scalar localtime, "\n\n"; while() { $lines++; print $fh $_; } close(I); print $fh "Nothing available for $title\n" unless $lines; print $fh "$SEP\n"; return $lines; }