#!/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" . "
$dateline
\n" . "
\n" . "$ch_ipaddress\n" . "" . " (resolve address)\n" . "
\n"; printheaders(HOSTFILE); } #print ("db_parse = @db_parse\nch_ports = @ch_ports\n"); foreach $port (@ch_ports) { @ch_port = split(/\./,$port); $cp_num = $ch_port[0]; $cp_state = $ch_port[1]; $cp_proto = $ch_port[2]; $cp_serv = $ch_port[3]; $cp_rpc = $ch_port[4]; if ($cp_serv eq "www") { $cp_serv = "http"; } elsif ($cp_serv eq "telnet") { $cp_serv = "telnet"; } elsif ($cp_serv eq "ftp") { $cp_serv = "ftp"; } elsif ($cp_serv eq "NetBIOS") { $cp_serv = "NetBIOS"; } # print the info to the file print HOSTFILE "$cp_num\n"; print HOSTFILE "$cp_proto\n"; print HOSTFILE "$cp_state\n"; print HOSTFILE "$cp_serv\n"; print HOSTFILE "$ch_seqindex\n"; print HOSTFILE "$ch_os\n"; } if($ch_ipaddress ne "") { print HOSTFILE "" . "
scan index\n" . "\n"; } } print INDEX "
\n" . "\n"; close NDB; sub printheaders { my $file = shift; print $file < port proto state service sequence os matches TABLEHEADER ; } exit 0;