LJ Archive

Listing 1. collector.pl

#!/usr/bin/perl -w

use Net::SSH::Perl;
use strict;

my %Cmds;
my $host = qw(192.168.10.5);
my $user = "root";

my @md5files = qw(/bin/login
                  /usr/bin/passwd
                  /bin/ps
                  /boot/vmlinuz-2.4.10);

my @configfiles = qw(/etc/passwd
                     /etc/shadow
                     /etc/inetd.conf
                     /etc/services);

$Cmds{'md5sigs'} = "md5sum @md5files";
$Cmds{'configs.tar'} = "tar cf - @configfiles";
$Cmds{'suidfiles'} = "find / -type f -perm        \
                               +6000 |xargs ls -l";

### main loop ###
for my $file (keys %Cmds) {
    my $cmd = $Cmds{$file};

    ### run each command on $host and print the
    ### output to $file
    &run_command($cmd, $file, $host);
}
exit 0;

sub run_command() {
    my ($cmd, $file, $host) = @_;

    ### turn on compression across the ssh session
    my $ssh = Net::SSH::Perl->new($host,         \
                                    compression=>1);
    $ssh->login($user);
    my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);

    open F, "> $file";
    print F $stdout;
    close F;
    return;
}
LJ Archive