| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id$ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# api::shodan Brik |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
package Metabrik::Api::Shodan; |
|
7
|
1
|
|
|
1
|
|
1094
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
31
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Client::Rest); |
|
|
1
|
|
|
|
|
29
|
|
|
|
1
|
|
|
|
|
591
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# API: https://developer.shodan.io/api |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub brik_properties { |
|
15
|
|
|
|
|
|
|
return { |
|
16
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
|
17
|
|
|
|
|
|
|
tags => [ qw(unstable rest) ], |
|
18
|
|
|
|
|
|
|
author => 'GomoR ', |
|
19
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
|
20
|
|
|
|
|
|
|
attributes => { |
|
21
|
|
|
|
|
|
|
output_mode => [ qw(json|xml) ], |
|
22
|
|
|
|
|
|
|
apikey => [ qw(apikey) ], |
|
23
|
|
|
|
|
|
|
uri => [ qw(shodan_uri) ], |
|
24
|
|
|
|
|
|
|
}, |
|
25
|
|
|
|
|
|
|
attributes_default => { |
|
26
|
|
|
|
|
|
|
output_mode => 'json', |
|
27
|
|
|
|
|
|
|
ssl_verify => 0, |
|
28
|
|
|
|
|
|
|
uri => 'https://api.shodan.io', |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
commands => { |
|
31
|
|
|
|
|
|
|
myip => [ qw(apikey|OPTIONAL) ], |
|
32
|
|
|
|
|
|
|
api_info => [ qw(apikey|OPTIONAL) ], |
|
33
|
|
|
|
|
|
|
host_ip => [ qw(ip_address apikey|OPTIONAL) ], |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
|
|
|
|
|
|
require_modules => { |
|
36
|
|
|
|
|
|
|
'Metabrik::Network::Address' => [ ], |
|
37
|
|
|
|
|
|
|
'Metabrik::String::Json' => [ ], |
|
38
|
|
|
|
|
|
|
'Metabrik::String::Xml' => [ ], |
|
39
|
|
|
|
|
|
|
}, |
|
40
|
|
|
|
|
|
|
}; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub myip { |
|
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $apikey = $self->apikey; |
|
47
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('myip', $apikey) or return; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $uri = $self->uri; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
my $resp = $self->get($uri.'/tools/myip?key='.$apikey) or return; |
|
52
|
0
|
|
|
|
|
|
my $content = $resp->{content}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$content =~ s/"?//g; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $content; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub api_info { |
|
60
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
61
|
0
|
|
|
|
|
|
my ($apikey) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
|
64
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('api_info', $apikey) or return; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $uri = $self->uri; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
my $resp = $self->get($uri.'/api-info?key='.$apikey) or return; |
|
69
|
0
|
|
|
|
|
|
my $content = $resp->{content}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
|
72
|
0
|
0
|
|
|
|
|
my $decoded = $sj->decode($content) or return; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $decoded; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub host_ip { |
|
78
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
79
|
0
|
|
|
|
|
|
my ($ip, $apikey) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
0
|
|
|
|
$apikey ||= $self->apikey; |
|
82
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('host_ip', $ip) or return; |
|
83
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('host_ip', $apikey) or return; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
my $na = Metabrik::Network::Address->new_from_brik_init($self) or return; |
|
86
|
0
|
0
|
|
|
|
|
if (! $na->is_ip($ip)) { |
|
87
|
0
|
|
|
|
|
|
return $self->log->error("host_ip: invalid format for IP [$ip]"); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $uri = $self->uri; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
my $resp = $self->get($uri.'/shodan/host/'.$ip.'?key='.$apikey) or return; |
|
93
|
0
|
|
|
|
|
|
my $content = $resp->{content}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
|
96
|
0
|
0
|
|
|
|
|
my $decoded = $sj->decode($content) or return; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $decoded; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |