#!/usr/bin/perl
# nmap2html.pl, distributed as part of Snortsnarf v021111.1
# Author: Joe McAlerney, Silicon Defense, joey@silicondefense.com
# copyright (c) 2000 by Silicon Defense (http://www.silicondefense.com/)
# Released under GNU General Public License, see the COPYING file included
# with the distribution or http://www.silicondefense.com/software/snortsnarf/
# for details.
# nmap2html.pl is a Nmap log output script to html. A large amount of code
# was borrowed from the nlog tool, by spinux.
# Please send complaints, kudos, and especially improvements and bugfixes to
# joey@SiliconDefense.com. As described in GNU General Public License, no
# warranty is expressed for this program.
# grab our parameters from cmd line
$datefile = $ARGV[0];
$dbfile = $ARGV[1];
$cgidir = "/cgi-bin";
if ($dbfile eq "" ) {
print "Usage: # nmaplog []\n" .
"Note: optional second parameter needed to extract the " .
"scan date and time\n";
exit 1;
}
# <1> Sean Boran: improve Title
if ($datefile ne "" ) {
# Unfortunately, log2db.pl does not preserve the scan date and time.
# We are forced to extract that information out of the original log file.
open(DATEFILE,"<$datefile")
|| warn "Can't open $datefile: $!\n";
$dateline = ;
# <1> better title
while () { # catch first and last line
if(/^#\s(.+)\sas/) {
$dateline=$dateline . $1 . ",";
}
elsif (/^#\sNmap run completed at(.+) scanned in \d+ seconds/) {
$dateline=$dateline . $1;
}
}
close(DATEFILE);
}
else {
# <1> can't get date from DATEFILE; so use today
$dateline = "Nmap scan results on `date`\n";
}
# open the index.html file, and print header info
open(INDEX,">index.html");
print INDEX "".
"\n" .
"Nmap scan results" .
"\n" .
"
$dateline
\n" .
"IP Address\n" .
"\n";
# open our database and loop through it by line
open(NDB, $dbfile) || die "Can't open database: $!\n";
while (){
(@db_parse) = split(/\|/,$_);
$ch_ipaddress = $db_parse[0];
$ch_portnum = $db_parse[1];
$ch_ports = $db_parse[2];
$ch_status = $db_parse[3];
$ch_seqindex = $db_parse[4];
$ch_os = $db_parse[5];
@ch_ports = split(/,/,$ch_ports);
if($ch_ipaddress ne "") {
open(HOSTFILE,">$ch_ipaddress.html") || die "can't open $ch_ipaddress file\n";
print INDEX "$ch_ipaddress \n";
print HOSTFILE
"".
"\n" .
"Nmap scan of host $ch_ipaddress" .
"\n" .
"