Skip to content

Commit a88d06c

Browse files
authored
Merge pull request #73 from NullArray/trivial
Implementation for all
2 parents a4c13bd + eb3d938 commit a88d06c

File tree

14 files changed

+4617
-813
lines changed

14 files changed

+4617
-813
lines changed

api_calls/censys.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import requests
2-
import threading
32

43
import lib.settings
5-
from lib.output import error
64
from lib.errors import AutoSploitAPIConnectionError
75
from lib.settings import (
86
HOST_FILE,
@@ -17,10 +15,12 @@ class CensysAPIHook(object):
1715
Censys API hook
1816
"""
1917

20-
def __init__(self, identity, token, query):
18+
def __init__(self, identity=None, token=None, query=None, proxy=None, agent=None, **kwargs):
2119
self.id = identity
2220
self.token = token
2321
self.query = query
22+
self.proxy = proxy
23+
self.user_agent = agent
2424
self.host_file = HOST_FILE
2525

2626
def censys(self):
@@ -30,12 +30,15 @@ def censys(self):
3030
discovered_censys_hosts = set()
3131
try:
3232
lib.settings.start_animation("searching Censys with given query '{}'".format(self.query))
33-
req = requests.post(API_URLS["censys"], auth=(self.id, self.token), json={"query": self.query})
33+
req = requests.post(
34+
API_URLS["censys"], auth=(self.id, self.token),
35+
json={"query": self.query}, headers=self.user_agent,
36+
proxies=self.proxy
37+
)
3438
json_data = req.json()
3539
for item in json_data["results"]:
3640
discovered_censys_hosts.add(str(item["ip"]))
3741
write_to_file(discovered_censys_hosts, self.host_file)
3842
return True
3943
except Exception as e:
40-
error(AutoSploitAPIConnectionError(str(e)))
41-
return False
44+
raise AutoSploitAPIConnectionError(str(e))

api_calls/shodan.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import requests
44

55
from lib.settings import start_animation
6-
from lib.output import error
76
from lib.errors import AutoSploitAPIConnectionError
87
from lib.settings import (
98
API_URLS,
@@ -18,27 +17,30 @@ class ShodanAPIHook(object):
1817
Shodan API hook, saves us from having to install another dependency
1918
"""
2019

21-
def __init__(self, token, query, proxy=None):
20+
def __init__(self, token=None, query=None, proxy=None, agent=None, **kwargs):
2221
self.token = token
2322
self.query = query
2423
self.proxy = proxy
24+
self.user_agent = agent
2525
self.host_file = HOST_FILE
2626

2727
def shodan(self):
2828
"""
2929
connect to the API and grab all IP addresses associated with the provided query
3030
"""
31-
start_animation("search Shodan with given query '{}'".format(self.query))
31+
start_animation("searching Shodan with given query '{}'".format(self.query))
3232
discovered_shodan_hosts = set()
3333
try:
34-
req = requests.get(API_URLS["shodan"].format(query=self.query, token=self.token))
34+
req = requests.get(
35+
API_URLS["shodan"].format(query=self.query, token=self.token),
36+
proxies=self.proxy, headers=self.user_agent
37+
)
3538
json_data = json.loads(req.content)
3639
for match in json_data["matches"]:
3740
discovered_shodan_hosts.add(match["ip_str"])
3841
write_to_file(discovered_shodan_hosts, self.host_file)
3942
return True
4043
except Exception as e:
41-
error(AutoSploitAPIConnectionError(str(e)))
42-
return False
44+
raise AutoSploitAPIConnectionError(str(e))
4345

4446

api_calls/zoomeye.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from lib.settings import start_animation
88
from lib.errors import AutoSploitAPIConnectionError
9-
from lib.output import error
109
from lib.settings import (
1110
API_URLS,
1211
HOST_FILE,
@@ -21,9 +20,11 @@ class ZoomEyeAPIHook(object):
2120
so we're going to use some 'lifted' credentials to login for us
2221
"""
2322

24-
def __init__(self, query):
23+
def __init__(self, query=None, proxy=None, agent=None, **kwargs):
2524
self.query = query
2625
self.host_file = HOST_FILE
26+
self.proxy = proxy
27+
self.user_agent = agent
2728
self.user_file = "{}/etc/text_files/users.lst".format(os.getcwd())
2829
self.pass_file = "{}/etc/text_files/passes.lst".format(os.getcwd())
2930

@@ -61,9 +62,18 @@ def zoomeye(self):
6162
discovered_zoomeye_hosts = set()
6263
try:
6364
token = self.__get_auth()
64-
headers = {"Authorization": "JWT {}".format(str(token["access_token"]))}
65+
if self.user_agent is None:
66+
headers = {"Authorization": "JWT {}".format(str(token["access_token"]))}
67+
else:
68+
headers = {
69+
"Authorization": "JWT {}".format(str(token["access_token"])),
70+
"agent": self.user_agent["User-Agent"]
71+
}
6572
params = {"query": self.query, "page": "1", "facet": "ipv4"}
66-
req = requests.get(API_URLS["zoomeye"][1].format(query=self.query), params=params, headers=headers)
73+
req = requests.get(
74+
API_URLS["zoomeye"][1].format(query=self.query),
75+
params=params, headers=headers, proxies=self.proxy
76+
)
6777
_json_data = req.json()
6878
for item in _json_data["matches"]:
6979
if len(item["ip"]) > 1:
@@ -74,6 +84,5 @@ def zoomeye(self):
7484
write_to_file(discovered_zoomeye_hosts, self.host_file)
7585
return True
7686
except Exception as e:
77-
error(AutoSploitAPIConnectionError(str(e)))
78-
return False
87+
raise AutoSploitAPIConnectionError(str(e))
7988

0 commit comments

Comments
 (0)