Hi, I've made something: take what you want from it.
Be aware that this script needs a certain kind of tables; I've listed an
SQL of them at the bottom.
There might be lots of other ways to do this better though.
[nessusrun.pl]
#!/usr/bin/perl -w
use strict;
use DBI;
# Make sure to edit these variables so that they suit your needs
my $nessus_targetsfile = "~/securescan/targets"; # location of targetsfile
my $nessus_resultsfile = "~/securescan/results"; # location of resultsfile
my $nessus_exec = "/usr/local/bin/nessus"; # location of nessus binary
my $nessus_user = "";
my $nessus_password = "";
my $nessus_host = "";
my $nessus_port = "1241";
my $database = ""; # mysql database name
my $bruker = ""; # mysql user
my $vert = ""; # mysql host
my $passord = ""; # mysql password
# explode ~ to actual path.
$nessus_targetsfile =~ s{^~([^/]*)}{$1 ? (getpwnam($1))[7] : ( $ENV{HOME} ||
$ENV{LOGDIR} ) }ex;
$nessus_resultsfile =~ s{^~([^/]*)}{$1 ? (getpwnam($1))[7] : ( $ENV{HOME} ||
$ENV{LOGDIR} ) }ex;
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
# Main loop
my $nessus_target;
if (-e $nessus_targetsfile) {
open(TIN,"<$nessus_targetsfile");
while (<TIN>) {
$nessus_target .= $_;
}
close(TIN);
} else {
die("Couldn't find $nessus_targetsfile. Please ensure that the nessus executable is
in the right location.\n");
}
run_nessus();
my $dbh =
DBI->connect("DBI:mysql:database=$database;host=$vert;user=nessus,$bruker,$passord,{'printError'
=> 1, 'AutoCommit' => 1});
process_output();
$dbh->disconnect();
sub run_nessus {
my @exec_ary = ("$nessus_exec", "-q", "$nessus_host", "$nessus_port",
"$nessus_user", "$nessus_password", "$nessus_targetsfile", "$nessus_resultsfile");
unless (system(@exec_ary) == 0) { die("Couldn't run nessus: $!\n"); }
}
sub process_output {
# putt i execution
my $sth = $dbh->prepare("INSERT INTO execution (user,target) VALUES (?,?)");
$sth->execute($nessus_user,$nessus_target);
(my $exec_id, my @rest) = $dbh->selectrow_array("SELECT LAST_INSERT_ID()");
open(IN, "<$nessus_resultsfile");
while (<IN>) {
if (/^results/) {
my @line = split(/\|/,$_);
# insert line
my $sth = $dbh->prepare("INSERT INTO results
(exec_id,subnet,ip,script_id,portdescr) VALUES (?,?,?,?,?)");
$sth->execute($exec_id,$line[1],$line[2],$line[4],$line[3]);
} elsif ((/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) && (/(\|.*?){4}/)) {
my @line = split(/\|/,$_);
# insert line
my $sth = $dbh->prepare("INSERT INTO results (exec_id,ip,script_id,portdescr)
VALUES (?,?,?,?)");
$sth->execute($exec_id,$line[0],$line[2],$line[1]);
}
}
close(IN);
}
[/nessusrun.pl]
[nessus.sql]
-- MySQL dump 8.21
--
-- Host: localhost Database: nessus
---------------------------------------------------------
-- Server version 3.23.49-log
--
-- Table structure for table 'execution'
--
CREATE TABLE execution (
id int(11) NOT NULL auto_increment,
timestamp timestamp(14) NOT NULL,
user varchar(16) NOT NULL default '',
target text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
--
-- Table structure for table 'results'
--
CREATE TABLE results (
exec_id int(11) NOT NULL default '0',
subnet varchar(255) NOT NULL default '',
ip varchar(255) NOT NULL default '',
script_id int(11) NOT NULL default '0',
portdescr varchar(255) NOT NULL default ''
) TYPE=MyISAM;
--
-- Table structure for table 'rules'
--
CREATE TABLE rules (
script_id int(11) NOT NULL default '0',
script_version varchar(250) NOT NULL default '',
script_cve_id varchar(13) NOT NULL default '',
script_name varchar(250) NOT NULL default '',
script_desc text NOT NULL,
script_summary varchar(250) NOT NULL default '',
script_category varchar(30) NOT NULL default '',
script_highest_risk varchar(20) NOT NULL default 'None',
script_family varchar(50) NOT NULL default '',
script_timestamp timestamp(14) NOT NULL,
script_filename varchar(250) NOT NULL default '',
script_highest_risk_pri int(11) NOT NULL default '0',
PRIMARY KEY (script_id)
) TYPE=MyISAM;
[/nessus.sql]
---
Nicolas Mendoza
On Tue, 13 Aug 2002, Greg wrote:
> Hi -
>
> I would like to setup Nessus to scan my network using a cronjob, and I wanted
> the results to be imported into a MySQL database. Has anyone created a similar
> setup, and if so how would I go about doing it?
>
> Thanks,
>
> Greg
>
>
> -
> [EMAIL PROTECTED]: general discussions about Nessus.
> * To unsubscribe, send a mail to [EMAIL PROTECTED] with
> "unsubscribe nessus" in the body.
>
-
[EMAIL PROTECTED]: general discussions about Nessus.
* To unsubscribe, send a mail to [EMAIL PROTECTED] with
"unsubscribe nessus" in the body.