line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SecurityCenter::API::Plugin; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
763
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
100
|
|
7
|
2
|
|
|
2
|
|
801
|
use MIME::Base64; |
|
2
|
|
|
|
|
1092
|
|
|
2
|
|
|
|
|
96
|
|
8
|
2
|
|
|
2
|
|
12
|
use Params::Check qw(allow); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
11
|
use parent 'Net::SecurityCenter::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
106
|
use Net::SecurityCenter::Utils qw(:all); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1721
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.310'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $common_template = { |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
id => { |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
21
|
|
|
|
|
|
|
messages => { |
22
|
|
|
|
|
|
|
required => 'Plugin ID is required', |
23
|
|
|
|
|
|
|
allow => 'Invalid Plugin ID', |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
filter => { |
28
|
|
|
|
|
|
|
allow => [ 'usable', 'manageable' ], |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
fields => { |
32
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
# METHODS |
39
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub list { |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
1
|
3
|
my ( $self, %args ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $tmpl = { |
46
|
|
|
|
|
|
|
raw => {}, |
47
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
48
|
|
|
|
|
|
|
type => { |
49
|
|
|
|
|
|
|
allow => [ 'active', 'all', 'compliance', 'custom', 'lce', 'notPassive', 'passive' ], |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
sort_field => { |
52
|
|
|
|
|
|
|
allow => [ 'modifiedTime', 'id', 'name', 'family', 'type' ], |
53
|
|
|
|
|
|
|
remap => 'sortDirection', |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
start_offset => { |
56
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
57
|
|
|
|
|
|
|
remap => 'startOffset', |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
end_offset => { |
60
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
61
|
|
|
|
|
|
|
remap => 'endOffset', |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
sort_direction => { |
64
|
|
|
|
|
|
|
allow => [ 'ASC', 'DESC' ], |
65
|
|
|
|
|
|
|
remap => 'sortDirection', |
66
|
0
|
|
|
0
|
|
0
|
filter => sub { uc $_[0] }, |
67
|
|
|
|
|
|
|
}, |
68
|
1
|
|
|
|
|
42
|
since => { |
69
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
filter_field => { |
72
|
|
|
|
|
|
|
allow => [ |
73
|
|
|
|
|
|
|
'copyright', 'description', 'exploitAvailable', 'family', |
74
|
|
|
|
|
|
|
'id', 'name', 'patchPubDate', 'patchModDate', |
75
|
|
|
|
|
|
|
'pluginPubDate', 'pluginModDate', 'sourceFile', 'type', |
76
|
|
|
|
|
|
|
'version', 'vulnPubDate', 'xrefs', 'xrefs:ALAS', |
77
|
|
|
|
|
|
|
'xrefs:APPLE-SA', 'xrefs:AUSCERT', 'xrefs:BID', 'xrefs:CERT', |
78
|
|
|
|
|
|
|
'xrefs:CERT-CC', 'xrefs:CERT-FI', 'xrefs:CERTA', 'xrefs:CISCO-BUG-ID', |
79
|
|
|
|
|
|
|
'xrefs:CISCO-SA', 'xrefs:CISCO-SR', 'xrefs:CLSA', 'xrefs:CONECTIVA', |
80
|
|
|
|
|
|
|
'xrefs:CVE', 'xrefs:CWE', 'xrefs:DSA', 'xrefs:EDB-ID', |
81
|
|
|
|
|
|
|
'xrefs:FEDORA', 'xrefs:FLSA', 'xrefs:FreeBSD', 'xrefs:GLSA', |
82
|
|
|
|
|
|
|
'xrefs:HP', 'xrefs:HPSB', 'xrefs:IAVA', 'xrefs:IAVB', |
83
|
|
|
|
|
|
|
'xrefs:IAVT', 'xrefs:ICS-ALERT', 'xrefs:ICSA', 'xrefs:MDKSA', |
84
|
|
|
|
|
|
|
'xrefs:MDVSA', 'xrefs:MGASA', 'xrefs:MSFT', 'xrefs:MSVR', |
85
|
|
|
|
|
|
|
'xrefs:NSFOCUS', 'xrefs:NessusID', 'xrefs:OSVDB', 'xrefs:OWASP', |
86
|
|
|
|
|
|
|
'xrefs:OpenPKG-SA', 'xrefs:RHSA', 'xrefs:SSA', 'xrefs:Secunia', |
87
|
|
|
|
|
|
|
'xrefs:SuSE', 'xrefs:TLSA', 'xrefs:TSLSA', 'xrefs:USN', |
88
|
|
|
|
|
|
|
'xrefs:VMSA', 'xrefs:zone-h' |
89
|
|
|
|
|
|
|
], |
90
|
|
|
|
|
|
|
remap => 'filterField', |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
op => { |
93
|
|
|
|
|
|
|
allow => [ 'eq', 'gt', 'gte', 'like', 'lt', 'lte' ] |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
value => {}, |
96
|
|
|
|
|
|
|
filter => {}, |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
1
|
50
|
|
|
|
6
|
if ( defined( $args{'filter'} ) ) { |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
0
|
if ( ref $args{'filter'} ne 'ARRAY' ) { |
102
|
0
|
|
|
|
|
0
|
carp "Filter is not ARRAY"; |
103
|
0
|
|
|
|
|
0
|
croak 'Usage: ' . __PACKAGE__ . '->list ( filter => [ FIELD, OPERATOR, VALUE ], ... )'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
my ( $filter_field, $operator, $value ) = @{ $args{'filter'} }; |
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
$args{'filter_field'} = $filter_field; |
109
|
0
|
|
|
|
|
0
|
$args{'op'} = $operator; |
110
|
0
|
|
|
|
|
0
|
$args{'value'} = $value; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
delete( $args{'filter'} ); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
4
|
my $params = sc_check_params( $tmpl, \%args ); |
117
|
1
|
|
|
|
|
3
|
my $raw = delete( $params->{'raw'} ); |
118
|
1
|
|
|
|
|
4
|
my $plugins = $self->client->get( '/plugin', $params ); |
119
|
|
|
|
|
|
|
|
120
|
1
|
50
|
|
|
|
5
|
return if ( !$plugins ); |
121
|
|
|
|
|
|
|
|
122
|
1
|
50
|
|
|
|
4
|
if ($raw) { |
123
|
0
|
0
|
|
|
|
0
|
return wantarray ? @{$plugins} : $plugins; |
|
0
|
|
|
|
|
0
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
7
|
return wantarray ? @{ sc_normalize_array($plugins) } : sc_normalize_array($plugins); |
|
0
|
|
|
|
|
0
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub get { |
133
|
|
|
|
|
|
|
|
134
|
1
|
|
|
1
|
1
|
4
|
my ( $self, %args ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $tmpl = { |
137
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
138
|
1
|
|
|
|
|
6
|
id => $common_template->{'id'}, |
139
|
|
|
|
|
|
|
raw => {}, |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
4
|
my $params = sc_check_params( $tmpl, \%args ); |
143
|
1
|
|
|
|
|
2
|
my $raw = delete( $params->{'raw'} ); |
144
|
1
|
|
|
|
|
4
|
my $plugin_id = delete( $params->{'id'} ); |
145
|
1
|
|
|
|
|
13
|
my $plugin = $self->client->get( "/plugin/$plugin_id", $params ); |
146
|
|
|
|
|
|
|
|
147
|
1
|
50
|
|
|
|
5
|
return if ( !$plugin ); |
148
|
1
|
50
|
|
|
|
5
|
return $plugin if ($raw); |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
4
|
return sc_normalize_hash($plugin); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub download { |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $tmpl = { |
161
|
|
|
|
|
|
|
filename => {}, |
162
|
0
|
|
|
|
|
|
id => $common_template->{'id'}, |
163
|
|
|
|
|
|
|
}; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my $params = sc_check_params( $tmpl, \%args ); |
166
|
0
|
|
|
|
|
|
my $plugin_id = delete( $params->{'id'} ); |
167
|
0
|
|
|
|
|
|
my $filename = delete( $params->{'filename'} ); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $plugin_data = $self->client->get( "/plugin/$plugin_id", { 'fields' => 'id,source' } )->{'source'}; |
170
|
0
|
|
|
|
|
|
my $plugin_source = decode_base64($plugin_data); |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
return $plugin_source if ( !$filename ); |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
open my $fh, '>', $filename |
175
|
|
|
|
|
|
|
or croak("Could not open file '$filename': $!"); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
print $fh $plugin_source; |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
close $fh |
180
|
|
|
|
|
|
|
or carp("Failed to close file '$filename': $!"); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return 1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |