Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Nmap::Parser;
- ##############################################
- # Build host Entities from Nmap XML file #
- # Build host Entities by onair Nmap scan #
- # Build open ports Entities from host #
- # Default plase for XMLout - /root/ #
- # input is: /path/to/nmap.xml #
- # 192.168.0.0-192.168.0.255 #
- # 192.168.0.1 - previus scaned #
- # #
- # (c) r3dh4t #
- ##############################################
- my $np = new Nmap::Parser;
- my $netblock = $ARGV[0];
- print "<MaltegoMessage>\n<MaltegoTransformResponseMessage>\n<UIMessages>\n";
- print '<UIMessage MessageType="Inform">'."\n";
- if (grep(/^\//,$netblock)){
- # if Maltego input is path to Nmap XML file
- $infile = "$netblock";
- } else {
- if (grep(/-/,$netblock)){
- # if Maltego input is IP range, then deaggregate it to subnet mask for Nmap (ftp://ftp.opennet.ru/pub/sys/misk/ipcalc.pl)
- @netmask = `/usr/bin/perl ./ipcalc.pl $netblock`;
- $netscan = @netmask[1];
- system('nmap -PN -sS -F -O -sV --max-rtt-timeout 200ms -oX "/root/'.$netblock.'-nmap.xml" '.$netscan.' 2>&1');
- $infile = '/root/'.$netblock.'-nmap.xml';
- }else{
- # if Maltego INPUT is single IP - then create open port entities;
- $netscan = $netblock;
- &PortEntities($ARGV[1]); #In ARGV[1] Maltego sends infoarmation in <AdditionalFields> of Entity IPv4Address
- }
- }
- #my $infile = './netblock-nmap.xml';
- print "</UIMessage>\n</UIMessages>\n<Entities>\n";
- $np->parsefile($infile);
- #GETTING SCAN INFORMATION
- my $si = $np->get_session();
- for my $host ($np->all_hosts()){ # Get scanned hosts in network
- $counter = 0;
- $host->ipv4_addr();
- @hst = $host->tcp_ports; # If host is UP create Maltego Entity
- if (@hst){
- print '<Entity Type="maltego.IPv4Address"><Value>'.$host->ipv4_addr().'</Value><Weight>100</Weight><AdditionalFields>'."\n";
- print '<Field Name="hostname" DisplayName="hostname">'.$host->hostname().'</Field>'."\n";
- print '<Field Name="mac" DisplayName="MAC">'.$host->mac_addr().'</Field>'."\n";
- for $port ($host->tcp_ports()){ # Get host's service,ports,etc..
- $counter++;
- $service = $host->tcp_service($port);
- $os = $host->os_sig;
- $service_banner = $port.",".$service->name.",".$service->product.",".$service->version;
- $os_banner = $os->name.",".$os->family.",".$os->osgen();
- print '<Field Name="service'.$counter.'" DisplayName="Service">'.$service_banner.'</Field>'."\n";
- }
- print '<Field Name="os" DisplayName="System">'.$os_banner.'</Field>'."\n";
- print "</AdditionalFields></Entity>\n";
- }
- }
- print "</Entities>\n</MaltegoTransformResponseMessage>\n</MaltegoMessage>\n";
- sub PortEntities {
- print "</UIMessage>\n</UIMessages>\n<Entities>\n";
- @fields = split(/\#/,$ARGV[1]); # split <AdditionalFields> into array by "#"
- foreach (@fields) {
- @field = grep(/service/,$_); # make new array of greped values by "service'
- foreach (@field){
- if ($_){
- @field_name = split(/=/,$_); # get pure port info
- print '<Entity Type="maltego.service"><Value>'.$field_name[1].'</Value><Weight>100</Weight></Entity>'."\n";
- }
- }
- }
- print "</Entities>\n</MaltegoTransformResponseMessage>\n</MaltegoMessage>\n";
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement