line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TenableSC::Utils; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
60
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
54
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
7
|
1
|
|
|
1
|
|
10
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
8
|
1
|
|
|
1
|
|
5
|
use Term::ReadKey; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
20
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1130
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.311'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
config_parse_line |
17
|
|
|
|
|
|
|
config_parser |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
file_slurp |
20
|
|
|
|
|
|
|
trim |
21
|
|
|
|
|
|
|
dumper |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
cli_version |
24
|
|
|
|
|
|
|
cli_error |
25
|
|
|
|
|
|
|
cli_readkey |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub cli_error { |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
0
|
|
my ($error) = @_; |
34
|
0
|
|
|
|
|
|
$error =~ s/ at .* line \d+.*//; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $script_name = basename($0); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
print "$script_name ERROR: $error\n"; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
exit(255); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub cli_readkey { |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
0
|
0
|
|
my ($message) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $value = undef; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
print $message; |
51
|
0
|
|
|
|
|
|
ReadMode 'noecho'; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$value = ReadLine 0; |
54
|
0
|
|
|
|
|
|
chomp $value; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
ReadMode 'normal'; |
57
|
0
|
|
|
|
|
|
print "\n"; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $value; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub cli_version { |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
0
|
|
require IO::Socket::SSL; |
66
|
0
|
|
|
|
|
|
require LWP::UserAgent; |
67
|
0
|
|
|
|
|
|
require Net::SecurityCenter; |
68
|
0
|
|
|
|
|
|
require App::TenableSC; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
my $io_socket_ssl = ($IO::Socket::SSL::VERSION) ? $IO::Socket::SSL::VERSION : 'n/a'; |
71
|
0
|
0
|
|
|
|
|
my $lwp_useragent = ($LWP::UserAgent::VERSION) ? $LWP::UserAgent::VERSION : 'n/a'; |
72
|
0
|
|
|
|
|
|
my $script_name = basename($0); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
print <<"EOF"; |
75
|
|
|
|
|
|
|
$script_name v$VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
CORE |
78
|
|
|
|
|
|
|
Perl ($^V, $^O) |
79
|
|
|
|
|
|
|
Net::SecurityCenter ($Net::SecurityCenter::VERSION) |
80
|
|
|
|
|
|
|
App::TenableSC ($App::TenableSC::VERSION) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
MODULES |
83
|
|
|
|
|
|
|
LWP::UserAgent ($lwp_useragent) |
84
|
|
|
|
|
|
|
IO::Socket::SSL ($io_socket_ssl) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
EOF |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
exit 0; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub trim { |
93
|
0
|
|
|
0
|
0
|
|
Net::SecurityCenter::Utils::trim(@_); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub dumper { |
97
|
0
|
|
|
0
|
0
|
|
Net::SecurityCenter::Utils::dumper(@_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub file_slurp { |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
0
|
|
my ($file) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
open my $fh, '<', $file or croak("Can't open $file file: $!"); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $string = do { |
107
|
0
|
|
|
|
|
|
local $/ = undef; |
108
|
0
|
|
|
|
|
|
<$fh>; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
close $fh or croak("Failed to close $file file: $!"); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $string; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub config_parse_line { |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
0
|
|
my ($value) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
return 1 if ( $value =~ m/^(yes|true)$/s ); |
124
|
0
|
0
|
|
|
|
|
return 0 if ( $value =~ m/^(no|false)$/s ); |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if ( $value =~ /\,/ ) { |
127
|
0
|
|
|
|
|
|
return map { trim($_) } split /,/, $value; |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $value; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub config_parser { |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
0
|
|
my ($config_string) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $section = '_'; # Root section |
141
|
0
|
|
|
|
|
|
my $config_data = {}; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
foreach my $line ( split /\n/, $config_string ) { |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
chomp($line); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# skip comments and empty lines |
148
|
0
|
0
|
|
|
|
|
next if ( $line =~ m/^\s*([#;])/ ); |
149
|
0
|
0
|
|
|
|
|
next if ( $line =~ m/^\s*$/ ); |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^\[(.*)\]\s*$/ ) { |
152
|
0
|
|
|
|
|
|
$section = trim($1); |
153
|
0
|
|
|
|
|
|
next; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^([^=]+?)\s*=\s*(.*?)\s*$/ ) { |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my ( $field, $raw_value ) = ( $1, $2 ); |
159
|
0
|
|
|
|
|
|
my $parsed_value = [ config_parse_line($raw_value) ]; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
my $value = ( ( @{$parsed_value} == 1 ) ? $parsed_value->[0] : $parsed_value ); |
|
0
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
if ( not defined $section ) { |
164
|
0
|
|
|
|
|
|
$config_data->{$field} = $value; |
165
|
0
|
|
|
|
|
|
next; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$config_data->{$section}->{$field} = $value; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return $config_data; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=pod |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=encoding UTF-8 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 NAME |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
App::TenableSC::Utils - Utilities for App::TenableSC |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SYNOPSIS |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
use App::TenableSC::Utils qw(:all); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
print dumper( { 'foo' => 'bar' } ); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 DESCRIPTION |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This module provides Perl scripts easy way to interface the REST API of Tenable.sc |
200
|
|
|
|
|
|
|
(SecurityCenter). |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
For more information about the Tenable.sc (SecurityCenter) REST API follow the online documentation: |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 METHODS |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 SUPPORT |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 Bugs / Feature Requests |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Please report any bugs or feature requests through the issue tracker |
215
|
|
|
|
|
|
|
at L. |
216
|
|
|
|
|
|
|
You will be notified automatically of any progress on your issue. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 Source Code |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This is open source software. The code repository is available for |
221
|
|
|
|
|
|
|
public review and contribution under the terms of the license. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
git clone https://github.com/giterlizzi/perl-Net-SecurityCenter.git |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 AUTHOR |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over 4 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * Giuseppe Di Terlizzi |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This software is copyright (c) 2018-2023 by Giuseppe Di Terlizzi. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
242
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |