Skip to content

Commit 9adb6eb

Browse files
author
ekultek
committed
implemented the switches, search engines, and everything else, issue #49, #64, #57
1 parent c7f05ca commit 9adb6eb

File tree

12 files changed

+4493
-40
lines changed

12 files changed

+4493
-40
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: 7 additions & 5 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,10 +17,11 @@ 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):
@@ -31,14 +31,16 @@ def shodan(self):
3131
start_animation("search 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

autosploit-dev.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from autosploit.main import main
2+
3+
4+
if __name__ == "__main__":
5+
# this will be taking precedence over autosploit.py in the future
6+
# until we're ready for 2.0 we'll call this autosploit-dev.py
7+
main()

autosploit/__init__.py

Whitespace-only changes.

autosploit/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
3+
from lib.cmdline.cmd import AutoSploitParser
4+
from lib.term.terminal import AutoSploitTerminal
5+
from lib.output import (
6+
info,
7+
warning,
8+
error,
9+
prompt
10+
)
11+
from lib.settings import (
12+
logo,
13+
load_api_keys,
14+
check_services,
15+
cmdline,
16+
EXPLOIT_FILES_PATH,
17+
START_APACHE_PATH,
18+
START_POSTGRESQL_PATH
19+
)
20+
from lib.jsonize import load_exploits
21+
22+
23+
def main():
24+
25+
opts = AutoSploitParser().optparser()
26+
27+
logo()
28+
info("welcome to autosploit, give us a little bit while we configure")
29+
info("checking for services")
30+
service_names = ("postgresql", "apache")
31+
for service in list(service_names):
32+
if not check_services(service):
33+
choice = prompt("it appears that service {} is not enabled, would you like us to enable it for you[y/N]")
34+
if choice.lower().startswith("y"):
35+
if "postgre" in service:
36+
cmdline("sudo bash {}".format(START_POSTGRESQL_PATH))
37+
else:
38+
cmdline("sudo bash {}".format(START_APACHE_PATH))
39+
info("service started successfully")
40+
else:
41+
error("service {} is required to be started for autosploit to run, exiting".format(service.title()))
42+
sys.exit(1)
43+
44+
if len(sys.argv) > 1:
45+
info("attempting to load API keys")
46+
loaded_tokens = load_api_keys()
47+
AutoSploitParser().parse_provided(opts)
48+
info("checking if there are multiple exploit files")
49+
loaded_exploits = load_exploits(EXPLOIT_FILES_PATH)
50+
AutoSploitParser().single_run_args(opts, loaded_tokens, loaded_exploits)
51+
else:
52+
warning("no arguments have been parsed, defaulting to terminal session. press 99 to quit and help to get help")
53+
info("checking if there are multiple exploit files")
54+
loaded_exploits = load_exploits(EXPLOIT_FILES_PATH)
55+
info("attempting to load API keys")
56+
loaded_tokens = load_api_keys()
57+
terminal = AutoSploitTerminal(loaded_tokens)
58+
terminal.terminal_main_display(loaded_exploits)

0 commit comments

Comments
 (0)