line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SecurityCenter::API::Scan; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
926
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
138
|
|
7
|
2
|
|
|
2
|
|
1188
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
2798
|
|
|
2
|
|
|
|
|
12
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
703
|
use parent 'Net::SecurityCenter::Base'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
155
|
use Net::SecurityCenter::Utils qw(:all); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
3012
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.300'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $common_template = { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
id => { |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
20
|
|
|
|
|
|
|
messages => { |
21
|
|
|
|
|
|
|
required => 'Scan ID is required', |
22
|
|
|
|
|
|
|
allow => 'Invalid Scan ID', |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
filter => { |
27
|
|
|
|
|
|
|
allow => [ 'usable', 'manageable' ] |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
fields => { |
31
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
# METHODS |
38
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %args ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $single_id_filter = sub { |
45
|
0
|
|
|
0
|
|
0
|
return { 'id' => $_[0] }; |
46
|
0
|
|
|
|
|
0
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $array_ids_filter = sub { |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
|
0
|
my $data = []; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
foreach my $id ( @{ $_[0] } ) { |
|
0
|
|
|
|
|
0
|
|
53
|
0
|
|
|
|
|
0
|
push( @{$data}, { 'id' => $id } ); |
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
return $data; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $report_filter = sub { |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
0
|
|
0
|
my $data = []; |
63
|
0
|
|
|
|
|
0
|
my $report_types = [ 'cumulative', 'patched', 'individual', 'lce', 'archive', 'mobile' ]; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
require Params::Check; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
foreach my $id ( keys %{ $_[0] } ) { |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
my $type = $_[0]->{$id}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
0
|
if ( !Params::Check::allow( $type, @{$report_types} ) ) { |
|
0
|
|
|
|
|
0
|
|
72
|
0
|
|
|
|
|
0
|
croak( "Invalid 'reports ($type) value (allowed values: " . join( ', ', @{$report_types} ) . ')' ); |
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
push( @{$data}, { 'id' => $id, 'reportSource' => $type } ); |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
return $data; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $tmpl = { |
84
|
|
|
|
|
|
|
name => { |
85
|
|
|
|
|
|
|
required => 1, |
86
|
|
|
|
|
|
|
errors => { required => 'Specify scan name' } |
87
|
|
|
|
|
|
|
}, |
88
|
|
|
|
|
|
|
description => {}, |
89
|
|
|
|
|
|
|
targets => { |
90
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
91
|
|
|
|
|
|
|
remap => 'ipList' |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
assets => { |
94
|
|
|
|
|
|
|
filter => \&$array_ids_filter, |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
zone => { |
97
|
|
|
|
|
|
|
allow => qr/\d+/, |
98
|
|
|
|
|
|
|
errors => { allow => 'Invalid Scan Zone ID' }, |
99
|
|
|
|
|
|
|
filter => \&$single_id_filter |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
policy => { |
102
|
|
|
|
|
|
|
allow => qr/\d+/, |
103
|
|
|
|
|
|
|
errors => { allow => 'Invalid Policy ID' }, |
104
|
|
|
|
|
|
|
filter => \&$single_id_filter |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
plugin => { |
107
|
|
|
|
|
|
|
allow => qr/\d+/, |
108
|
|
|
|
|
|
|
errors => { allow => 'Invalid Plugin ID' }, |
109
|
|
|
|
|
|
|
filter => \&$single_id_filter |
110
|
|
|
|
|
|
|
}, |
111
|
|
|
|
|
|
|
repository => { |
112
|
|
|
|
|
|
|
allow => qr/\d+/, |
113
|
|
|
|
|
|
|
errors => { allow => 'Invalid Repository ID' }, |
114
|
|
|
|
|
|
|
filter => \&$single_id_filter |
115
|
|
|
|
|
|
|
}, |
116
|
|
|
|
|
|
|
credentials => { |
117
|
|
|
|
|
|
|
filter => \&$array_ids_filter, |
118
|
|
|
|
|
|
|
}, |
119
|
|
|
|
|
|
|
max_time => { |
120
|
|
|
|
|
|
|
allow => qr/\d+/, |
121
|
|
|
|
|
|
|
remap => 'maxScanTime' |
122
|
|
|
|
|
|
|
}, |
123
|
|
|
|
|
|
|
email_on_launch => { |
124
|
|
|
|
|
|
|
remap => 'emailOnLaunch', |
125
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
126
|
|
|
|
|
|
|
allow => qr/\d/, |
127
|
|
|
|
|
|
|
}, |
128
|
|
|
|
|
|
|
email_on_finish => { |
129
|
|
|
|
|
|
|
remap => 'emailOnFinish', |
130
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
131
|
|
|
|
|
|
|
allow => qr/\d/, |
132
|
|
|
|
|
|
|
}, |
133
|
|
|
|
|
|
|
dhcp_tracking => { |
134
|
|
|
|
|
|
|
remap => 'dhcpTracking', |
135
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
136
|
|
|
|
|
|
|
allow => qr/\d/, |
137
|
|
|
|
|
|
|
}, |
138
|
|
|
|
|
|
|
reports => { |
139
|
|
|
|
|
|
|
filter => \&$report_filter, |
140
|
|
|
|
|
|
|
}, |
141
|
|
|
|
|
|
|
type => { |
142
|
|
|
|
|
|
|
allow => [ 'plugin', 'policy' ] |
143
|
|
|
|
|
|
|
}, |
144
|
|
|
|
|
|
|
timeout => { |
145
|
|
|
|
|
|
|
allow => [ 'discard', 'import', 'rollover' ], |
146
|
|
|
|
|
|
|
remap => 'timeoutAction', |
147
|
|
|
|
|
|
|
}, |
148
|
|
|
|
|
|
|
schedule => { |
149
|
|
|
|
|
|
|
filter => sub { |
150
|
0
|
|
|
0
|
|
0
|
return sc_schedule( %{ $_[0] } ); |
|
0
|
|
|
|
|
0
|
|
151
|
|
|
|
|
|
|
}, |
152
|
|
|
|
|
|
|
}, |
153
|
0
|
|
|
|
|
0
|
rollover => { |
154
|
|
|
|
|
|
|
allow => [ 'nextDay', 'template' ], |
155
|
|
|
|
|
|
|
remap => 'rolloverType', |
156
|
|
|
|
|
|
|
}, |
157
|
|
|
|
|
|
|
scan_vhost => { |
158
|
|
|
|
|
|
|
remap => 'scanningVirtualHosts' |
159
|
|
|
|
|
|
|
}, |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
0
|
my $params = sc_check_params( $tmpl, \%args ); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
croak('"policy" and "plugin" are not allowed in same time') |
165
|
0
|
0
|
0
|
|
|
0
|
if ( defined( $params->{'policy'} ) && defined( $params->{'plugin'} ) ); |
166
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
0
|
if ( !defined( $params->{'type'} ) ) { |
168
|
0
|
0
|
|
|
|
0
|
$params->{'type'} = ( $params->{'policy'} ) ? 'policy' : 'plugin'; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
0
|
my $result = $self->client->post( '/scan', $params ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Return the Scan Result ID for schedule=now scans |
174
|
0
|
0
|
|
|
|
0
|
if ( defined( $result->{'scanResultID'} ) ) { |
175
|
0
|
|
|
|
|
0
|
return $result->{'scanResultID'}; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# Return the Scan ID |
179
|
0
|
0
|
|
|
|
0
|
if ( defined( $result->{'id'} ) ) { |
180
|
0
|
|
|
|
|
0
|
return $result->{'id'}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub execute { |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %params ) = @_; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
0
|
$params{'schedule'} = { 'type' => 'now' }; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
0
|
return $self->add(%params); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub launch { |
200
|
|
|
|
|
|
|
|
201
|
1
|
|
|
1
|
1
|
5
|
my ( $self, %args ) = @_; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $tmpl = { |
204
|
|
|
|
|
|
|
diagnostic_target => { remap => 'diagnosticTarget' }, |
205
|
|
|
|
|
|
|
diagnostic_password => { remap => 'diagnosticPassword' }, |
206
|
1
|
|
|
|
|
9
|
id => $common_template->{'id'}, |
207
|
|
|
|
|
|
|
}; |
208
|
|
|
|
|
|
|
|
209
|
1
|
|
|
|
|
6
|
my $params = sc_check_params( $tmpl, \%args ); |
210
|
1
|
|
|
|
|
4
|
my $scan_id = delete( $params->{'id'} ); |
211
|
1
|
|
|
|
|
5
|
my $result = $self->client->post( "/scan/$scan_id/launch", $params ); |
212
|
|
|
|
|
|
|
|
213
|
1
|
50
|
|
|
|
5
|
if ( !defined( $result->{'scanResult'}->{'id'} ) ) { |
214
|
0
|
|
|
|
|
0
|
croak('Invalid response from SecurityCenter'); # TODO |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
13
|
return $result->{'scanResult'}->{'id'}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub list { |
224
|
|
|
|
|
|
|
|
225
|
1
|
|
|
1
|
1
|
4
|
my ( $self, %args ) = @_; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $tmpl = { |
228
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
229
|
1
|
|
|
|
|
8
|
filter => $common_template->{'filter'}, |
230
|
|
|
|
|
|
|
raw => {}, |
231
|
|
|
|
|
|
|
}; |
232
|
|
|
|
|
|
|
|
233
|
1
|
|
|
|
|
5
|
my $params = sc_check_params( $tmpl, \%args ); |
234
|
1
|
|
|
|
|
6
|
my $raw = delete( $params->{'raw'} ); |
235
|
1
|
|
|
|
|
17
|
my $scans = $self->client->get( '/scan', $params ); |
236
|
|
|
|
|
|
|
|
237
|
1
|
50
|
|
|
|
6
|
return if ( !$scans ); |
238
|
1
|
50
|
|
|
|
5
|
return $scans if ($raw); |
239
|
1
|
|
|
|
|
7
|
return sc_merge($scans); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub get { |
245
|
|
|
|
|
|
|
|
246
|
1
|
|
|
1
|
0
|
5
|
my ( $self, %args ) = @_; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
my $tmpl = { |
249
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
250
|
1
|
|
|
|
|
5
|
id => $common_template->{'id'}, |
251
|
|
|
|
|
|
|
}; |
252
|
|
|
|
|
|
|
|
253
|
1
|
|
|
|
|
5
|
my $params = sc_check_params( $tmpl, \%args ); |
254
|
1
|
|
|
|
|
4
|
my $scan_id = delete( $params->{'id'} ); |
255
|
1
|
|
|
|
|
4
|
my $raw = delete( $params->{'raw'} ); |
256
|
1
|
|
|
|
|
5
|
my $scan = $self->client->get( "/scan/$scan_id", $params ); |
257
|
|
|
|
|
|
|
|
258
|
1
|
50
|
|
|
|
6
|
return if ( !$scan ); |
259
|
1
|
50
|
|
|
|
8
|
return $scan if ($scan); |
260
|
0
|
|
|
|
|
|
return sc_normalize_hash($scan); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub delete { |
267
|
|
|
|
|
|
|
|
268
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
|
my $tmpl = { id => $common_template->{'id'}, }; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $params = sc_check_params( $tmpl, \%args ); |
273
|
0
|
|
|
|
|
|
my $scan_id = delete( $params->{'id'} ); |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
return $self->client->delete("/scan/$scan_id"); # TODO |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |