line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# api::virustotal Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Api::Virustotal; |
7
|
1
|
|
|
1
|
|
670
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Client::Rest); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1110
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable rest domain virtualhost) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
apikey => [ qw(apikey) ], |
20
|
|
|
|
|
|
|
output_mode => [ qw(json|xml) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
attributes_default => { |
23
|
|
|
|
|
|
|
ssl_verify => 0, |
24
|
|
|
|
|
|
|
output_mode => 'json', |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
commands => { |
27
|
|
|
|
|
|
|
check_resource => [ qw(hash apikey|OPTIONAL) ], |
28
|
|
|
|
|
|
|
file_report => [ qw(hash apikey|OPTIONAL) ], |
29
|
|
|
|
|
|
|
ipv4_address_report => [ qw(ipv4_address apikey|OPTIONAL) ], |
30
|
|
|
|
|
|
|
domain_report => [ qw(domain apikey|OPTIONAL) ], |
31
|
|
|
|
|
|
|
subdomain_list => [ qw(domain) ], |
32
|
|
|
|
|
|
|
hosted_domains => [ qw(ipv4_address) ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
require_modules => { |
35
|
|
|
|
|
|
|
'Metabrik::String::Json' => [ ], |
36
|
|
|
|
|
|
|
'Metabrik::String::Xml' => [ ], |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub check_resource { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my ($resource, $apikey) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
46
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('check_resource', $resource) or return; |
47
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('check_resource', $apikey) or return; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
my $r = $self->post({ apikey => $apikey, resource => $resource }, |
50
|
|
|
|
|
|
|
'https://www.virustotal.com/vtapi/v2/file/rescan') |
51
|
|
|
|
|
|
|
or return; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $content = $r->{content}; |
54
|
0
|
|
|
|
|
|
my $code = $r->{code}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->log->verbose("check_resource: returned code [$code]"); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
59
|
0
|
0
|
|
|
|
|
my $decode = $sj->decode($content) or return; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $decode; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub file_report { |
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my ($resource, $apikey) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
69
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('file_report', $resource) or return; |
70
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('file_report', $apikey) or return; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
my $r = $self->post({ apikey => $apikey, resource => $resource }, |
73
|
|
|
|
|
|
|
'https://www.virustotal.com/vtapi/v2/file/report') |
74
|
|
|
|
|
|
|
or return; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $content = $r->{content}; |
77
|
0
|
|
|
|
|
|
my $code = $r->{code}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$self->log->verbose("file_report: returned code [$code]"); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
82
|
0
|
0
|
|
|
|
|
my $decode = $sj->decode($content) or return; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $decode; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub ipv4_address_report { |
88
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
89
|
0
|
|
|
|
|
|
my ($ipv4_address, $apikey) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
92
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('ipv4_address_report', $ipv4_address) or return; |
93
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('ipv4_address_report', $apikey) or return; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
my $r = $self->get('https://www.virustotal.com/vtapi/v2/ip-address/report?apikey=' |
96
|
|
|
|
|
|
|
.$apikey.'&ip='.$ipv4_address) |
97
|
|
|
|
|
|
|
or return; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $content = $r->{content}; |
100
|
0
|
|
|
|
|
|
my $code = $r->{code}; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->log->verbose("ipv4_address_report: returned code [$code]"); |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
105
|
0
|
0
|
|
|
|
|
my $decode = $sj->decode($content) or return; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $decode; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub domain_report { |
111
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
my ($domain, $apikey) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
115
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('domain_report', $domain) or return; |
116
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('domain_report', $apikey) or return; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
my $r = $self->get('https://www.virustotal.com/vtapi/v2/domain/report?apikey=' |
119
|
|
|
|
|
|
|
.$apikey.'&domain='.$domain) |
120
|
|
|
|
|
|
|
or return; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $content = $r->{content}; |
123
|
0
|
|
|
|
|
|
my $code = $r->{code}; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$self->log->verbose("domain_report: returned code [$code]"); |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
128
|
0
|
0
|
|
|
|
|
my $decode = $sj->decode($content) or return; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $decode; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub subdomain_list { |
134
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
135
|
0
|
|
|
|
|
|
my ($domain) = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('subdomain_list', $domain) or return; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
my $r = $self->domain_report($domain) or return; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
0
|
|
|
|
if (exists($r->{subdomains}) && ref($r->{subdomains}) eq 'ARRAY') { |
142
|
0
|
|
|
|
|
|
return $r->{subdomains}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return []; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub hosted_domains { |
149
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
150
|
0
|
|
|
|
|
|
my ($ipv4_address) = @_; |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('hosted_domains', $ipv4_address) or return; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
my $r = $self->ipv4_address_report($ipv4_address) or return; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my @result = (); |
157
|
0
|
0
|
0
|
|
|
|
if (exists($r->{resolutions}) && ref($r->{resolutions}) eq 'ARRAY') { |
158
|
0
|
|
|
|
|
|
for (@{$r->{resolutions}}) { |
|
0
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
push @result, $_->{hostname}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return \@result; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__END__ |