5569l1 Listing 1. collector.pl 1 #!/usr/bin/perl -w 2 3 use Net::SSH::Perl; 4 use strict; 5 6 my %Cmds; 7 my $host = qw(192.168.10.5); 8 my $user = "root"; 9 10 my @md5files = qw(/bin/login 11 /usr/bin/passwd 12 /bin/ps 13 /boot/vmlinuz-2.4.10); 14 15 my @configfiles = qw(/etc/passwd 16 /etc/shadow 17 /etc/inetd.conf 18 /etc/services); 19 20 $Cmds{'md5sigs'} = "md5sum @md5files"; 21 $Cmds{'configs.tar'} = "tar cf - @configfiles"; 23 $Cmds{'suidfiles'} = "find / -type f -perm \ 24 +6000 |xargs ls -l"; 25 26 ### main loop ### 27 for my $file (keys %Cmds) { 28 my $cmd = $Cmds{$file}; 29 30 ### run each command on $host and print the 31 ### output to $file 32 &run_command($cmd, $file, $host); 33 } 34 exit 0; 35 36 sub run_command() { 37 my ($cmd, $file, $host) = @_; 38 39 ### turn on compression across the ssh session 40 my $ssh = Net::SSH::Perl->new($host, \ 41 compression=>1); 42 $ssh->login($user); 43 my ($stdout, $stderr, $exit) = $ssh->cmd($cmd); 44 45 open F, "> $file"; 46 print F $stdout; 47 close F; 48 return; 49 }