File Coverage

blib/lib/Parse/Nessus/XML.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Parse::Nessus::XML;
2 2     2   70920 use strict;
  2         6  
  2         93  
3 2     2   1055 use XML::Simple qw();
  0            
  0            
4              
5             use vars qw($VERSION);
6             $VERSION = (qw($Revision: 1.14 $))[1];
7              
8             # Documentation {{{
9              
10             =head1 NAME
11              
12             Parse::Nessus::XML - Interface to Nessus XML result files
13              
14             =head1 SYNOPSIS
15              
16             use Parse::Nessus::XML
17             my $scan = Parse::Nessus::XML->new( $filename );
18             my @results = $scan->results;
19              
20             my $plugin = $scan->plugin(10964); # Parse::Nessus::XML::Plugin object
21             my $name = $plugin->name;
22              
23             =head1 DESCRIPTION
24              
25             Provides an interface to the Nessus XML report file. This is primarily
26             for my own use, so if it's missing stuff that you think should be in
27             here, send me a patch.
28              
29             Please note that this API is just a suggestion, and is subject to change
30             in the first few releases. Because of how deeply nested the data
31             structure is, there's no particularly nice API to the whole thing - at
32             least that I can think of. See the example script in the example/
33             subdirectory to see how I use this in real life.
34              
35             =cut
36              
37             # }}}
38              
39             # sub new {{{
40              
41             =head2 new
42              
43             my $scan = Parse::Nessus::XML->new( $filename );
44              
45             Given the path to a file, returns a Parse::Nessus::XML object.
46              
47             =cut
48              
49             sub new {
50             my ( $class, $file ) = @_;
51             @XML::Simple::DefKeyAttr = qw(id);
52             my $scan = XML::Simple::XMLin(
53             $file,
54             KeyAttr => {
55             plugin => 'id',
56             ports => 'portid'
57             },
58             );
59              
60             my $self = bless( $scan, ref($class) || $class );
61             return ($self);
62             } # }}}
63              
64             # sub results {{{
65              
66             =head2 results
67              
68             my $results = $scan->results; # listref
69             my @results = $scan->results; # list
70              
71             =cut
72              
73             sub results {
74             my $self = shift;
75             return wantarray ? @{ $self->{results}->{result} }
76             : $self->{results}->{result};
77             } # }}}
78              
79             # sub plugin {{{
80              
81             =head2 plugin
82              
83             Returns a plugin object, given the ID. Then you can call for attributes
84             off of that object.
85              
86             my $plugin = $scan->plugin(10964);
87             $name = $plugin->name;
88             $risk = $plugin->risk;
89              
90             =cut
91              
92             sub plugin {
93             my $scan = shift;
94             my $ID = shift;
95              
96             return unless $ID;
97             return Parse::Nessus::XML::Plugin->new( $scan, ID => $ID );
98             } # }}}
99              
100             1;
101              
102             # Parse::Nessus::XML::Plugin {{{
103              
104             =head2 package Parse::Nessus::XML::Plugin
105              
106             Supplementary package which facilitates figuring out what's in a
107             particular plugin. Also allows location of a plugin by ID number, which
108             speeds things up.
109              
110             =cut
111              
112             package Parse::Nessus::XML::Plugin;
113             use vars qw($AUTOLOAD);
114              
115             =head2 Parse::Nessus::XML::Plugin->new
116              
117             my $plugin = Parse::Nessus::XML::Plugin->new( $scan, ID => 10964 );
118             my $risk = $plugin->risk;
119              
120             Available attributes are: id, name, version, family, cve_id, bugtraq_id,
121             category, risk, summary, copyright
122              
123             =cut
124              
125             sub new {
126             my $class = shift;
127             my $self = {};
128              
129             my $scan = shift;
130             my %attribs = @_;
131              
132             if ($attribs{ID}) {
133             $self = $scan->{plugins}{plugin}{$attribs{ID}};
134             $self->{id} = $attribs{ID};
135             } else {
136             warn "No ID given, so I don't know what plugin you wanted.";
137             }
138              
139             bless $self, $class;
140             return $self;
141             }
142              
143             sub AUTOLOAD {
144             my $self = shift;
145             my $attrib = $AUTOLOAD;
146             $attrib =~ s/.*:://;
147             return $self->{$attrib} || undef;
148             }
149              
150             1;
151              
152             # End package }}}
153              
154             =head1 AUTHOR
155              
156             Rich Bowen
157             CPAN ID: RBOW
158             rbowen@rcbowen.com
159             http://rich.rcbowen.com/
160              
161             =head1 COPYRIGHT
162              
163             This program is free software; you can redistribute
164             it and/or modify it under the same terms as Perl itself.
165              
166             The full text of the license can be found in the
167             LICENSE file included with this module.
168              
169             =head1 SEE ALSO
170              
171             Parse::Nessus::NBE
172              
173             =cut
174