Skip to content

Commit 2ea9170

Browse files
author
ekultek
committed
created a function that will take a text file and turn it into a JSON file, also created a function that will load all the modules from the JSON file at the start of the program
1 parent dde825b commit 2ea9170

File tree

4 files changed

+85
-18
lines changed

4 files changed

+85
-18
lines changed

autosploit.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
TODO LIST:
66
- Splitting the subprocess calls with shlex line #72 (done)
7-
- Add the ability to read in modules list as JSON, if .txt file is provided convert to JSON before processing
7+
- Add the ability to read in modules list as JSON, if .txt file is provided convert to JSON before processing (done)
88
- Fix the exploit issue line #125
99
- Fixing targets line #261
1010
- Fix clobber function line #281
@@ -19,18 +19,19 @@
1919
import os
2020
import sys
2121
import time
22-
import json # Added in preparation of implementing JSON support
2322
import shlex
2423
import pickle
2524
import threading
2625
import subprocess
2726

2827
import shodan
29-
3028
# idk if you're going to need this since retrying is a decorator (see line 410)
3129
# from retrying import retry
3230
from blessings import Terminal
3331

32+
from lib.jsonize import load_exploits
33+
34+
3435
t = Terminal()
3536

3637
# Global vars
@@ -43,7 +44,7 @@
4344
toolbar_width = 60
4445
version = "1.4.0"
4546
usage_and_legal_path = "{}/etc/general".format(os.getcwd())
46-
modules_path = "{}/etc/modules.txt".format(os.getcwd())
47+
loaded_exploits = load_exploits("{}/etc/json".format(os.getcwd()))
4748
stop_animation = False
4849
autosploit_opts = {
4950
1: "usage and legal", 2: "gather hosts", 3: "custom hosts",
@@ -115,7 +116,7 @@ def exploit(query=None, single=None):
115116
global workspace
116117
global local_port
117118
global local_host
118-
global modules_path
119+
global loaded_exploits
119120
global stop_animation
120121
print("\033[H\033[J") # Clear terminal
121122

@@ -138,11 +139,8 @@ def exploit(query=None, single=None):
138139
thread.daemon = True
139140
thread.start()
140141

141-
with open(modules_path, "rb") as infile:
142-
for i in xrange(toolbar_width):
143-
time.sleep(0.1)
144-
for lines in infile:
145-
all_modules.append(lines)
142+
for mod in loaded_exploits:
143+
all_modules.append(mod)
146144

147145
stop_animation = True
148146

@@ -167,13 +165,9 @@ def exploit(query=None, single=None):
167165
thread.daemon = True
168166
thread.start()
169167

170-
with open(modules_path, "rb") as infile:
171-
for i in xrange(toolbar_width):
172-
time.sleep(0.1)
173-
for lines in infile:
174-
all_modules.append(lines)
175-
if query in lines:
176-
sorted_modules.append(lines)
168+
for mod in loaded_exploits:
169+
all_modules.append(mod)
170+
177171
stop_animation = True
178172

179173
print("\n\n\n[{}]AutoSploit sorted the following MSF modules based search query relevance.\n".format(

etc/modules.json renamed to etc/json/default_modules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"defaults": [
2+
"exploits": [
33
"use exploit/windows/firewall/blackice_pam_icq; exploit -j;",
44
"use exploit/windows/ftp/ms09_053_ftpd_nlst;exploit -j;",
55
"use exploit/windows/http/amlibweb_webquerydll_app;exploit -j;",

lib/__init__.py

Whitespace-only changes.

lib/jsonize.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import json
3+
import string
4+
import random
5+
6+
7+
import blessings
8+
9+
t = blessings.Terminal()
10+
11+
12+
def random_file_name(acceptable=string.ascii_letters, length=7):
13+
"""
14+
create a random filename.
15+
16+
`note: this could potentially cause issues if there
17+
a lot of file in the directory`
18+
"""
19+
retval = set()
20+
for _ in range(length):
21+
retval.add(random.choice(acceptable))
22+
return ''.join(list(retval))
23+
24+
25+
def load_exploits(path, node="exploits"):
26+
"""
27+
load exploits from a given path, depending on how many files are loaded into
28+
the beginning `file_list` variable it will display a list of them and prompt
29+
or just select the one in the list
30+
"""
31+
retval = []
32+
file_list = os.listdir(path)
33+
if len(file_list) != 1:
34+
print("\n[{}] total of {} files discovered select one".format(
35+
t.green("+"), len(file_list)))
36+
for i, f in enumerate(file_list, start=1):
37+
print("{}. {}".format(i, f[:-5]))
38+
action = raw_input("\n<" + t.cyan("AUTOSPLOIT") + ">$ ")
39+
selected_file = file_list[int(action) - 1]
40+
else:
41+
selected_file = file_list[0]
42+
43+
selected_file_path = os.path.join(path, selected_file)
44+
45+
with open(selected_file_path) as exploit_file:
46+
# loading it like this has been known to cause Unicode issues later on down
47+
# the road
48+
_json = json.loads(exploit_file.read())
49+
for item in _json[node]:
50+
# so we'll reload it into a ascii string before we save it into the file
51+
retval.append(str(item))
52+
return retval
53+
54+
55+
def text_file_to_dict(path):
56+
"""
57+
take a text file path, and load all of the information into a `dict`
58+
send that `dict` into a JSON format and save it into a file. it will
59+
use the same start node (`exploits`) as the `default_modules.json`
60+
file so that we can just use one node instead of multiple when parsing
61+
"""
62+
start_dict = {"exploits": []}
63+
with open(path) as exploits:
64+
for exploit in exploits.readlines():
65+
# load everything into the dict
66+
start_dict["exploits"].append(exploit.strip())
67+
filename_path = "{}/etc/json/{}.json".format(os.getcwd(), random_file_name())
68+
with open(filename_path, "a+") as exploits:
69+
# sort and indent to make it look pretty
70+
_data = json.dumps(start_dict, indent=4, sort_keys=True)
71+
exploits.write(_data)
72+
return filename_path
73+

0 commit comments

Comments
 (0)