Skript för att migrera Nessus rapporter

Jag hade behov av att migrera en massa gamla scan rapporter från ett system till ett annat. Som jag helt föraktar återkommande manuellt arbete jag skrev några Perl-skript för att lösa problemet för mig.

exportReports.pl

use strict;
use warnings;
use Net::Nessus::XMLRPC;

# Settings
my $nessus_url = "https://127.0.0.1:8834";
my $nessus_user = "username";
my $nessus_pass = "password";
my $base_dir    = "C:\\Temp\\Nessus";
# Variables
my $xmlReport;
my $n = Net::Nessus::XMLRPC->new( $nessus_url, $nessus_user, $nessus_pass );
die "Cannot login to: " . $n->nurl . "\n" unless ( $n->logged_in );
print "Logged in\n";
my @reports = $n->report_list_uids();
for my $report (@reports) {
    for my $reportUID ( @{$report} ) {
        print "Report " . $reportUID . ": Downloading...";
        $xmlReport = $n->report_file_download($reportUID);
        print " Saving...";
        open( FH, ">" . $base_dir . "\\" . $reportUID . ".xml" );
        print FH $xmlReport;
        close(FH);
        print " Done!\n";
    }
}
$n->logout();
print "Export completed!";



importReports.pl

use Net::Nessus::XMLRPC;

# Settings
my $nessus_url  = "https://127.0.0.1:8834";
my $nessus_user = "username";
my $nessus_pass = "password";
my $base_dir    = "C:\\Temp\\Nessus";
# Variables
my $xmlReport;
my $n = Net::Nessus::XMLRPC->new( $nessus_url, $nessus_user, $nessus_pass );
die "Cannot login to: " . $n->nurl . "\n" unless ( $n->logged_in );
print "Logged in\n";
print "Reading dir...";
opendir( DIR, $base_dir . "\\." );
@reports = grep( /\.xml$/, readdir(DIR) );
closedir(DIR);
print " Done!\n";
foreach $report (@reports) {
    print "Uploading report " . $report . "...";
    #$n->report_import_file ( $base_dir . "\\" . $report ); # Didn't work for me
    print " Reading...";
    {
        local $/ = undef;
        open FILE, $base_dir . "\\" . $report or die "Couldn't open file: $!";
        binmode FILE;
        $xmlReport = <FILE>;
        close FILE;
    }
    print " Uploading...";
    my $filename = $n->upload( $report, $xmlReport );
    print " Importing...";
    $n->report_import($filename);
    print " Done!\n";
}
$n->logout();
print "Done importing reports!" 


Om du fått nytta av skripten eller har förslag hur man gör det bättre lämna gärna en kommentar. Tack!

/Michael Boman

0 kommentarer :: Skript för att migrera Nessus rapporter

Skicka en kommentar