| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: ScanDetails.pm 18 2008-05-05 23:55:18Z jabra $ |
|
2
|
|
|
|
|
|
|
package NexposeSimpleXML::Parser::ScanDetails; |
|
3
|
|
|
|
|
|
|
{ |
|
4
|
1
|
|
|
1
|
|
2212
|
use Object::InsideOut; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
1
|
|
|
1
|
|
544
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use NexposeSimpleXML::Parser::Host; |
|
7
|
|
|
|
|
|
|
use NexposeSimpleXML::Parser::Host::Service; |
|
8
|
|
|
|
|
|
|
use NexposeSimpleXML::Parser::Fingerprint; |
|
9
|
|
|
|
|
|
|
use NexposeSimpleXML::Parser::Vulnerability; |
|
10
|
|
|
|
|
|
|
use NexposeSimpleXML::Parser::Reference; |
|
11
|
|
|
|
|
|
|
my @hosts : Field : Arg(hosts) : Get(hosts) : |
|
12
|
|
|
|
|
|
|
Type(List(NexposeSimpleXML::Parser::Host)); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub parse { |
|
15
|
|
|
|
|
|
|
my ( $self, $parser, $doc ) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $xpc = XML::LibXML::XPathContext->new($doc); |
|
18
|
|
|
|
|
|
|
my @hosts; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
foreach my $h ( $xpc->findnodes('//NeXposeSimpleXML/devices/device') ) |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
|
|
|
|
|
|
my $ip = $h->getAttribute('address'); |
|
23
|
|
|
|
|
|
|
my @services; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my (@vulns, $fp, $fp_certainty, |
|
26
|
|
|
|
|
|
|
$fp_description, $fp_vendor, $fp_family, |
|
27
|
|
|
|
|
|
|
$fp_product, $fp_version, $fp_class |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
foreach my $f ( $h->findnodes('fingerprint') ) { |
|
30
|
|
|
|
|
|
|
$fp_certainty = $f->getAttribute('certainty'); |
|
31
|
|
|
|
|
|
|
$fp_description |
|
32
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('description') } ) |
|
33
|
|
|
|
|
|
|
> 0 |
|
34
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('description') }[0] |
|
35
|
|
|
|
|
|
|
->textContent() |
|
36
|
|
|
|
|
|
|
: undef; |
|
37
|
|
|
|
|
|
|
$fp_device_class |
|
38
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('device-class') } ) |
|
39
|
|
|
|
|
|
|
> 0 |
|
40
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('device-class') }[0] |
|
41
|
|
|
|
|
|
|
->textContent() |
|
42
|
|
|
|
|
|
|
: undef; |
|
43
|
|
|
|
|
|
|
$fp_vendor |
|
44
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('vendor') } ) > 0 |
|
45
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('vendor') }[0] |
|
46
|
|
|
|
|
|
|
->textContent() |
|
47
|
|
|
|
|
|
|
: undef; |
|
48
|
|
|
|
|
|
|
$fp_family |
|
49
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('family') } ) > 0 |
|
50
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('family') }[0] |
|
51
|
|
|
|
|
|
|
->textContent() |
|
52
|
|
|
|
|
|
|
: undef; |
|
53
|
|
|
|
|
|
|
$fp_product |
|
54
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('product') } ) > 0 |
|
55
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('product') }[0] |
|
56
|
|
|
|
|
|
|
->textContent() |
|
57
|
|
|
|
|
|
|
: undef; |
|
58
|
|
|
|
|
|
|
$fp_version |
|
59
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('version') } ) > 0 |
|
60
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('version') }[0] |
|
61
|
|
|
|
|
|
|
->textContent() |
|
62
|
|
|
|
|
|
|
: undef; |
|
63
|
|
|
|
|
|
|
$fp_arch |
|
64
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('architecture') } ) |
|
65
|
|
|
|
|
|
|
> 0 |
|
66
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('architecture') }[0] |
|
67
|
|
|
|
|
|
|
->textContent() |
|
68
|
|
|
|
|
|
|
: undef; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
$host_fp = NexposeSimpleXML::Parser::Fingerprint->new( |
|
72
|
|
|
|
|
|
|
certainty => $fp_certainty, |
|
73
|
|
|
|
|
|
|
description => $fp_description, |
|
74
|
|
|
|
|
|
|
family => $fp_family, |
|
75
|
|
|
|
|
|
|
version => $fp_version, |
|
76
|
|
|
|
|
|
|
product => $fp_product, |
|
77
|
|
|
|
|
|
|
vendor => $fp_vendor, |
|
78
|
|
|
|
|
|
|
arch => $fp_arch, |
|
79
|
|
|
|
|
|
|
device_class => $fp_device_class, |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my @host_vulns; |
|
83
|
|
|
|
|
|
|
foreach my $v ( $h->findnodes('vulnerabilities/vulnerability') ) { |
|
84
|
|
|
|
|
|
|
my @refs; |
|
85
|
|
|
|
|
|
|
foreach my $r ( $v->findnodes('id') ) { |
|
86
|
|
|
|
|
|
|
my $ref = NexposeSimpleXML::Parser::Reference->new( |
|
87
|
|
|
|
|
|
|
id => $r->textContent(), |
|
88
|
|
|
|
|
|
|
type => $r->getAttribute('type'), |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
push( @refs, $ref ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
my $vuln = NexposeSimpleXML::Parser::Vulnerability->new( |
|
93
|
|
|
|
|
|
|
id => $v->getAttribute('id'), |
|
94
|
|
|
|
|
|
|
result_code => $v->getAttribute('resultCode'), |
|
95
|
|
|
|
|
|
|
references => \@refs, |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
push( @host_vulns, $vuln ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
foreach my $s ( $h->findnodes('services/service') ) { |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my ( @vulns, $fp, $fp_certainty, $fp_description, $fp_vendor, |
|
103
|
|
|
|
|
|
|
$fp_family, $fp_product, $fp_version ); |
|
104
|
|
|
|
|
|
|
foreach my $f ( $s->findnodes('fingerprint') ) { |
|
105
|
|
|
|
|
|
|
$fp_certainty = $f->getAttribute('certainty'); |
|
106
|
|
|
|
|
|
|
$fp_description |
|
107
|
|
|
|
|
|
|
= scalar( |
|
108
|
|
|
|
|
|
|
@{ $f->getElementsByTagName('description') } ) > 0 |
|
109
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('description') }[0] |
|
110
|
|
|
|
|
|
|
->textContent() |
|
111
|
|
|
|
|
|
|
: undef; |
|
112
|
|
|
|
|
|
|
$fp_vendor |
|
113
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('vendor') } ) |
|
114
|
|
|
|
|
|
|
> 0 |
|
115
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('vendor') }[0] |
|
116
|
|
|
|
|
|
|
->textContent() |
|
117
|
|
|
|
|
|
|
: undef; |
|
118
|
|
|
|
|
|
|
$fp_family |
|
119
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('family') } ) |
|
120
|
|
|
|
|
|
|
> 0 |
|
121
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('family') }[0] |
|
122
|
|
|
|
|
|
|
->textContent() |
|
123
|
|
|
|
|
|
|
: undef; |
|
124
|
|
|
|
|
|
|
$fp_product |
|
125
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('product') } ) |
|
126
|
|
|
|
|
|
|
> 0 |
|
127
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('product') }[0] |
|
128
|
|
|
|
|
|
|
->textContent() |
|
129
|
|
|
|
|
|
|
: undef; |
|
130
|
|
|
|
|
|
|
$fp_version |
|
131
|
|
|
|
|
|
|
= scalar( @{ $f->getElementsByTagName('version') } ) |
|
132
|
|
|
|
|
|
|
> 0 |
|
133
|
|
|
|
|
|
|
? @{ $f->getElementsByTagName('version') }[0] |
|
134
|
|
|
|
|
|
|
->textContent() |
|
135
|
|
|
|
|
|
|
: undef; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
$fp = NexposeSimpleXML::Parser::Fingerprint->new( |
|
139
|
|
|
|
|
|
|
certainty => $fp_certainty, |
|
140
|
|
|
|
|
|
|
family => $fp_family, |
|
141
|
|
|
|
|
|
|
version => $fp_version, |
|
142
|
|
|
|
|
|
|
product => $fp_product, |
|
143
|
|
|
|
|
|
|
vendor => $fp_vendor, |
|
144
|
|
|
|
|
|
|
description => $fp_description, |
|
145
|
|
|
|
|
|
|
); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
foreach |
|
148
|
|
|
|
|
|
|
my $v ( $s->findnodes('vulnerabilities/vulnerability') ) |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
|
|
|
|
|
|
my @refs; |
|
151
|
|
|
|
|
|
|
foreach my $r ( $v->findnodes('id') ) { |
|
152
|
|
|
|
|
|
|
my $ref = NexposeSimpleXML::Parser::Reference->new( |
|
153
|
|
|
|
|
|
|
id => $r->textContent(), |
|
154
|
|
|
|
|
|
|
type => $r->getAttribute('type'), |
|
155
|
|
|
|
|
|
|
); |
|
156
|
|
|
|
|
|
|
push( @refs, $ref ); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
my $vuln = NexposeSimpleXML::Parser::Vulnerability->new( |
|
159
|
|
|
|
|
|
|
id => $v->getAttribute('id'), |
|
160
|
|
|
|
|
|
|
result_code => $v->getAttribute('resultCode'), |
|
161
|
|
|
|
|
|
|
references => \@refs, |
|
162
|
|
|
|
|
|
|
); |
|
163
|
|
|
|
|
|
|
push( @vulns, $vuln ); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $service = NexposeSimpleXML::Parser::Host::Service->new( |
|
168
|
|
|
|
|
|
|
name => $s->getAttribute('name'), |
|
169
|
|
|
|
|
|
|
protocol => $s->getAttribute('protocol'), |
|
170
|
|
|
|
|
|
|
port => $s->getAttribute('port'), |
|
171
|
|
|
|
|
|
|
fingerprint => $fp, |
|
172
|
|
|
|
|
|
|
vulnerabilities => \@vulns, |
|
173
|
|
|
|
|
|
|
); |
|
174
|
|
|
|
|
|
|
push( @services, $service ); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
my $host = NexposeSimpleXML::Parser::Host->new( |
|
177
|
|
|
|
|
|
|
address => $ip, |
|
178
|
|
|
|
|
|
|
fingerprint => $host_fp, |
|
179
|
|
|
|
|
|
|
services => \@services, |
|
180
|
|
|
|
|
|
|
vulnerabilities => \@host_vulns, |
|
181
|
|
|
|
|
|
|
); |
|
182
|
|
|
|
|
|
|
push( @hosts, $host ); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
return NexposeSimpleXML::Parser::ScanDetails->new( hosts => \@hosts ); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub get_host_ip { |
|
189
|
|
|
|
|
|
|
my ( $self, $ip ) = @_; |
|
190
|
|
|
|
|
|
|
my @hosts = grep( $_->address eq $address, @{ $self->hosts } ); |
|
191
|
|
|
|
|
|
|
return $hosts[0]; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub all_hosts { |
|
195
|
|
|
|
|
|
|
my ($self) = @_; |
|
196
|
|
|
|
|
|
|
my @hosts = @{ $self->hosts }; |
|
197
|
|
|
|
|
|
|
return @hosts; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
1; |