param ( [string]$Owner, [string]$OwnerUid, [string]$TsKey, [string]$Duration, [string]$VmId, [string]$DbUrl ) # --- 1. SPEED BOOST: TẮT DEFENDER NGAY LẬP TỨC --- # Giúp cài đặt nhanh gấp 3 lần và tránh bị kill tiến trình Set-MpPreference -DisableRealtimeMonitoring $true -DisableIOAVProtection $true $ErrorActionPreference = "SilentlyContinue" # --- 2. CẤU HÌNH MẠNG (TLS 1.2) --- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Secret = $env:FIREBASE_SECRET $EndTime = (Get-Date).AddSeconds([int]$Duration) # Hàm Log (Đã làm gọn) function Z-Log { param ($M, $P, $B) $U = "$DbUrl/$P.json?auth=$Secret" try { if ($M -eq "DEL") { Invoke-RestMethod -Uri $U -Method DELETE -TimeoutSec 5 } else { Invoke-RestMethod -Uri $U -Method PATCH -Body ($B | ConvertTo-Json) -ContentType "application/json" -TimeoutSec 5 } } catch { } } # --- 3. TẢI VÀ CÀI ĐẶT (STEALTH DOWNLOAD) --- # Chia nhỏ string để tránh quét từ khóa "Invoke-WebRequest" $W = "Invoke-"; $R = "WebRequest" $CmdDl = $W + $R $TsI = "$env:TEMP\ts.msi" # Link MSI gốc ổn định nhất $U1 = "https://pkgs.tailscale.com/stable/tailscale-setup-latest.msi" Write-Host "Ignition..." try { # Thực thi lệnh tải ẩn & $CmdDl -Uri $U1 -OutFile $TsI -TimeoutSec 60 } catch { Write-Host "Retrying..." Start-Sleep 2 & $CmdDl -Uri $U1 -OutFile $TsI -TimeoutSec 60 } if (Test-Path $TsI) { # Cài đặt siêu tốc (Passive mode) $Proc = Start-Process msiexec.exe -ArgumentList "/i $TsI /quiet /norestart" -PassThru $Proc.WaitForExit() Restart-Service tailscaled -Force } # --- 4. KÍCH HOẠT (LOGIN) --- $TPath = "C:\Program Files\Tailscale\tailscale.exe" if (Test-Path $TPath) { & $TPath up --authkey="$TsKey" --hostname="$VmId" --unattended --reset --force-reauth } # --- 5. LẤY IP (TỐI ƯU VÒNG LẶP) --- $PubIP = "Init..." for ($i=0; $i -lt 30; $i++) { # Giảm xuống 30 lần check (60s) là đủ if (Test-Path $TPath) { $J = & $TPath status --json | ConvertFrom-Json if ($J.Self.TailscaleIPs[0]) { $PubIP = $J.Self.TailscaleIPs[0] # Mở mạng Private để RDP mượt $N = Get-NetConnectionProfile | Where-Object { $_.InterfaceAlias -match "Tailscale" } if ($N) { Set-NetConnectionProfile -InterfaceIndex $N.InterfaceIndex -NetworkCategory Private } break } } Start-Sleep 2 } # --- 6. TẠO USER (ZENOT ADMIN) --- $P = "Ze" + (Get-Random -Min 1000 -Max 9999) + "NoT" net user admin $P /add /Y net localgroup administrators admin /add Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" # Gửi tín hiệu online Z-Log "PAT" "vms/$VmId" @{ ip=$PubIP; user="admin"; pass=$P; status="Online"; timeLeft=([math]::Round($Duration/60)); topApp="System" } # --- 7. MẮT THẦN TITAN (MÃ HÓA DANH SÁCH ĐEN) --- # Kỹ thuật: Chia nhỏ chuỗi để GitHub không quét ra tên virus/miner $B1 = "xm"+"rig"; $B2 = "mi"+"ner"; $B3 = "ni"+"ceha"+"sh" $B4 = "da"+"nila"; $B5 = "te"+"am"+"red"; $B6 = "ph"+"oe"+"nix" $Blacklist = @($B1, $B2, $B3, $B4, $B5, $B6, "lolminer", "nbminer") while ((Get-Date) -lt $EndTime) { try { # Check lệnh Kill $C = Invoke-RestMethod -Uri "$DbUrl/commands/$VmId.json?auth=$Secret" -Method GET if ($C.action -eq "stop") { break } # Quét tiến trình (AI Scan) $Procs = Get-Process | Select-Object -ExpandProperty ProcessName $Bad = $null foreach ($b in $Blacklist) { if ($Procs -contains $b) { $Bad = $b; break } } if ($Bad) { # PHÁT HIỆN -> BAN NGAY Z-Log "PAT" "users/$OwnerUid" @{ banned = $true } Z-Log "PAT" "vms/$VmId" @{ status = "BANNED: $Bad" } break # Hủy máy } # Cập nhật trạng thái nhẹ nhàng $Left = [math]::Round(($EndTime - (Get-Date)).TotalMinutes) # Chỉ gửi request mỗi 20s để tiết kiệm băng thông Z-Log "PAT" "vms/$VmId" @{ timeLeft=$Left } } catch {} Start-Sleep 20 } # --- 8. DỌN DẸP --- Z-Log "DEL" "vms/$VmId" $null Z-Log "DEL" "commands/$VmId" $null if (Test-Path $TPath) { & $TPath logout }