2323 raw_input = input
2424
2525
26+ def check_version_number (current_version ):
27+ """
28+ check the version number before creating an issue
29+ """
30+ version_checker = re .compile (r"version.=.\S\d.\d.(\d)?" , re .I )
31+ try :
32+ req = requests .get ("https://raw.githubusercontent.com/NullArray/AutoSploit/master/lib/banner.py" )
33+ available_version = version_checker .search (req .content ).group ().split ("=" )[- 1 ].split ('"' )[1 ]
34+ if available_version != current_version :
35+ return False
36+ return True
37+ except Exception as e :
38+ print e
39+ return True
40+
41+
2642def create_identifier (data ):
43+ """
44+ create the exception identifier
45+ """
2746 obj = hashlib .sha1 ()
2847 try :
2948 obj .update (data )
@@ -83,7 +102,7 @@ def find_url(params):
83102 split_information = str (html ).split ("\n " )
84103 for i , line in enumerate (split_information ):
85104 if searcher .search (line ) is not None :
86- href = split_information [i - 1 ]
105+ href = split_information [i ]
87106 if href is not None :
88107 soup = BeautifulSoup (href , "html.parser" )
89108 for item in soup .findAll ("a" ):
@@ -93,13 +112,17 @@ def find_url(params):
93112
94113
95114def hide_sensitive ():
115+ """
116+ hide sensitive information from the terminal
117+ """
96118 sensitive = (
97119 "--proxy" , "-P" , "--personal-agent" , "-q" , "--query" , "-C" , "--config" ,
98120 "--whitelist" , "--msf-path"
99121 )
100122 args = sys .argv
101123 for item in sys .argv :
102124 if item in sensitive :
125+ # TODO:/ we need to block the IP addresses in the -C argument
103126 try :
104127 item_index = args .index (item ) + 1
105128 hidden = '' .join ([x .replace (x , "*" ) for x in str (args [item_index ])])
@@ -119,56 +142,66 @@ def request_issue_creation(path, arguments, error_message):
119142 "do you want to create an anonymized issue?[y/N]: "
120143 )
121144 if question .lower ().startswith ("y" ):
122- # gonna read a chunk of it instead of one line
123- chunk = 4096
124- with open (path ) as data :
125- identifier = create_identifier (data .read (chunk ))
126- # gotta seek to the beginning of the file since it's already been read `4096` into it
127- data .seek (0 )
128- issue_title = "Unhandled Exception ({})" .format (identifier )
129-
130- issue_data = {
131- "title" : issue_title ,
132- "body" : (
133- "Autosploit version: `{}`\n "
134- "OS information: `{}`\n "
135- "Running context: `{}`\n "
136- "Error meesage: `{}`\n "
137- "Error traceback:\n ```\n {}\n ```\n "
138- "Metasploit launched: `{}`\n " .format (
139- lib .banner .VERSION ,
140- platform .platform (),
141- ' ' .join (sys .argv ),
142- error_message ,
143- open (path ).read (),
144- lib .settings .MSF_LAUNCHED ,
145+ if check_version_number (lib .banner .VERSION ):
146+ # gonna read a chunk of it instead of one line
147+ chunk = 4096
148+ with open (path ) as data :
149+ identifier = create_identifier (error_message )
150+ # gotta seek to the beginning of the file since it's already been read `4096` into it
151+ data .seek (0 )
152+ issue_title = "Unhandled Exception ({})" .format (identifier )
153+
154+ issue_data = {
155+ "title" : issue_title ,
156+ "body" : (
157+ "Autosploit version: `{}`\n "
158+ "OS information: `{}`\n "
159+ "Running context: `{}`\n "
160+ "Error mesage: `{}`\n "
161+ "Error traceback:\n ```\n {}\n ```\n "
162+ "Metasploit launched: `{}`\n " .format (
163+ lib .banner .VERSION ,
164+ platform .platform (),
165+ ' ' .join (sys .argv ),
166+ error_message ,
167+ open (path ).read (),
168+ lib .settings .MSF_LAUNCHED ,
169+ )
145170 )
146- )
147- }
171+ }
148172
149- _json_data = json .dumps (issue_data )
150- if sys .version_info > (3 ,): # python 3
151- _json_data = _json_data .encode ("utf-8" )
173+ _json_data = json .dumps (issue_data )
174+ if sys .version_info > (3 ,): # python 3
175+ _json_data = _json_data .encode ("utf-8" )
152176
153- if not ensure_no_issue (identifier ):
154- req = Request (
155- url = "https://api.github.com/repos/nullarray/autosploit/issues" , data = _json_data ,
156- headers = {"Authorization" : "token {}" .format (get_token (lib .settings .TOKEN_PATH ))}
157- )
158- urlopen (req , timeout = 10 ).read ()
159- lib .output .info (
160- "issue has been generated with the title '{}', at the following "
161- "URL '{}'" .format (
162- issue_title , find_url (identifier )
177+ if not ensure_no_issue (identifier ):
178+ req = Request (
179+ url = "https://api.github.com/repos/nullarray/autosploit/issues" , data = _json_data ,
180+ headers = {"Authorization" : "token {}" .format (get_token (lib .settings .TOKEN_PATH ))}
163181 )
164- )
182+ urlopen (req , timeout = 10 ).read ()
183+ lib .output .info (
184+ "issue has been generated with the title '{}', at the following "
185+ "URL '{}'" .format (
186+ issue_title , find_url (identifier )
187+ )
188+ )
189+ else :
190+ lib .output .error (
191+ "someone has already created this issue here: {}" .format (find_url (identifier ))
192+ )
193+ try :
194+ os .remove (path )
195+ except :
196+ pass
165197 else :
198+ sep = "-" * 35
166199 lib .output .error (
167- "someone has already created this issue here: {}" .format (find_url (identifier ))
200+ "it appears you are not using the current version of AutoSploit please update to the newest version "
201+ "and try again, this can also happen when a new update has been pushed and the cached raw page has "
202+ "not been updated yet. If you feel this is the later please create and issue on AutoSploits Github "
203+ "page with the following info:"
168204 )
169- try :
170- os .remove (path )
171- except :
172- pass
205+ print ("{}\n {}\n {}" .format (sep , open (path ).read (), sep ))
173206 else :
174207 lib .output .info ("the issue has been logged to a file in path: '{}'" .format (path ))
0 commit comments