Api/Virustotal.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Api/Splunk.pm ↑ Summary Audio/Soundconverter.pm »
1 #
2 # $Id$
3 #
4 # api::virustotal Brik
5 #
6 package Metabrik::Api::Virustotal;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Client::Rest);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable rest domain virtualhost) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
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 my $self = shift;
43 my ($resource, $apikey) = @_;
44  
45 $apikey ||= $self->apikey;
46 $self->brik_help_run_undef_arg('check_resource', $resource) or return;
47 $self->brik_help_run_undef_arg('check_resource', $apikey) or return;
48  
49 my $r = $self->post({ apikey => $apikey, resource => $resource },
50 'https://www.virustotal.com/vtapi/v2/file/rescan')
51 or return;
52  
53 my $content = $r->{content};
54 my $code = $r->{code};
55  
56 $self->log->verbose("check_resource: returned code [$code]");
57  
58 my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
59 my $decode = $sj->decode($content) or return;
60  
61 return $decode;
62 }
63  
64 sub file_report {
65 my $self = shift;
66 my ($resource, $apikey) = @_;
67  
68 $apikey ||= $self->apikey;
69 $self->brik_help_run_undef_arg('file_report', $resource) or return;
70 $self->brik_help_run_undef_arg('file_report', $apikey) or return;
71  
72 my $r = $self->post({ apikey => $apikey, resource => $resource },
73 'https://www.virustotal.com/vtapi/v2/file/report')
74 or return;
75  
76 my $content = $r->{content};
77 my $code = $r->{code};
78  
79 $self->log->verbose("file_report: returned code [$code]");
80  
81 my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
82 my $decode = $sj->decode($content) or return;
83  
84 return $decode;
85 }
86  
87 sub ipv4_address_report {
88 my $self = shift;
89 my ($ipv4_address, $apikey) = @_;
90  
91 $apikey ||= $self->apikey;
92 $self->brik_help_run_undef_arg('ipv4_address_report', $ipv4_address) or return;
93 $self->brik_help_run_undef_arg('ipv4_address_report', $apikey) or return;
94  
95 my $r = $self->get('https://www.virustotal.com/vtapi/v2/ip-address/report?apikey='
96 .$apikey.'&ip='.$ipv4_address)
97 or return;
98  
99 my $content = $r->{content};
100 my $code = $r->{code};
101  
102 $self->log->verbose("ipv4_address_report: returned code [$code]");
103  
104 my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
105 my $decode = $sj->decode($content) or return;
106  
107 return $decode;
108 }
109  
110 sub domain_report {
111 my $self = shift;
112 my ($domain, $apikey) = @_;
113  
114 $apikey ||= $self->apikey;
115 $self->brik_help_run_undef_arg('domain_report', $domain) or return;
116 $self->brik_help_run_undef_arg('domain_report', $apikey) or return;
117  
118 my $r = $self->get('https://www.virustotal.com/vtapi/v2/domain/report?apikey='
119 .$apikey.'&domain='.$domain)
120 or return;
121  
122 my $content = $r->{content};
123 my $code = $r->{code};
124  
125 $self->log->verbose("domain_report: returned code [$code]");
126  
127 my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
128 my $decode = $sj->decode($content) or return;
129  
130 return $decode;
131 }
132  
133 sub subdomain_list {
134 my $self = shift;
135 my ($domain) = @_;
136  
137 $self->brik_help_run_undef_arg('subdomain_list', $domain) or return;
138  
139 my $r = $self->domain_report($domain) or return;
140  
141 if (exists($r->{subdomains}) && ref($r->{subdomains}) eq 'ARRAY') {
142 return $r->{subdomains};
143 }
144  
145 return [];
146 }
147  
148 sub hosted_domains {
149 my $self = shift;
150 my ($ipv4_address) = @_;
151  
152 $self->brik_help_run_undef_arg('hosted_domains', $ipv4_address) or return;
153  
154 my $r = $self->ipv4_address_report($ipv4_address) or return;
155  
156 my @result = ();
157 if (exists($r->{resolutions}) && ref($r->{resolutions}) eq 'ARRAY') {
158 for (@{$r->{resolutions}}) {
159 push @result, $_->{hostname};
160 }
161 }
162  
163 return \@result;
164 }
165  
166 1;
167  
168 __END__
« Api/Splunk.pm ↑ Summary Audio/Soundconverter.pm »