Skip to content

Commit 28a5c86

Browse files
author
ekultek
committed
created a method to load the API keys since we now use multiple of them, it will prompt for them if they do not exist otherwise it will load them from a file in etc/tokens
1 parent 4c1783c commit 28a5c86

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ api.p
44
hosts.txt
55
secret.p
66
uid.p
7+
etc/tokens/*

api_calls/censys.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111

1212
class CensysAPIHook(object):
1313

14+
"""
15+
Censys API hook
16+
"""
17+
1418
def __init__(self, identity, token, query):
1519
self.id = identity
1620
self.token = token
1721
self.query = query
1822
self.host_file = HOST_FILE
1923

2024
def censys(self):
25+
"""
26+
connect to the Censys API and pull all IP addresses from the provided query
27+
"""
2128
discovered_censys_hosts = set()
2229
try:
2330
req = requests.post(API_URLS["censys"], auth=(self.id, self.token), json={"query": self.query})

api_calls/shodan.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313

1414
class ShodanAPIHook(object):
1515

16+
"""
17+
Shodan API hook, saves us from having to install another dependency
18+
"""
19+
1620
def __init__(self, token, query, proxy=None):
1721
self.token = token
1822
self.query = query
1923
self.proxy = proxy
2024
self.host_file = HOST_FILE
2125

2226
def shodan(self):
27+
"""
28+
connect to the API and grab all IP addresses associated with the provided query
29+
"""
2330
discovered_shodan_hosts = set()
2431
try:
2532
req = requests.get(API_URLS["shodan"].format(query=self.query, token=self.token))

api_calls/zoomeye.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
class ZoomEyeAPIHook(object):
1717

18+
"""
19+
API hook for the ZoomEye API, in order to connect you need to provide a phone number
20+
so we're going to use some 'lifted' credentials to login for us
21+
"""
22+
1823
def __init__(self, query):
1924
self.query = query
2025
self.host_file = HOST_FILE
@@ -23,6 +28,9 @@ def __init__(self, query):
2328

2429
@staticmethod
2530
def __decode(filepath):
31+
"""
32+
we all know what this does
33+
"""
2634
with open(filepath) as f:
2735
data = f.read()
2836
token, n = data.split(":")
@@ -31,6 +39,11 @@ def __decode(filepath):
3139
return token.strip()
3240

3341
def __get_auth(self):
42+
"""
43+
get the authorization for the authentication token, you have to login
44+
before you can access the API, this is where the 'lifted' creds come into
45+
play.
46+
"""
3447
username = self.__decode(self.user_file)
3548
password = self.__decode(self.pass_file)
3649
data = {"username": username, "password": password}
@@ -39,6 +52,10 @@ def __get_auth(self):
3952
return token
4053

4154
def zoomeye(self):
55+
"""
56+
connect to the API and pull all the IP addresses that are associated with the
57+
given query
58+
"""
4259
discovered_zoomeye_hosts = set()
4360
try:
4461
token = self.__get_auth()
@@ -48,8 +65,8 @@ def zoomeye(self):
4865
_json_data = req.json()
4966
for item in _json_data["matches"]:
5067
if len(item["ip"]) > 1:
51-
# TODO:/ grab all the IP addresses when there's more then 1
52-
discovered_zoomeye_hosts.add(str(item["ip"][0]))
68+
for ip in item["ip"]:
69+
discovered_zoomeye_hosts.add(ip)
5370
else:
5471
discovered_zoomeye_hosts.add(str(item["ip"][0]))
5572
write_to_file(discovered_zoomeye_hosts, self.host_file)

autosploit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from lib.settings import (
3535
validate_ip_addr,
3636
check_services,
37+
load_api_keys,
3738
PLATFORM_PROMPT,
3839
AUTOSPLOIT_PROMPT,
3940
AUTOSPLOIT_TERM_OPTS
@@ -605,20 +606,17 @@ def start_apache():
605606
start_ap = prompt("Start Apache Service? [Y]es/[N]o")
606607
if start_ap == 'y':
607608
start_apache()
608-
time.sleep(1.5)
609-
610609
elif start_ap == 'n':
611610
error("AutoSploit's MSF related operations require this service to be active.")
612611
error("Aborted.")
613-
time.sleep(1.5)
614612
sys.exit(0)
615613
else:
616614
warning("Unhandled Option. Defaulting to starting the service.")
617615
start_apache()
618-
time.sleep(1.5)
619616

620617
# We will check if the shodan api key has been saved before, if not we are going to prompt
621618
# for it and save it to a file
619+
# load_api_keys()
622620
if not os.path.isfile("api.p"):
623621
info("Please provide your Shodan.io API key.")
624622

lib/settings.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
START_APACHE_PATH = "{}/etc/scripts/start_apache.sh".format(os.getcwd())
1313
PLATFORM_PROMPT = "\n{}@\033[36mPLATFORM\033[0m$ ".format(getpass.getuser())
1414
AUTOSPLOIT_PROMPT = "\n\033[31m{}\033[0m@\033[36mautosploit\033[0m# ".format(getpass.getuser())
15+
API_KEYS = {
16+
"censys": "{}/etc/tokens/censys.key".format(os.getcwd()),
17+
"shodan": "{}/etc/tokens/shodan.key".format(os.getcwd())
18+
}
1519
API_URLS = {
1620
"shodan": "https://api.shodan.io/shodan/host/search?key={token}&query={query}",
1721
"censys": "https://censys.io/api/v1/search/ipv4",
@@ -73,3 +77,31 @@ def write_to_file(data_to_write, filename, mode="a+"):
7377
log.write(data_to_write)
7478
lib.output.info("successfully wrote info to '{}'".format(filename))
7579
return filename
80+
81+
82+
def load_api_keys(path="{}/etc/tokens".format(os.getcwd())):
83+
84+
"""
85+
load the API keys from their .key files
86+
"""
87+
88+
def makedir(dir):
89+
"""
90+
make the directory if it does not exist
91+
"""
92+
if not os.path.exists(dir):
93+
os.mkdir(dir)
94+
95+
makedir(path)
96+
for key in API_KEYS.keys():
97+
if not os.path.isfile(API_KEYS[key]):
98+
access_token = lib.output.prompt("enter your {} API token".format(key.title()), lowercase=False)
99+
with open(API_KEYS[key], "a+") as log:
100+
log.write(access_token.strip())
101+
else:
102+
lib.output.info("{} API token loaded from {}".format(key.title(), API_KEYS[key]))
103+
api_tokens = {
104+
"censys": open(API_KEYS["censys"]).read(),
105+
"shodan": open(API_KEYS["shodan"]).read()
106+
}
107+
return api_tokens

0 commit comments

Comments
 (0)