| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # $Id: ScanDetails.pm 142 2009-10-16 19:13:45Z jabra $ | 
| 2 |  |  |  |  |  |  | package Nikto::Parser::ScanDetails; | 
| 3 |  |  |  |  |  |  | { | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 5 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 2112 | use Object::InsideOut; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 8 | 1 |  |  | 1 |  | 570 | use XML::LibXML; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | use Nikto::Parser::Host; | 
| 10 |  |  |  |  |  |  | use Nikto::Parser::Host::Port; | 
| 11 |  |  |  |  |  |  | use Nikto::Parser::Host::Port::Item; | 
| 12 |  |  |  |  |  |  | my @hosts : Field : Arg(hosts) : Get(hosts) : | 
| 13 |  |  |  |  |  |  | Type(List(Nikto::Parser::Host)); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub parse { | 
| 16 |  |  |  |  |  |  | my ( $self, $parser, $doc ) = @_; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | my $xpc = XML::LibXML::XPathContext->new($doc); | 
| 19 |  |  |  |  |  |  | my @hosts; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | foreach my $h ( $xpc->findnodes('//niktoscan/scandetails') ) { | 
| 22 |  |  |  |  |  |  | my $ip       = $h->getAttribute('targetip'); | 
| 23 |  |  |  |  |  |  | my $hostname = $h->getAttribute('targethostname'); | 
| 24 |  |  |  |  |  |  | my @ports; | 
| 25 |  |  |  |  |  |  | my $host = Nikto::Parser::Host->new( | 
| 26 |  |  |  |  |  |  | ip       => $ip, | 
| 27 |  |  |  |  |  |  | hostname => $hostname, | 
| 28 |  |  |  |  |  |  | ports    => \@ports, | 
| 29 |  |  |  |  |  |  | ); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | foreach my $scandetail ( | 
| 32 |  |  |  |  |  |  | $xpc->findnodes( | 
| 33 |  |  |  |  |  |  | '//niktoscan/scandetails[@targetip="' . $ip . '"]' | 
| 34 |  |  |  |  |  |  | ) | 
| 35 |  |  |  |  |  |  | ) | 
| 36 |  |  |  |  |  |  | { | 
| 37 |  |  |  |  |  |  | my $port   = $scandetail->getAttribute('targetport'); | 
| 38 |  |  |  |  |  |  | my $banner = $scandetail->getAttribute('targetbanner'); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | my $start_scan_time = $scandetail->getAttribute('starttime'); | 
| 41 |  |  |  |  |  |  | my $sitename        = $scandetail->getAttribute('sitename'); | 
| 42 |  |  |  |  |  |  | my $siteip          = $scandetail->getAttribute('siteip'); | 
| 43 |  |  |  |  |  |  | my @items; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | my ( @stats, $elasped_scan_time, $end_scan_time, | 
| 46 |  |  |  |  |  |  | $items_tested, $items_found ); | 
| 47 |  |  |  |  |  |  | if (scalar( | 
| 48 |  |  |  |  |  |  | @{  $scandetail->getElementsByTagName('statistics') | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | ) > 0 | 
| 51 |  |  |  |  |  |  | ) | 
| 52 |  |  |  |  |  |  | { | 
| 53 |  |  |  |  |  |  | @stats = $scandetail->getElementsByTagName('statistics'); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | $elasped_scan_time = $stats[0]->getAttribute('elapsed'); | 
| 56 |  |  |  |  |  |  | $end_scan_time     = $stats[0]->getAttribute('endtime'); | 
| 57 |  |  |  |  |  |  | $items_tested = $stats[0]->getAttribute('itemstested'); | 
| 58 |  |  |  |  |  |  | $items_found  = $stats[0]->getAttribute('itemsfound'); | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | foreach my $i ( $scandetail->getElementsByTagName('item') ) { | 
| 62 |  |  |  |  |  |  | my $id        = $i->getAttribute('id'); | 
| 63 |  |  |  |  |  |  | my $osvdbid   = $i->getAttribute('osvdbid'); | 
| 64 |  |  |  |  |  |  | my $osvdblink = $i->getAttribute('osvdblink'); | 
| 65 |  |  |  |  |  |  | my $method    = $i->getAttribute('method'); | 
| 66 |  |  |  |  |  |  | my $description | 
| 67 |  |  |  |  |  |  | = @{ $i->getElementsByTagName('description') }[0] | 
| 68 |  |  |  |  |  |  | ->textContent(); | 
| 69 |  |  |  |  |  |  | my $uri | 
| 70 |  |  |  |  |  |  | = scalar( @{ $i->getElementsByTagName('uri') } ) > 0 | 
| 71 |  |  |  |  |  |  | ? @{ $i->getElementsByTagName('uri') }[0] | 
| 72 |  |  |  |  |  |  | ->textContent() | 
| 73 |  |  |  |  |  |  | : undef; | 
| 74 |  |  |  |  |  |  | my $namelink | 
| 75 |  |  |  |  |  |  | = scalar( @{ $i->getElementsByTagName('namelink') } ) | 
| 76 |  |  |  |  |  |  | > 0 | 
| 77 |  |  |  |  |  |  | ? @{ $i->getElementsByTagName('namelink') }[0] | 
| 78 |  |  |  |  |  |  | ->textContent() | 
| 79 |  |  |  |  |  |  | : undef; | 
| 80 |  |  |  |  |  |  | my $iplink | 
| 81 |  |  |  |  |  |  | = scalar( @{ $i->getElementsByTagName('iplink') } ) | 
| 82 |  |  |  |  |  |  | > 0 | 
| 83 |  |  |  |  |  |  | ? @{ $i->getElementsByTagName('iplink') }[0] | 
| 84 |  |  |  |  |  |  | ->textContent() | 
| 85 |  |  |  |  |  |  | : undef; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | my $item = Nikto::Parser::Host::Port::Item->new( | 
| 88 |  |  |  |  |  |  | id          => $id, | 
| 89 |  |  |  |  |  |  | osvdbid     => $osvdbid, | 
| 90 |  |  |  |  |  |  | osvdblink   => $osvdblink, | 
| 91 |  |  |  |  |  |  | method      => $method, | 
| 92 |  |  |  |  |  |  | description => $description, | 
| 93 |  |  |  |  |  |  | uri         => $uri, | 
| 94 |  |  |  |  |  |  | namelink    => $namelink, | 
| 95 |  |  |  |  |  |  | iplink      => $iplink, | 
| 96 |  |  |  |  |  |  | ); | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | push( @items, $item ); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | my $objport = Nikto::Parser::Host::Port->new( | 
| 102 |  |  |  |  |  |  | port              => $port, | 
| 103 |  |  |  |  |  |  | banner            => $banner, | 
| 104 |  |  |  |  |  |  | start_scan_time   => $start_scan_time, | 
| 105 |  |  |  |  |  |  | end_scan_time     => $end_scan_time, | 
| 106 |  |  |  |  |  |  | elasped_scan_time => $elasped_scan_time, | 
| 107 |  |  |  |  |  |  | sitename          => $sitename, | 
| 108 |  |  |  |  |  |  | siteip            => $siteip, | 
| 109 |  |  |  |  |  |  | items             => \@items, | 
| 110 |  |  |  |  |  |  | items_tested      => $items_tested, | 
| 111 |  |  |  |  |  |  | items_found       => $items_found | 
| 112 |  |  |  |  |  |  | ); | 
| 113 |  |  |  |  |  |  | push( @ports, $objport ); | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | $host->ports( \@ports ); | 
| 117 |  |  |  |  |  |  | push( @hosts, $host ); | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | return Nikto::Parser::ScanDetails->new( hosts => \@hosts ); | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | sub get_host_ip { | 
| 124 |  |  |  |  |  |  | my ( $self, $ip ) = @_; | 
| 125 |  |  |  |  |  |  | my @hosts = grep( $_->ip eq $ip, @{ $self->hosts } ); | 
| 126 |  |  |  |  |  |  | return $hosts[0]; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | sub get_host_hostname { | 
| 130 |  |  |  |  |  |  | my ( $self, $hostname ) = @_; | 
| 131 |  |  |  |  |  |  | my @hosts = grep( $_->hostname eq $hostname, @{ $self->hosts } ); | 
| 132 |  |  |  |  |  |  | return $hosts[0]; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | sub all_hosts { | 
| 136 |  |  |  |  |  |  | my ($self) = @_; | 
| 137 |  |  |  |  |  |  | my @hosts = @{ $self->hosts }; | 
| 138 |  |  |  |  |  |  | return @hosts; | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | sub print_hosts { | 
| 142 |  |  |  |  |  |  | my ($self) = @_; | 
| 143 |  |  |  |  |  |  | foreach my $host ( @{ $self->hosts } ) { | 
| 144 |  |  |  |  |  |  | print "IP: " . $host->ip . "\n"; | 
| 145 |  |  |  |  |  |  | print "Hostname: " . $host->hostname . "\n"; | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  | } | 
| 149 |  |  |  |  |  |  | 1; |