| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Webservice::CVEDB::API; |
|
2
|
|
|
|
|
|
|
our $VERSION = '1.001'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
238222
|
use v5.40; |
|
|
1
|
|
|
|
|
3
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use feature 'class'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
133
|
|
|
6
|
1
|
|
|
1
|
|
4
|
no warnings 'experimental::class'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
53
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
class Webservice::CVEDB::API 1.001; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2592
|
use HTTP::Tiny; |
|
|
1
|
|
|
|
|
61639
|
|
|
|
1
|
|
|
|
|
62
|
|
|
11
|
1
|
|
|
1
|
|
13
|
use JSON::PP; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
83
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
970
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
field $ua :reader = HTTP::Tiny->new(timeout => 7); |
|
15
|
|
|
|
|
|
|
field $base :reader = 'https://cvedb.shodan.io' ; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
method get_cve ($cve_id){ |
|
18
|
|
|
|
|
|
|
return fetch($self, "/cve/$cve_id"); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
method get_cpes (%params){ |
|
22
|
|
|
|
|
|
|
return fetch($self, "/cpes?", \%params); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
method get_cves (%params){ |
|
26
|
|
|
|
|
|
|
return fetch($self, "/cves?", \%params); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
0
|
|
sub fetch($self, $endpoint, $params //= ''){ |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
$params = $self->ua->www_form_urlencode( $params ) if $params; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
my $response = $self->ua->get($self->base.$endpoint.$params) or croak "$!"; |
|
33
|
0
|
0
|
|
|
|
|
if (! $response->{success}){ |
|
34
|
0
|
|
|
|
|
|
my %error; |
|
35
|
0
|
|
|
|
|
|
try{ |
|
36
|
0
|
0
|
|
|
|
|
my $detail = decode_json($response->{content}) or croak "$!"; |
|
37
|
0
|
|
|
|
|
|
$error{detail} = $detail->{detail}."\n"; |
|
38
|
0
|
|
|
|
|
|
$error{success} = $response->{success}; |
|
39
|
|
|
|
|
|
|
}catch($e){ |
|
40
|
0
|
|
|
|
|
|
$error{detail} = $response->{content}; |
|
41
|
0
|
|
|
|
|
|
$error{success} = $response->{success}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return \%error; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
try{ |
|
48
|
0
|
|
|
|
|
|
$response->{content} = decode_json($response->{content}); |
|
49
|
|
|
|
|
|
|
}catch($e){ |
|
50
|
0
|
|
|
|
|
|
croak "unable to decode message from API \n".$e; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$response->{content}->{success} = $response->{success}; |
|
54
|
0
|
|
|
|
|
|
return $response->{content}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
1; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |