line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Parser.pm 142 2009-10-16 19:13:45Z jabra $ |
2
|
|
|
|
|
|
|
package Nikto::Parser; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
444360
|
use Object::InsideOut; |
|
7
|
|
|
|
|
434031
|
|
|
7
|
|
|
|
|
56
|
|
8
|
7
|
|
|
7
|
|
5324
|
use Nikto::Parser::Session; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my @session : Field : Arg(session) : Get(session) : |
10
|
|
|
|
|
|
|
Type(Nikto::Parser::Session); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# parse_file |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Input: |
15
|
|
|
|
|
|
|
# argument - self obj - |
16
|
|
|
|
|
|
|
# argument - xml scalar |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# Ouptut: |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
sub parse_file { |
21
|
|
|
|
|
|
|
my ( $self, $file ) = @_; |
22
|
|
|
|
|
|
|
my $parser = XML::LibXML->new(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $doc = $parser->parse_file($file); |
25
|
|
|
|
|
|
|
return Nikto::Parser->new( |
26
|
|
|
|
|
|
|
session => Nikto::Parser::Session->parse( $parser, $doc ) ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub parse_scan { |
30
|
|
|
|
|
|
|
my ( $self, $ndir, $args, @ips ) = @_; |
31
|
|
|
|
|
|
|
my $FH; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if ( $args =~ /-Format/ ) { |
34
|
|
|
|
|
|
|
die |
35
|
|
|
|
|
|
|
"[Nikto-Parser] Cannot pass option '-Format ' to parse_scan()"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ( $args =~ /-output/ ) { |
39
|
|
|
|
|
|
|
die |
40
|
|
|
|
|
|
|
"[Nikto-Parser] Cannot pass option '-output ' to parse_scan()"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
if ( -d $ndir ) { |
43
|
|
|
|
|
|
|
chdir $ndir or die "[Nikto-Parser] $ndir not a directory\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
|
|
|
|
|
|
die "[Nikto-Parser] $ndir not a directory\n"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $cmd = "./nikto.pl -Format xml -output \"-\" -host " |
50
|
|
|
|
|
|
|
. ( join ' ', @ips ); |
51
|
|
|
|
|
|
|
print "$cmd\n"; |
52
|
|
|
|
|
|
|
open $FH, "$cmd |" |
53
|
|
|
|
|
|
|
|| die "[Nikto-Parser] Could not perform nikto scan - $!"; |
54
|
|
|
|
|
|
|
my $p = XML::LibXML->new(); |
55
|
|
|
|
|
|
|
my $doc = $p->parse_fh($FH); |
56
|
|
|
|
|
|
|
my $parser = Nikto::Parser->new( |
57
|
|
|
|
|
|
|
session => Nikto::Parser::Session->parse( $p, $doc ) ); |
58
|
|
|
|
|
|
|
close $FH; |
59
|
|
|
|
|
|
|
return $parser; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# return the session information for the current nikto scan |
63
|
|
|
|
|
|
|
sub get_session { |
64
|
|
|
|
|
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
my $session = $self->session; |
66
|
|
|
|
|
|
|
return $session; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# return the host obj based on an ip address |
70
|
|
|
|
|
|
|
sub get_host { |
71
|
|
|
|
|
|
|
my ( $self, $ip ) = @_; |
72
|
|
|
|
|
|
|
my $host_obj = $self->session->scandetails->get_host_ip($ip); |
73
|
|
|
|
|
|
|
return $host_obj; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# return an ArrayRef containing all of the host objs |
77
|
|
|
|
|
|
|
sub get_all_hosts { |
78
|
|
|
|
|
|
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
my @all_hosts = $self->session->scandetails->all_hosts(); |
80
|
|
|
|
|
|
|
return @all_hosts; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|