1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #!/usr/bin/perl
# (C) Kost. Distributed under GPL.
use Carp;
use warnings;
use strict;
use XML::Simple;
use Getopt::Long;
use Cwd;
use File::Spec;
use Data::Dumper;
my $fileperhost = 1;
my $repertoireCourant = getcwd;
my $nmapfile = File::Spec->catfile($repertoireCourant, 'leScan.xml');
my $mindmap = File::Spec->catfile($repertoireCourant, 'mapXmind.mm');
print "Repertoire courrant : $repertoireCourant\n";
print "nmapfile : $nmapfile\n";
print "mindmap : $mindmap\n";
$fileperhost=0;
print STDERR "Using $mindmap as output\n";
print STDERR "Processing $nmapfile...\n";
if ( ! -f $nmapfile ) { die "$nmapfile not exists\n"; }
my $nmapxml = XMLin($nmapfile, ForceArray => 1, KeyAttr => '');
my $mindfile=$mindmap;
if ($fileperhost == 0) {
open OFILE,'>', $mindfile or die ("Cannot open $mindmap for writting: $!");
print OFILE '<map version="0.7.1">'."\n";
print OFILE '<node TEXT="scan">'."\n";
print OFILE '<node TEXT="hosts">'."\n";
} else {
open GFILE, '>', "$mindmap.mm" or die ("Cannot open $mindmap for writting: $!");
print GFILE '<map version="0.7.1">'."\n";
print GFILE '<node TEXT="scan">'."\n";
print GFILE '<node TEXT="hosts">'."\n";
}
foreach my $host (@{$nmapxml->{'host'}}) {
my %hostinfo;
$mindfile=$mindmap."-".$host->{'address'}->[0]->{'addr'}.".mm";
if ($fileperhost == 1) {
open OFILE,'>', $mindfile or die ("Cannot open $mindmap for writting: $!");
print OFILE '<map version="0.7.1">'."\n";
print OFILE '<node TEXT="scan" LINK="'.$mindmap.'.mm">'."\n";
print OFILE '<node TEXT="hosts">'."\n";
print GFILE "<node TEXT=\"$host->{'address'}->[0]->{'addr'}\" LINK=\"$mindfile\">\n";
print GFILE "</node>\n"; # host
}
print OFILE "<node TEXT=\"$host->{'address'}->[0]->{'addr'}\">\n";
print OFILE '<node TEXT="dns">'."\n";
print OFILE "<node TEXT=\"$host->{'hostnames'}->[0]->{'hostname'}->[0]->{'name'}\"/>\n";
print OFILE "</node>\n"; # dns
print OFILE '<node TEXT="OS">'."\n";
if (($host->{'os'}->[0]->{'osclass'}) || ($host->{'os'}->[0]->{'osmatch'})) {
print OFILE "<node TEXT=\"$host->{'os'}->[0]->{'osclass'}->[0]->{'type'},$hostinfo{'name'}=$host->{'os'}->[0]->{'osmatch'}->[0]->{'name'},$hostinfo{'acc'}=$host->{'os'}->[0]->{'osmatch'}->[0]->{'accuracy'}\"/>\n";
}
print OFILE "</node>\n"; # OS
# print Dumper (@{$host->{'ports'}->[0]->{'port'}});
print OFILE '<node TEXT="ports">'."\n";
if (defined({$host->{'ports'}->[0]->{'port'}})) {
print OFILE '<node TEXT="open">'."\n";
if ({$host->{'ports'}->[0]->{'port'}}) {
foreach my $port (@{$host->{'ports'}->[0]->{'port'}}) {
my $fstate;
$fstate=$port->{'state'}->[0]->{'state'};
if ($fstate eq "open") {
print OFILE "<node TEXT=\"$port->{'protocol'}/$port->{'portid'}\">\n";
print OFILE "<node TEXT=\"$port->{'service'}->[0]->{'name'};$port->{'service'}->[0]->{'product'};$port->{'service'}->[0]->{'conf'}\"/>\n";
print OFILE "</node>\n";
}
} # foreach
} # not empty
print OFILE "</node>\n";
} # defined
if (defined({$host->{'ports'}->[0]->{'extraports'}})) {
if (({$host->{'ports'}->[0]->{'extraports'}})) {
print OFILE '<node TEXT="extra">'."\n";
foreach my $port (@{$host->{'ports'}->[0]->{'extraports'}}) {
print OFILE "<node TEXT=\"$port->{'state'}\">\n";
print OFILE "<node TEXT=\"$port->{'count'}\"/>\n";
print OFILE "</node>\n"; # state
}
print OFILE "</node>\n"; # extra
}
}
print OFILE "</node>\n"; # ports node
print OFILE "</node>\n"; # host node
if ($fileperhost == 1) {
print OFILE "</node>\n"; # hosts
print OFILE "</node>\n"; # scan
print OFILE "</map>\n";
close OFILE;
}
}
if ($fileperhost == 0) {
print OFILE "</node>\n"; # hosts
print OFILE "</node>\n"; # scan
print OFILE "</map>\n";
close OFILE;
} else {
print GFILE "</node>\n"; # hosts
print GFILE "</node>\n"; # scan
print GFILE "</map>\n";
close GFILE;
} |
Partager