Thread: [Netpass-devel] NetPass/bin appstarter.pl,1.5,1.6 import_nessus_scans.pl,1.5,1.6 npsvc.pl,1.6,1.7 up
Brought to you by:
jeffmurphy
From: jeff m. <jef...@us...> - 2005-08-22 19:26:18
|
Update of /cvsroot/netpass/NetPass/bin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3124/bin Modified Files: appstarter.pl import_nessus_scans.pl npsvc.pl update_nessus_plugins.sh Log Message: appstarter changes Index: import_nessus_scans.pl =================================================================== RCS file: /cvsroot/netpass/NetPass/bin/import_nessus_scans.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- import_nessus_scans.pl 8 May 2005 02:35:45 -0000 1.5 +++ import_nessus_scans.pl 22 Aug 2005 19:26:06 -0000 1.6 @@ -59,6 +59,8 @@ my ($dbuser, $dbpass) = exists $opts{'U'} ? split('/', $opts{'U'}) : (undef, undef); +$0 = "import_nessus_scans: connecting to NetPass"; + print "Loading Netpass object ..\n" if $D; my $np = new NetPass(-cstr => exists $opts{'c'} ? $opts{'c'} : undef, @@ -84,19 +86,22 @@ my $pass = $np->cfg->nessus(-key => 'password'); my $port = $np->cfg->nessus(-key => 'port'); -my $ncmd = "$bd/bin/nessus -q -p $host $port $user $pass "; +my $ncmd = "$bd/bin/nessus -c /dev/null -x -q -p $host $port $user $pass "; print qq{Nessus command is: "$ncmd"\n} if $D; +$0 = "import_nessus_scans: connecting to Nessus"; + open(FD, "$ncmd |") || die qq{open of "$ncmd" failed: $!}; my $query = "INSERT IGNORE INTO nessusScans (pluginID, name, family, category, short_desc, description, addedBy, lastModifiedBy, revision, copyright, cve, bugtraq, other_refs) VALUES (?,?,?,?,?,?,'import','import',?,?,?,?,?)"; my $sth = $dbh->prepare($query); - +my $sn = 0; print "Going into read loop ..\n" if $D; while(my $l = <FD>) { + $0 = "import_nessus_scans: importing scans ".$sn++; print qq{Read: "$l"} if $D; my ($id, $family, $name, $category, $copyright, $shortDesc, $revision, $cveId, $bugtraqId, $references, $description) = split(/\|/, $l); Index: update_nessus_plugins.sh =================================================================== RCS file: /cvsroot/netpass/NetPass/bin/update_nessus_plugins.sh,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- update_nessus_plugins.sh 3 Aug 2005 02:46:07 -0000 1.1 +++ update_nessus_plugins.sh 22 Aug 2005 19:26:06 -0000 1.2 @@ -1,5 +1,9 @@ #!/bin/sh -/usr/local/bin/nessus-fetch --plugins +cd /tmp +/usr/local/sbin/nessus-update-plugins +# after the plugins are updated, nessus thinks for a bit +# before you can connect to it. +sleep 300 /opt/netpass/bin/import_nessus_scans.pl exit 0 Index: npsvc.pl =================================================================== RCS file: /cvsroot/netpass/NetPass/bin/npsvc.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- npsvc.pl 16 Aug 2005 19:38:33 -0000 1.6 +++ npsvc.pl 22 Aug 2005 19:26:06 -0000 1.7 @@ -128,19 +128,19 @@ my $smtp = Net::SMTP->new($mailserver); if (!$smtp) { - warn("There was a problem sending email..."); - } - - use Sys::Hostname; - my $shn = (split(/\./, hostname))[0]; - $shn ||= hostname; - $smtp->mail($from); - $smtp->to($to); - $smtp->data(); - $smtp->datasend("Subject: $shn: $subject"); - $smtp->datasend("\n\n\n"); - $smtp->datasend($shn.":\n\n".$mesg); - $smtp->quit; + _log("WARNING", "There was a problem creating the SMTP object.\n"); + } else { + use Sys::Hostname; + my $shn = (split(/\./, hostname))[0]; + $shn ||= hostname; + $smtp->mail($from); + $smtp->to($to); + $smtp->data(); + $smtp->datasend("Subject: $shn: $subject"); + $smtp->datasend("\n\n\n"); + $smtp->datasend($shn.":\n\n".$mesg); + $smtp->quit; + } return (1); } @@ -202,7 +202,7 @@ my $child = fork; return if (defined($child) && ($child > 0)); # parent - setsid or _log("WARN", "$$ child failed to setsid $!\n"); + setsid or _log("WARNING", "$$ child failed to setsid $!\n"); _log("DEBUG", "$$ inchild change to uid=$uid gid=$gid\n"); Index: appstarter.pl =================================================================== RCS file: /cvsroot/netpass/NetPass/bin/appstarter.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- appstarter.pl 10 Aug 2005 19:52:15 -0000 1.5 +++ appstarter.pl 22 Aug 2005 19:26:06 -0000 1.6 @@ -133,6 +133,10 @@ use RUNONCE; use NetPass::LOG qw(_log _cont); +use Proc::ProcessTable; +use Sys::Hostname; + + my $myName = "appstarter"; my %opts; @@ -197,20 +201,20 @@ foreach my $row (@$x) { if ($row->[2] eq "start") { - if (isRunning($row->[1])) { + if (isRunning($row)) { _log("WARNING", $row->[1]. " is already running, so wont start another copy.\n"); - # behavior is to ack the duplicate.XXX } else { start($row); } } elsif ($row->[2] eq "stop") { - if (!isRunning($row->[1])) { + if (!isRunning($row)) { _log("WARNING", $row->[1]. " is not running, so cant stop.\n"); } else { stop($row) unless !isRunning($row->[1]); } } + $np->db->ackAppAction($row->[0]); } } @@ -220,14 +224,14 @@ } sub isRunning { - my $cn = shift; + my $row = shift; + my $cn = $row->[1]; _log("DEBUG", "isRunning $cn\n") if $D; my @pids = (); if ($cn =~ /^([u]{0,1}[n]{0,1})quarall$/) { - use Proc::ProcessTable; my $pt = new Proc::ProcessTable; my $un = $1; foreach my $pte (@{$pt->table}) { @@ -237,13 +241,24 @@ _log("DEBUG", "isRunning looking for $cn found: ".join(',',@pids)."\n") if $D; return @pids; } + + if ($cn eq "reload_nessus_plugins") { + my $pt = new Proc::ProcessTable; + foreach my $pte (@{$pt->table}) { + push @pids, $pte->pid + if ($pte->cmndline =~ /(nessus-fetch|nessus-update-plugins|import_nessus_scans)/); + } + _log("DEBUG", "isRunning looking for $cn found: ".join(',',@pids)."\n") if $D; + return @pids; + } + _log("DEBUG", "shouldnt be here\n"); } sub start { my $row = shift; - my ($rowid, $cmd, $junk, $as) = @$row; + my ($rowid, $cmd, $junk, $as, $hn) = @$row; if ($cmd eq "quarall") { runAs("/opt/netpass/bin/bulk_moveport.pl -N 0.0.0.0/0 -a quarantine", $as); @@ -251,15 +266,57 @@ elsif ($cmd eq "unquarall") { runAs("/opt/netpass/bin/bulk_moveport.pl -N 0.0.0.0/0 -a unquarantine", $as); } + elsif ($cmd eq "reload_nessus_plugins") { + runAs("/opt/netpass/bin/update_nessus_plugins.sh", $as); + } } sub stop { - my $cmd = shift; + my $row = shift; + my ($rowid, $cmd, $junk, $as, $hn) = @$row; + my @pids; + if ($cmd eq "quarall") { # search for "reset: quarantine" + + my $pt = new Proc::ProcessTable; + my $un = $1; + foreach my $pte (@{$pt->table}) { + push @pids, $pte->pid + if ($pte->cmndline =~ /^reset:\squarantine/); + } + _log("DEBUG", "stopping $cmd pids: ".join(',',@pids)."\n") if $D; + kill 9, @pids; + return @pids; } elsif ($cmd eq "unquarall") { # search for "reset: unquarantine" + + my $pt = new Proc::ProcessTable; + my $un = $1; + foreach my $pte (@{$pt->table}) { + push @pids, $pte->pid + if ($pte->cmndline =~ /^reset:\sunquarantine/); + } + _log("DEBUG", "stopping $cmd pids: ".join(',',@pids)."\n") if $D; + kill 9, @pids; + return @pids; + } + elsif ($cmd eq "reload_nessus_plugins") { + # search for "nessus-fetch" + # search for "nessus-update-plugins" + # search for "import_nessus_scans" + # search for "update_nessus_plugins.sh" + + my $pt = new Proc::ProcessTable; + my $un = $1; + foreach my $pte (@{$pt->table}) { + push @pids, $pte->pid + if ($pte->cmndline =~ /(nessus-fetch|nessus-update-plugins|import_nessus_scans|update_nessus_plugins\.sh)/); + } + _log("DEBUG", "stopping $cmd pids: ".join(',',@pids)."\n") if $D; + kill 9, @pids; + return @pids; } } @@ -281,8 +338,6 @@ my $child = fork; return if (defined($child) && ($child > 0)); # parent - #open STDIN, '/dev/null'; - #open STDOUT, '>/dev/null'; setsid or _log("WARN", "$$ child failed to setsid $!\n"); _log("DEBUG", "$$ inchild change to uid=$uid gid=$gid\n"); @@ -300,6 +355,8 @@ } { _log("DEBUG", qq{$$ in child. calling exec\n}) if $D; + open STDIN, '/dev/null'; + open STDOUT, '>/dev/null'; exec($cmd); } _log("ERROR", "child $$ failed to exec($cmd) $!\n"); |