import requests, json, time, sys with open("/tmp/agent_b64.txt") as f: b64 = f.read().strip() print("Base64 length:", len(b64)) token_r = requests.post("http://localhost:3001/api/auth/login", json={"email": "claude-api@azcomputerguru.com", "password": "ClaudeAPI2026!@#"}) token = token_r.json()["token"] headers = {"Authorization": "Bearer " + token, "Content-Type": "application/json"} agent_id = "d28a1c90-47d7-448f-a287-197bc8892234" chunk_size = 200000 chunks = [b64[i:i+chunk_size] for i in range(0, len(b64), chunk_size)] print("Chunks:", len(chunks)) def send_cmd(cmd, timeout=60, wait=15): r = requests.post( "http://localhost:3001/api/agents/" + agent_id + "/command", headers=headers, json={"command_type": "powershell", "command": cmd, "timeout_seconds": timeout} ) cmd_id = r.json()["command_id"] time.sleep(wait) r2 = requests.get("http://localhost:3001/api/commands/" + cmd_id, headers=headers) return r2.json() # Chunk 1: create file cmd = "$b = [Convert]::FromBase64String('" + chunks[0] + "'); New-Item -ItemType Directory -Path C:/Temp -Force | Out-Null; [System.IO.File]::WriteAllBytes('C:/Temp/agent_chunk.bin', $b); Write-Output ('Chunk 1: ' + $b.Length.ToString() + ' bytes')" d = send_cmd(cmd) print("Chunk 1:", d["status"], d.get("stdout","")) if d["status"] != "completed": print("ERROR:", (d.get("stderr","") or "")[:300]) sys.exit(1) # Append remaining chunks for i, chunk in enumerate(chunks[1:], 2): cmd = "$b = [Convert]::FromBase64String('" + chunk + "'); $f = [System.IO.File]::Open('C:/Temp/agent_chunk.bin', [System.IO.FileMode]::Append); $f.Write($b, 0, $b.Length); $f.Close(); Write-Output ('Chunk " + str(i) + ": ' + $b.Length.ToString() + ' bytes')" d = send_cmd(cmd, wait=10) print("Chunk", i, ":", d["status"], d.get("stdout","")) if d["status"] != "completed": print("ERROR:", (d.get("stderr","") or "")[:300]) sys.exit(1) # Verify final size d = send_cmd("(Get-Item C:/Temp/agent_chunk.bin).Length", wait=5) print("Final size:", d.get("stdout","").strip(), "(expected 3577856)") # Now create update script that stops service, replaces binary, starts service update_cmd = """ $src = 'C:/Temp/agent_chunk.bin' $dst = 'C:/Program Files/GuruRMM/gururmm-agent.exe' $bak = 'C:/Program Files/GuruRMM/gururmm-agent.exe.bak' Copy-Item $dst $bak -Force Stop-Service GuruRMMAgent -Force Start-Sleep -Seconds 2 Copy-Item $src $dst -Force Start-Service GuruRMMAgent Write-Output 'Agent updated and restarted' """ print("\nNow creating scheduled task to perform the update...") sched_cmd = 'schtasks /create /tn AgentUpdate /tr "powershell.exe -ExecutionPolicy Bypass -Command \\"' + update_cmd.replace('\n', '; ').strip() + '\\"" /sc ONCE /st 00:00 /sd 01/01/2030 /ru SYSTEM /f' d = send_cmd(sched_cmd, wait=5) print("Sched task create:", d["status"], d.get("stdout",""), d.get("stderr","")[:200] if d.get("stderr") else "") d = send_cmd("schtasks /run /tn AgentUpdate", wait=5) print("Sched task run:", d["status"], d.get("stdout","")) print("\nAgent will restart momentarily. Wait 30s then check connection.")