Skip to content

Commit e309f3e

Browse files
author
ekultek
committed
pushing the API packages to Github, will implement them later on (issue #64 and #49)
1 parent 3d777f2 commit e309f3e

File tree

9 files changed

+181
-4
lines changed

9 files changed

+181
-4
lines changed

api_calls/__init__.py

Whitespace-only changes.

api_calls/censys.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import requests
2+
3+
from lib.errors import AutoSploitAPIConnectionError
4+
from lib.output import error
5+
from lib.settings import (
6+
HOST_FILE,
7+
API_URLS,
8+
write_to_file
9+
)
10+
11+
12+
class CensysAPIHook(object):
13+
14+
def __init__(self, identity, token, query):
15+
self.id = identity
16+
self.token = token
17+
self.query = query
18+
self.host_file = HOST_FILE
19+
20+
def censys(self):
21+
discovered_censys_hosts = set()
22+
try:
23+
req = requests.post(API_URLS["censys"], auth=(self.id, self.token), json={"query": self.query})
24+
json_data = req.json()
25+
for item in json_data["results"]:
26+
discovered_censys_hosts.add(str(item["ip"]))
27+
write_to_file(discovered_censys_hosts, self.host_file)
28+
return True
29+
except Exception as e:
30+
error(AutoSploitAPIConnectionError(str(e)))
31+
return False

api_calls/shodan.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
3+
import requests
4+
5+
from lib.errors import AutoSploitAPIConnectionError
6+
from lib.output import error
7+
from lib.settings import (
8+
API_URLS,
9+
HOST_FILE,
10+
write_to_file
11+
)
12+
13+
14+
class ShodanAPIHook(object):
15+
16+
def __init__(self, token, query, proxy=None):
17+
self.token = token
18+
self.query = query
19+
self.proxy = proxy
20+
self.host_file = HOST_FILE
21+
22+
def shodan(self):
23+
discovered_shodan_hosts = set()
24+
try:
25+
req = requests.get(API_URLS["shodan"].format(query=self.query, token=self.token))
26+
json_data = json.loads(req.content)
27+
for match in json_data["matches"]:
28+
discovered_shodan_hosts.add(match["ip_str"])
29+
write_to_file(discovered_shodan_hosts, self.host_file)
30+
return True
31+
except Exception as e:
32+
error(AutoSploitAPIConnectionError(str(e)))
33+
return False
34+
35+

api_calls/zoomeye.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import base64
3+
import json
4+
5+
import requests
6+
7+
from lib.errors import AutoSploitAPIConnectionError
8+
from lib.output import error
9+
from lib.settings import (
10+
API_URLS,
11+
HOST_FILE,
12+
write_to_file
13+
)
14+
15+
16+
class ZoomEyeAPIHook(object):
17+
18+
def __init__(self, query):
19+
self.query = query
20+
self.host_file = HOST_FILE
21+
self.user_file = "{}/etc/text_files/users.lst".format(os.getcwd())
22+
self.pass_file = "{}/etc/text_files/passes.lst".format(os.getcwd())
23+
24+
@staticmethod
25+
def __decode(filepath):
26+
with open(filepath) as f:
27+
data = f.read()
28+
token, n = data.split(":")
29+
for _ in range(int(n.strip())):
30+
token = base64.b64decode(token)
31+
return token.strip()
32+
33+
def __get_auth(self):
34+
username = self.__decode(self.user_file)
35+
password = self.__decode(self.pass_file)
36+
data = {"username": username, "password": password}
37+
req = requests.post(API_URLS["zoomeye"][0], json=data)
38+
token = json.loads(req.content)
39+
return token
40+
41+
def zoomeye(self):
42+
discovered_zoomeye_hosts = set()
43+
try:
44+
token = self.__get_auth()
45+
headers = {"Authorization": "JWT {}".format(str(token["access_token"]))}
46+
params = {"query": self.query, "page": "1", "facet": "ipv4"}
47+
req = requests.get(API_URLS["zoomeye"][1].format(query=self.query), params=params, headers=headers)
48+
_json_data = req.json()
49+
for item in _json_data["matches"]:
50+
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]))
53+
else:
54+
discovered_zoomeye_hosts.add(str(item["ip"][0]))
55+
write_to_file(discovered_zoomeye_hosts, self.host_file)
56+
return True
57+
except Exception as e:
58+
error(AutoSploitAPIConnectionError(str(e)))
59+
return False
60+

