33Autosploit Core, beta development version
44
55TODO LIST:
6- - Splitting the subprocess calls with shlex line #72
6+ - Splitting the subprocess calls with shlex line #72 (done)
77 - Fix the exploit issue line #125
88 - Fixing targets line #261
99 - Fix clobber function line #281
1818import os
1919import sys
2020import time
21+ import shlex
2122import pickle
23+ import threading
24+ import subprocess
25+
2226import shodan
2327
2428# idk if you're going to need this since retrying is a decorator (see line 410)
2529# from retrying import retry
2630from blessings import Terminal
27- from subprocess import PIPE , Popen
2831
2932t = Terminal ()
3033
3942version = "1.4.0"
4043usage_and_legal_path = "{}/etc/general" .format (os .getcwd ())
4144modules_path = "{}/etc/modules.txt" .format (os .getcwd ())
45+ stop_animation = False
4246autosploit_opts = {
4347 1 : "usage and legal" , 2 : "gather hosts" , 3 : "custom hosts" ,
4448 4 : "add single host" , 5 : "view gathered hosts" , 6 : "exploit gathered hosts" ,
45- # changing quit to 99 so that we can keep adding without having to change
46- # the numbers
4749 99 : "quit"
4850}
4951
@@ -60,6 +62,22 @@ def logo(line_sep="#--", space=" " * 30):
6062""" .format (sep1 = line_sep , v_num = version , space_sep = space )))
6163
6264
65+ def animation (text ):
66+ global stop_animation
67+ i = 0
68+ while not stop_animation :
69+ temp_text = list (text )
70+ if i >= len (temp_text ):
71+ i = 0
72+ temp_text [i ] = temp_text [i ].upper ()
73+ temp_text = '' .join (temp_text )
74+ sys .stdout .write ("\033 [96m\033 [1m{}...\r \033 [0m" .format (temp_text ))
75+ sys .stdout .flush ()
76+ i += 1
77+ time .sleep (0.1 )
78+ else : pass
79+
80+
6381def usage ():
6482 """Usage & Legal."""
6583 global usage_and_legal_path
@@ -78,13 +96,11 @@ def cmdline(command):
7896 I intend to have the issue resolved by Version 1.5.0.
7997 """
8098
81- # TODO:/
82- # split the command by shlex, this will help with
83- # most command injection sequences.
99+ command = shlex .split (command )
84100
85- process = Popen (
101+ process = subprocess . Popen (
86102 args = command ,
87- stdout = PIPE ,
103+ stdout = subprocess . PIPE ,
88104 shell = True
89105 )
90106 return process .communicate ()[0 ]
@@ -97,6 +113,7 @@ def exploit(query=None, single=None):
97113 global local_port
98114 global local_host
99115 global modules_path
116+ global stop_animation
100117 print ("\033 [H\033 [J" ) # Clear terminal
101118
102119 logo ()
@@ -112,18 +129,18 @@ def exploit(query=None, single=None):
112129 proceed = raw_input ("[" + t .magenta ("?" ) + "]Continue? [Y]es/[N]o: " ).lower ()
113130
114131 if proceed == 'y' :
115- print ("\n \n \n [{}]Loading modules..." .format (t .green ("+" )))
116- # Progress bar
117- sys .stdout .write ("[%s]" % (" " * toolbar_width ))
118- sys .stdout .flush ()
119- sys .stdout .write ("\b " * (toolbar_width + 1 ))
132+ thread = threading .Thread (target = animation , args = ("loading modules" , ))
133+ thread .daemon = True
134+ thread .start ()
120135
121136 with open (modules_path , "rb" ) as infile :
122137 for i in xrange (toolbar_width ):
123138 time .sleep (0.1 )
124139 for lines in infile :
125140 all_modules .append (lines )
126141
142+ stop_animation = True
143+
127144 print ("\n \n \n [{}]Done. Launching exploits." .format (t .green ("+" )))
128145 # TODO:/
129146 # exploit is not referenced anywhere around here
@@ -138,25 +155,21 @@ def exploit(query=None, single=None):
138155 print ("[{}]Unhandled Option. Defaulting to Main Menu" .format (t .red ("!" )))
139156
140157 else :
141- print ("[{}]Sorting modules relevant to the specified platform." .format (t .green ("+" )))
142- print ("[{}]This may take a while...\n \n \n " .format (t .green ("+" )))
143-
144- # Progress bar
145- sys .stdout .write ("[%s]" % (" " * toolbar_width ))
146- sys .stdout .flush ()
147- sys .stdout .write ("\b " * (toolbar_width + 1 ))
148-
149- with open (modules_path , "rb" ) as infile :
150- for i in xrange (toolbar_width ):
151- time .sleep (0.1 )
152- for lines in infile :
153- all_modules .append (lines )
154- if query in lines :
155- sorted_modules .append (lines )
156-
157- # update the bar
158- sys .stdout .write ('\033 [94m' + "|" + '\033 [0m' )
159- sys .stdout .flush ()
158+
159+ thread = threading .Thread (target = animation , args = (
160+ "sorting modules by relevance, this may take awhile" ,
161+ ))
162+ thread .daemon = True
163+ thread .start ()
164+
165+ with open (modules_path , "rb" ) as infile :
166+ for i in xrange (toolbar_width ):
167+ time .sleep (0.1 )
168+ for lines in infile :
169+ all_modules .append (lines )
170+ if query in lines :
171+ sorted_modules .append (lines )
172+ stop_animation = True
160173
161174 print ("\n \n \n [{}]AutoSploit sorted the following MSF modules based search query relevance.\n " .format (t .green ("+" )))
162175 # Print out the sorted modules
@@ -256,6 +269,7 @@ def settings(single=None):
256269def targets (clobber = True ):
257270 """Function to gather target host(s) from Shodan."""
258271 global query
272+ global stop_animation
259273
260274 print ("\033 [H\033 [J" ) # Clear terminal
261275 logo ()
@@ -280,10 +294,9 @@ def targets(clobber=True):
280294 print ("\n [{}]Critical. An error was raised with the following error message.\n " .format (t .red ("!" )))
281295 sys .exit () # must use an integer with sys.exit()
282296
283- # Setup progress bar
284- sys .stdout .write ("[%s]" % (" " * toolbar_width ))
285- sys .stdout .flush ()
286- sys .stdout .write ("\b " * (toolbar_width + 1 ))
297+ thread = threading .Thread (target = animation , args = ("collecting results" , ))
298+ thread .daemon = True
299+ thread .start ()
287300
288301 # TODO:/
289302 # edit the clobber function to work properly
@@ -294,11 +307,8 @@ def targets(clobber=True):
294307 for service in result ['matches' ]:
295308 log .write ("{}{}" .format (service ['ip_str' ], os .linesep ))
296309
297- # update the bar
298- sys .stdout .write ('\033 [94m' + "|" + '\033 [0m' )
299- sys .stdout .flush ()
300-
301- hostpath = os .path .abspath ("hosts.txt" )
310+ hostpath = os .path .abspath ("hosts.txt" )
311+ stop_animation = True
302312
303313 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
304314 print ("[{}]Host list saved to {}" .format (t .green ("+" ), hostpath ))
@@ -311,11 +321,8 @@ def targets(clobber=True):
311321 log .write (service ['ip_str' ])
312322 log .write ("\n " )
313323
314- # update the bar
315- sys .stdout .write ('\033 [94m' + "|" + '\033 [0m' )
316- sys .stdout .flush ()
317-
318324 hostpath = os .path .abspath ("hosts.txt" )
325+ stop_animation = True
319326
320327 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
321328 print ("[{}]Hosts appended to list at " .format (t .green ("+" ), hostpath ))
0 commit comments