-
Notifications
You must be signed in to change notification settings - Fork 5
/
shodan-php.php
124 lines (100 loc) · 3.14 KB
/
shodan-php.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
class WebAPI {
/* PHP Wrapper around the SHODAN webservices API
Author of PHP Wrapper: jordan-wright (jmwright798 at gmail.com)
SHODAN Database designed and maintained by achillean (John Matherly)
SHODAN website: http://www.shodanhq.com
Follow achillean on twitter: http://twitter.com/#!/achillean
*/
private $key;
private $base;
/* Constructor - Instantiates WebAPI object
Example: $shodan = new WebAPI("your API key");
*/
function __construct($api_key) {
$this->key = $api_key;
$this->base = "http://www.shodanhq.com/api/";
}
/* General CURL Request function
Arguments: function - function to be performed (Example: "search")
params - Associative array of arguments to that function
Returns: Associative array of JSON decoded output from the SHODAN webservice
*/
function _request($function,$params) {
$params = array("key" => $this->key) + $params;
$url = $this->base . "$function?" . http_build_query($params);
$req = curl_init($url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($req);
curl_close($req);
return json_decode($ret, true);
}
/* Search Function
Arguments: query - Query to be searched for
Returns: Result (associative array) from SHODAN webservices
*/
function search($query)
{
return $this->_request("search",array("q"=>$query));
}
/* Exploit DB Download Function
Arguments: id - Exploit DB ID of wanted exploit
Returns: Result (associative array) from SHODAN webservices
*/
function exploitdb_download($id)
{
return $this->_request("exploitdb/download",array("id"=>$id));
}
/* Exploit DB Search Function
Arguments: query - Query to be searched for
args - Associative array of other arguments to better define query
Returns: Result (associative array) from SHODAN webservices
*/
function exploitdb_search($query, $args)
{
$args = array("q"=>$query)+$args;
return $this->_request("exploitdb/search",$args);
}
/* Host Search Function
Arguments: ip - IP Address of specified host(s)
Returns: Result (associative array) from SHODAN webservices
*/
function host($ip)
{
return $this->_request("host",array("ip"=>$ip));
}
/* Fingerprint Function
Arguments: banner - HTTP Banner
Returns: Result (associative array) from SHODAN webservices
*/
function fingerprint($banner)
{
return $this->_request("fingerprint",array("banner"=>$banner));
}
/* Locations Function
Arguments: query - Query to be searched for
Returns: Result (associative array) from SHODAN webservices
*/
function locations($query)
{
return $this->_request("locations",array("q"=>$query));
}
/* MSF Download Function
Arguments: id - fullname of Metasploit Module
Returns: Result (associative array) from SHODAN webservices
*/
function msf_download($id)
{
return $this->_request("msf/download",array("id"=>$id));
}
/* MSF Search Function
Arguments: query - Metasploit module to be searched for
Returns: Result (associative array) from SHODAN webservices
*/
function msf_search($query, $args)
{
$args = array("q"=>$query) + $args;
return $this->_request("msf/search",$args);
}
}
?>