autosploit.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Fix the non-existing host path reference line #409
1414
- Create a retry decorator with a max of 5 min of 3 line #436
1515
- Add a secondary check to make sure autosploit is running line #535
16+
- Implement the API packages into the flow (api_calls, will create a `main` class or function for it)
1617
"""
1718

1819
import os
@@ -58,12 +59,19 @@
5859
stop_animation = False
5960

6061

61-
def logo(line_sep="#--", space=" " * 30):
62-
"""Logo."""
63-
print banner_main()
62+
def logo():
63+
"""
64+
display a random banner from the banner.py file
65+
"""
66+
print(banner_main())
6467

6568

6669
def animation(text):
70+
"""
71+
display an animation while working, this will be
72+
single threaded so that it will not screw with the
73+
current running process
74+
"""
6775
global stop_animation
6876
i = 0
6977
while not stop_animation:

etc/text_files/passes.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Vm0xNFUxSXlTWGxUV0dST1UwZFNUMVV3YUVOWFZteFZVMnhPV0ZKdGVIcFdiR2hyWWtaYWMxTnVjRmRpV0VKRVdWZDRkMDVyTVVWaGVqQTk=:7

etc/text_files/users.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Vm1wR2IyUXhVWGhXV0d4V1lteEtWVmx0ZUV0WFJteFZVVzFHYWxac1NsbGFWV1JIWVd4YWMxTnJiRlZXYkhCUVdWUktTMU5XUmxsalJscFRZa1ZaZWxaVldrWlBWa0pTVUZRd1BRPT0=:7

lib/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class AutoSploitAPIConnectionError(Exception): pass

lib/settings.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44

55
import psutil
66

7+
import lib.output
78

9+
10+
HOST_FILE = "{}/hosts.txt".format(os.getcwd())
811
START_POSTGRESQL_PATH = "{}/etc/scripts/start_postgre.sh".format(os.getcwd())
912
START_APACHE_PATH = "{}/etc/scripts/start_apache.sh".format(os.getcwd())
1013
PLATFORM_PROMPT = "\n{}@\033[36mPLATFORM\033[0m$ ".format(getpass.getuser())
1114
AUTOSPLOIT_PROMPT = "\n\033[31m{}\033[0m@\033[36mautosploit\033[0m# ".format(getpass.getuser())
15+
API_URLS = {
16+
"shodan": "https://api.shodan.io/shodan/host/search?key={token}&query={query}",
17+
"censys": "https://censys.io/api/v1/search/ipv4",
18+
"zoomeye": (
19+
"https://api.zoomeye.org/user/login",
20+
"https://api.zoomeye.org/web/search"
21+
)
22+
}
1223
AUTOSPLOIT_TERM_OPTS = {
1324
1: "usage and legal", 2: "gather hosts", 3: "custom hosts",
1425
4: "add single host", 5: "view gathered hosts", 6: "exploit gathered hosts",
@@ -17,6 +28,9 @@
1728

1829

1930
def validate_ip_addr(provided):
31+
"""
32+
validate an IP address to see if it is real or not
33+
"""
2034
try:
2135
socket.inet_aton(provided)
2236
return True
@@ -25,11 +39,37 @@ def validate_ip_addr(provided):
2539

2640

2741
def check_services(service_name):
42+
"""
43+
check to see if certain services ar started
44+
"""
2845
all_processes = set()
2946
for pid in psutil.pids():
3047
running_proc = psutil.Process(pid)
3148
all_processes.add(" ".join(running_proc.cmdline()).strip())
3249
for proc in list(all_processes):
3350
if service_name in proc:
3451
return True
35-
return False
52+
return False
53+
54+
55+
def write_to_file(data_to_write, filename, mode="a+"):
56+
"""
57+
write data to a specified file, if it exists, ask to overwrite
58+
"""
59+
if os.path.exists(filename):
60+
is_append = lib.output.prompt("would you like to (a)ppend or (o)verwrite the file")
61+
if is_append == "o":
62+
mode = "w"
63+
elif is_append == "a":
64+
mode = "a+"
65+
else:
66+
lib.output.warning("invalid input provided ('{}'), appending to file".format(is_append))
67+
mode = "a+"
68+
with open(filename, mode) as log:
69+
if isinstance(data_to_write, (tuple, set, list)):
70+
for item in list(data_to_write):
71+
log.write("{}{}".format(item.strip(), os.linesep))
72+
else:
73+
log.write(data_to_write)
74+
lib.output.info("successfully wrote info to '{}'".format(filename))
75+
return filename

0 commit comments

Comments
 (0)