line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package QualysGuard::Request; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
122831
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
229
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
862
|
use QualysGuard::Response; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use LWP::UserAgent; |
8
|
|
|
|
|
|
|
use HTTP::Request; |
9
|
|
|
|
|
|
|
use URI::Escape; |
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $QUALYS_FUNCTIONS = { |
15
|
|
|
|
|
|
|
'asset_data_report' => 1, |
16
|
|
|
|
|
|
|
'asset_domain' => 1, |
17
|
|
|
|
|
|
|
'asset_domain_list' => 1, |
18
|
|
|
|
|
|
|
'asset_group' => 1, |
19
|
|
|
|
|
|
|
'asset_group_delete' => 1, |
20
|
|
|
|
|
|
|
'asset_group_list' => 1, |
21
|
|
|
|
|
|
|
'asset_ip' => 1, |
22
|
|
|
|
|
|
|
'asset_ip_list' => 1, |
23
|
|
|
|
|
|
|
'asset_range_info' => 1, |
24
|
|
|
|
|
|
|
'asset_search' => 1, |
25
|
|
|
|
|
|
|
'get_host_info' => 1, |
26
|
|
|
|
|
|
|
'get_tickets' => 1, |
27
|
|
|
|
|
|
|
'iscanner_list' => 1, |
28
|
|
|
|
|
|
|
'map' => 1, |
29
|
|
|
|
|
|
|
'map-2' => 1, |
30
|
|
|
|
|
|
|
'map_report' => 1, |
31
|
|
|
|
|
|
|
'map_report_list' => 1, |
32
|
|
|
|
|
|
|
'report_template_list' => 1, |
33
|
|
|
|
|
|
|
'scan' => 1, |
34
|
|
|
|
|
|
|
'scan_cancel' => 1, |
35
|
|
|
|
|
|
|
'scan_options' => 1, |
36
|
|
|
|
|
|
|
'scan_report' => 1, |
37
|
|
|
|
|
|
|
'scan_report_delete' => 1, |
38
|
|
|
|
|
|
|
'scan_report_list' => 1, |
39
|
|
|
|
|
|
|
'scan_running_list' => 1, |
40
|
|
|
|
|
|
|
'scan_target_history' => 1, |
41
|
|
|
|
|
|
|
'scheduled_scans' => 1, |
42
|
|
|
|
|
|
|
'ticket_delete' => 1, |
43
|
|
|
|
|
|
|
'ticket_edit' => 1, |
44
|
|
|
|
|
|
|
'ticket_list' => 1, |
45
|
|
|
|
|
|
|
'ticket_list_deleted' => 1, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$QualysGuard::Request::Username = undef; |
49
|
|
|
|
|
|
|
$QualysGuard::Request::Password = undef; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
# new |
53
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
54
|
|
|
|
|
|
|
sub new { |
55
|
|
|
|
|
|
|
my ( $class, $function ) = @_; |
56
|
|
|
|
|
|
|
my $self = bless {}, ref($class) || $class; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( ! exists $QUALYS_FUNCTIONS->{$function} ) { |
59
|
|
|
|
|
|
|
croak "Qualys function '$function' does not exist"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->{function} = $function; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
70
|
|
|
|
|
|
|
# attributes |
71
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
72
|
|
|
|
|
|
|
sub attributes { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
my $attr = shift; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
while ( my ($a,$v) = each( %$attr ) ) { |
77
|
|
|
|
|
|
|
$self->{a}{lc($a)} = $v; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return $self->{a}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
86
|
|
|
|
|
|
|
# submit |
87
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
88
|
|
|
|
|
|
|
sub submit { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
my $url = $self->_url(); |
91
|
|
|
|
|
|
|
my $function = $self->{function}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $http_request = HTTP::Request->new( GET=>$url ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
if ( ! defined $QualysGuard::Request::Username ) { |
96
|
|
|
|
|
|
|
croak "Error : Undefined Qualys username."; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if ( ! defined $QualysGuard::Request::Password ) { |
100
|
|
|
|
|
|
|
croak "Error : Undefined Qualys password."; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$http_request->authorization_basic( |
104
|
|
|
|
|
|
|
$QualysGuard::Request::Username, |
105
|
|
|
|
|
|
|
$QualysGuard::Request::Password |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $http_response = $ua->request( $http_request ); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ( ! $http_response->is_success() ) { |
113
|
|
|
|
|
|
|
croak "HTTP Error: " . $http_response->status_line(); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $qualys_response = $self->_get_qualys_response_from( $http_response ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $qualys_response; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
124
|
|
|
|
|
|
|
# _url |
125
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
126
|
|
|
|
|
|
|
sub _url { |
127
|
|
|
|
|
|
|
my $self = shift; |
128
|
|
|
|
|
|
|
my $attr = $self->attributes(); |
129
|
|
|
|
|
|
|
my @kvps = (); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
while ( my ($k,$v) = each( %$attr ) ) { |
132
|
|
|
|
|
|
|
$k = uri_escape( $k ); |
133
|
|
|
|
|
|
|
$v = uri_escape( $v ); |
134
|
|
|
|
|
|
|
push( @kvps, "$k=$v" ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return 'https://qualysapi.qualys.com/msp/' . $self->{function} . '.php?' . join('&', @kvps); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
143
|
|
|
|
|
|
|
# Factory method that creates the appropriate Response Object |
144
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
145
|
|
|
|
|
|
|
sub _get_qualys_response_from { |
146
|
|
|
|
|
|
|
my ( $self, $http_response ) = @_; |
147
|
|
|
|
|
|
|
my $function = $self->{function}; |
148
|
|
|
|
|
|
|
my $xml_content = $http_response->content(); |
149
|
|
|
|
|
|
|
my $qualys_return = undef; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
if ( $function eq 'asset_data_report' ) { |
153
|
|
|
|
|
|
|
require QualysGuard::Response::AssetDataReport; |
154
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetDataReport->new( $xml_content ); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
elsif ( |
158
|
|
|
|
|
|
|
$function eq 'asset_domain' || |
159
|
|
|
|
|
|
|
$function eq 'asset_group' || |
160
|
|
|
|
|
|
|
$function eq 'asset_group_delete' || |
161
|
|
|
|
|
|
|
$function eq 'asset_ip' || |
162
|
|
|
|
|
|
|
$function eq 'scan_cancel' || |
163
|
|
|
|
|
|
|
$function eq 'scan_report_delete' ) |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
require QualysGuard::Response::GenericReturn; |
166
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::GenericReturn->new( $xml_content ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
elsif ( $function eq 'asset_domain_list' ) { |
170
|
|
|
|
|
|
|
require QualysGuard::Response::AssetDomainList; |
171
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetDomainList->new( $xml_content ); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
elsif ( $function eq 'asset_group_list' ) { |
175
|
|
|
|
|
|
|
require QualysGuard::Response::AssetGroupList; |
176
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetGroupList->new( $xml_content ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
elsif ( $function eq 'asset_ip_list' ) { |
180
|
|
|
|
|
|
|
require QualysGuard::Response::AssetHostList; |
181
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetHostList->new( $xml_content ); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
elsif ( $function eq 'asset_range_info' ) { |
185
|
|
|
|
|
|
|
require QualysGuard::Response::AssetRangeInfo; |
186
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetRangeInfo->new( $xml_content ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
elsif ( $function eq 'asset_search' ) { |
190
|
|
|
|
|
|
|
require QualysGuard::Response::AssetSearchReport; |
191
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::AssetSearchReport->new( $xml_content ); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
elsif ( $function eq 'get_host_info' ) { |
195
|
|
|
|
|
|
|
require QualysGuard::Response::HostInfo; |
196
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::HostInfo->new( $xml_content ); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
elsif ( $function eq 'get_tickets' ) { |
200
|
|
|
|
|
|
|
require QualysGuard::Response::RemediationTickets; |
201
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::RemediationTickets->new( $xml_content ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
elsif ( $function eq 'iscanner_list' ) { |
205
|
|
|
|
|
|
|
require QualysGuard::Response::IScannerList; |
206
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::IScannerList->new( $xml_content ); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
elsif ( |
210
|
|
|
|
|
|
|
$function eq 'map' || |
211
|
|
|
|
|
|
|
$function eq 'map_report' ) |
212
|
|
|
|
|
|
|
{ |
213
|
|
|
|
|
|
|
require QualysGuard::Response::MapReport; |
214
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::MapReport->new( $xml_content ); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
elsif ( $function eq 'map_report_list' ) { |
218
|
|
|
|
|
|
|
require QualysGuard::Response::MapReportList; |
219
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::MapReportList->new( $xml_content ); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
elsif ( $function eq 'report_template_list' ) { |
223
|
|
|
|
|
|
|
require QualysGuard::Response::ReportTemplateList; |
224
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ReportTemplateList->new( $xml_content ); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
elsif ( |
228
|
|
|
|
|
|
|
$function eq 'scan' || |
229
|
|
|
|
|
|
|
$function eq 'scan_report' ) |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
require QualysGuard::Response::ScanReport; |
232
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScanReport->new( $xml_content ); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
elsif ( $function eq 'scan_options' ) { |
236
|
|
|
|
|
|
|
require QualysGuard::Response::ScanOptions; |
237
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScanOptions->new( $xml_content ); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
elsif ( $function eq 'scan_report_list' ) { |
241
|
|
|
|
|
|
|
require QualysGuard::Response::ScanReportList; |
242
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScanReportList->new( $xml_content ); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
elsif ( $function eq 'scan_running_list' ) { |
246
|
|
|
|
|
|
|
require QualysGuard::Response::ScanRunningList; |
247
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScanRunningList->new( $xml_content ); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
elsif ( $function eq 'scan_target_history' ) { |
251
|
|
|
|
|
|
|
require QualysGuard::Response::ScanTargetHistory; |
252
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScanTargetHistory->new( $xml_content ); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
elsif ( $function eq 'scheduled_scans' ) { |
256
|
|
|
|
|
|
|
require QualysGuard::Response::ScheduledScans; |
257
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::ScheduledScans->new( $xml_content ); |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
elsif ( $function eq 'ticket_delete' ) { |
261
|
|
|
|
|
|
|
require QualysGuard::Response::TicketDelete; |
262
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::TicketDelete->new( $xml_content ); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
elsif ( $function eq 'ticket_edit' ) { |
266
|
|
|
|
|
|
|
require QualysGuard::Response::TicketEdit; |
267
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::TicketEdit->new( $xml_content ); |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
elsif ( $function eq 'ticket_list' ) { |
271
|
|
|
|
|
|
|
require QualysGuard::Response::TicketList; |
272
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::TicketList->new( $xml_content ); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
elsif ( $function eq 'ticket_list_deleted' ) { |
276
|
|
|
|
|
|
|
require QualysGuard::Response::TicketListDeleted; |
277
|
|
|
|
|
|
|
$qualys_return = QualysGuard::Response::TicketListDeleted->new( $xml_content ); |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
return $qualys_return; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
1; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
__END__ |