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+ return True
39+
40+
2641def create_identifier (data ):
42+ """
43+ create the exception identifier
44+ """
2745 obj = hashlib .sha1 ()
2846 try :
2947 obj .update (data )
@@ -83,7 +101,7 @@ def find_url(params):
83101 split_information = str (html ).split ("\n " )
84102 for i , line in enumerate (split_information ):
85103 if searcher .search (line ) is not None :
86- href = split_information [i - 1 ]
104+ href = split_information [i ]
87105 if href is not None :
88106 soup = BeautifulSoup (href , "html.parser" )
89107 for item in soup .findAll ("a" ):
@@ -93,13 +111,17 @@ def find_url(params):
93111
94112
95113def hide_sensitive ():
114+ """
115+ hide sensitive information from the terminal
116+ """
96117 sensitive = (
97118 "--proxy" , "-P" , "--personal-agent" , "-q" , "--query" , "-C" , "--config" ,
98119 "--whitelist" , "--msf-path"
99120 )
100121 args = sys .argv
101122 for item in sys .argv :
102123 if item in sensitive :
124+ # TODO:/ we need to block the IP addresses in the -C argument
103125 try :
104126 item_index = args .index (item ) + 1
105127 hidden = '' .join ([x .replace (x , "*" ) for x in str (args [item_index ])])
@@ -119,56 +141,66 @@ def request_issue_creation(path, arguments, error_message):
119141 "do you want to create an anonymized issue?[y/N]: "
120142 )
121143 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 ,
144+ if check_version_number (lib .banner .VERSION ):
145+ # gonna read a chunk of it instead of one line
146+ chunk = 4096
147+ with open (path ) as data :
148+ identifier = create_identifier (error_message )
149+ # gotta seek to the beginning of the file since it's already been read `4096` into it
150+ data .seek (0 )
151+ issue_title = "Unhandled Exception ({})" .format (identifier )
152+
153+ issue_data = {
154+ "title" : issue_title ,
155+ "body" : (
156+ "Autosploit version: `{}`\n "
157+ "OS information: `{}`\n "
158+ "Running context: `{}`\n "
159+ "Error mesage: `{}`\n "
160+ "Error traceback:\n ```\n {}\n ```\n "
161+ "Metasploit launched: `{}`\n " .format (
162+ lib .banner .VERSION ,
163+ platform .platform (),
164+ ' ' .join (sys .argv ),
165+ error_message ,
166+ open (path ).read (),
167+ lib .settings .MSF_LAUNCHED ,
168+ )
145169 )
146- )
147- }
170+ }
148171
149- _json_data = json .dumps (issue_data )
150- if sys .version_info > (3 ,): # python 3
151- _json_data = _json_data .encode ("utf-8" )
172+ _json_data = json .dumps (issue_data )
173+ if sys .version_info > (3 ,): # python 3
174+ _json_data = _json_data .encode ("utf-8" )
152175
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 )
176+ if not ensure_no_issue (identifier ):
177+ req = Request (
178+ url = "https://api.github.com/repos/nullarray/autosploit/issues" , data = _json_data ,
179+ headers = {"Authorization" : "token {}" .format (get_token (lib .settings .TOKEN_PATH ))}
163180 )
164- )
181+ urlopen (req , timeout = 10 ).read ()
182+ lib .output .info (
183+ "issue has been generated with the title '{}', at the following "
184+ "URL '{}'" .format (
185+ issue_title , find_url (identifier )
186+ )
187+ )
188+ else :
189+ lib .output .error (
190+ "someone has already created this issue here: {}" .format (find_url (identifier ))
191+ )
192+ try :
193+ os .remove (path )
194+ except :
195+ pass
165196 else :
197+ sep = "-" * 35
166198 lib .output .error (
167- "someone has already created this issue here: {}" .format (find_url (identifier ))
199+ "it appears you are not using the current version of AutoSploit please update to the newest version "
200+ "and try again, this can also happen when a new update has been pushed and the cached raw page has "
201+ "not been updated yet. If you feel this is the later please create and issue on AutoSploits Github "
202+ "page with the following info:"
168203 )
169- try :
170- os .remove (path )
171- except :
172- pass
204+ print ("{}\n {}\n {}" .format (sep , open (path ).read (), sep ))
173205 else :
174- lib .output .info ("the issue has been logged to a file in path: '{}'" .format (path ))
206+ lib .output .info ("the issue has been logged to a file in path: '{}'" .format (path ))
0 commit comments