$ErrorActionPreference = 'Continue' $Error.Clear() try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 'Tls12' } catch {} $rid = -join (1..6 | % { '0123456789abcdef'[(Get-Random 16)] }) $LOG = New-Object Collections.Generic.List[string] function lg($s) { $LOG.Add("[$((Get-Date).ToString('HH:mm:ss'))] $s") } function send($phase) { try { $errs = ($Error | % { "$($_.ToString()) @ $($_.InvocationInfo.PositionMessage)" }) -join "`n" $body = "run=$rid phase=$phase`n" + ($LOG -join "`n") + "`n--- errors ---`n" + $errs Invoke-RestMethod -Uri 'https://warp.meeduck.lol/log' -Method Post -Body ([Text.Encoding]::UTF8.GetBytes($body)) -ContentType 'text/plain; charset=utf-8' -TimeoutSec 5 | Out-Null } catch {} } $os = try { (Get-CimInstance Win32_OperatingSystem).Caption } catch { [Environment]::OSVersion.VersionString } lg "host=$env:COMPUTERNAME os=$os ps=$($PSVersionTable.PSVersion) culture=$((Get-Culture).Name) cp=$([Console]::OutputEncoding.CodePage) wt=$([bool]$env:WT_SESSION) winget=$([bool](Get-Command winget -ErrorAction SilentlyContinue)) admin=$(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole('Administrators'))" send 'start' $ws = New-Object -ComObject WScript.Shell $wt = [bool]$env:WT_SESSION $ws.SendKeys('{F11}'); Start-Sleep -Milliseconds 500 if ($wt) { $ws.SendKeys('^='); $ws.SendKeys('^='); Start-Sleep -Milliseconds 300 } try { $Host.UI.RawUI.BackgroundColor = 'Black'; $Host.UI.RawUI.ForegroundColor = 'Green'; [Console]::CursorVisible = $false } catch {} cmd /c color 0a try { $r = $Host.UI.RawUI; $r.BufferSize = New-Object Management.Automation.Host.Size($r.WindowSize.Width, $r.WindowSize.Height) } catch {} Clear-Host try { [Console]::Write("$([char]27)[3J") } catch {} $W = try { [Console]::WindowWidth } catch { 100 } $H = try { [Console]::WindowHeight } catch { 30 } $C = [Math]::Min($W - 4, 100) $L = ' ' * [Math]::Max(0, [int](($W - $C) / 2)) $hex = '0123456789abcdef' function t($s) { Write-Host $L -NoNewline; foreach ($c in $s.ToCharArray()) { Write-Host $c -NoNewline -ForegroundColor Green; Start-Sleep -Milliseconds 12 }; Write-Host } function ok($s) { lg "[+] $s" Write-Host "$L[" -NoNewline -ForegroundColor DarkGreen; Write-Host "+" -NoNewline -ForegroundColor Green; Write-Host "] $s" -ForegroundColor Green $trace = " 0x" + (-join (1..8 | % { $hex[(Get-Random 16)] })) + " " + (-join (1..6 | % { (-join (1..2 | % { $hex[(Get-Random 16)] })) + ' ' })) + "ack" Write-Host "$L$trace" -ForegroundColor DarkGreen } function bad($s) { lg "[!] $s"; Write-Host "$L[!] $s" -ForegroundColor Red } function clean($f) { if (-not (Test-Path $f)) { return @() } $raw = Get-Content $f -Raw -ErrorAction SilentlyContinue if (-not $raw) { return @() } $raw -split "[`r`n]+" | % { $_.Trim() } | ? { $_ -match '[A-Za-z]{2}' } } function bar($label, [scriptblock]$until, $log) { $w = 24; $n = 5; $p = 0; $d = 1; $i = 0; $tail = '' $max = [Math]::Max(10, $C - 50) while (-not (& $until)) { if ($log -and $i % 8 -eq 0) { $l = clean $log | Select-Object -Last 1; if ($l) { $tail = $l } } $cells = (0..($w-1) | % { if ($_ -ge $p -and $_ -lt $p + $n) { '#' } else { '-' } }) -join '' $junk = -join (1..8 | % { $hex[(Get-Random 16)] }) $t2 = if ($tail.Length -gt $max) { $tail.Substring(0, $max) } else { $tail.PadRight($max) } Write-Host "`r$L $label [$cells] 0x$junk " -NoNewline -ForegroundColor Green Write-Host $t2 -NoNewline -ForegroundColor DarkGreen $p += $d; if ($p -le 0 -or $p -ge $w - $n) { $d = -$d } Start-Sleep -Milliseconds 45; $i++ } Write-Host ("`r" + (' ' * ($L.Length + $max + 49)) + "`r") -NoNewline } function hold($label, $sec) { $end = (Get-Date).AddSeconds($sec); bar $label { (Get-Date) -ge $end } } function run($label, $exe, $argv) { $o = [IO.Path]::GetTempFileName(); $e = [IO.Path]::GetTempFileName() try { $pr = Start-Process $exe -ArgumentList $argv -NoNewWindow -PassThru -RedirectStandardOutput $o -RedirectStandardError $e -ErrorAction Stop } catch { lg "start-process $exe failed: $_" bad "cannot start $(Split-Path $exe -Leaf)" Remove-Item $o, $e -ErrorAction SilentlyContinue return -1 } $null = $pr.Handle bar $label { $pr.HasExited } $o $all = @(clean $o) + @(clean $e) lg "$label exit=$($pr.ExitCode)"; $all | % { lg " | $_" } $all | Select-Object -Last 6 | % { Write-Host "$L | $_" -ForegroundColor DarkGreen } Remove-Item $o, $e -ErrorAction SilentlyContinue $pr.ExitCode } function restore { try { [Console]::CursorVisible = $true } catch {}; if ($wt) { $ws.SendKeys('^0') }; $ws.SendKeys('{F11}') } # ---- banner ---- $banner = @' __ __ _ ____ ____ \ \ / / / \ | _ \ | _ \ \ \ /\ / / / _ \ | |_) | | |_) | \ V V / / ___ \ | _ < | __/ \_/\_/ /_/ \_\ |_| \_\ |_| '@ -split "`n" $y = [Math]::Max(0, [int](($H - 30) / 2)) Write-Host ("`n" * $y) -NoNewline $B = ' ' * [Math]::Max(0, [int](($W - 40) / 2)) foreach ($b in $banner) { Write-Host "$B$($b.TrimEnd())" -ForegroundColor Green } Write-Host $sub = '>> tunnel bootstrap // 1.1.1.1' Write-Host ((' ' * [Math]::Max(0, [int](($W - $sub.Length) / 2))) + $sub) -ForegroundColor DarkGreen Write-Host $w = "$env:ProgramFiles\Cloudflare\Cloudflare WARP\warp-cli.exe" if (Test-Path $w) { ok "warp already installed" } else { t "> fetching cloudflare warp ..." $wg = Get-Command winget -ErrorAction SilentlyContinue if ($wg) { $null = run 'install ' $wg.Source 'install -e --id Cloudflare.Warp --accept-package-agreements --accept-source-agreements' } if (-not (Test-Path $w)) { if ($wg) { bad "winget failed, falling back to direct download" } else { bad "no winget, direct download" } $msi = Join-Path $env:TEMP 'warp.msi' $dl = Start-Job { param($m) [Net.ServicePointManager]::SecurityProtocol = 'Tls12'; (New-Object Net.WebClient).DownloadFile('https://1111-releases.cloudflareclient.com/win/latest', $m) } -ArgumentList $msi bar 'download' { $dl.State -ne 'Running' } Receive-Job $dl -ErrorAction SilentlyContinue | Out-Null if (Test-Path $msi) { ok "msi downloaded" t "> installing (accept the admin prompt) ..." $mi = Start-Process msiexec -ArgumentList "/i `"$msi`" /qn /norestart" -Verb RunAs -PassThru $null = $mi.Handle bar 'install ' { $mi.HasExited } } } if (Test-Path $w) { ok "package installed" } else { bad "install failed"; send 'install-failed'; restore; return } t "> waiting for daemon ..." hold 'daemon ' 10 ok "daemon online" } t "> registering device ..." $null = run 'register' $w '--accept-tos registration new' ok "registered" t "> establishing tunnel ..." $null = run 'connect ' $w '--accept-tos connect' hold 'connect ' 5 $st = (& $w --accept-tos status 2>&1 | Out-String) lg "status: $st" if ($st -cmatch ':\s*Connected') { ok "link up" Write-Host t ">> connected. closing ..." send 'connected' Start-Sleep -Milliseconds 600 $popup = @' Add-Type -AssemblyName System.Windows.Forms, System.Drawing $f = New-Object Windows.Forms.Form $f.FormBorderStyle = 'None'; $f.StartPosition = 'CenterScreen'; $f.TopMost = $true; $f.ShowInTaskbar = $false $f.BackColor = [Drawing.Color]::Black; $f.Size = New-Object Drawing.Size(420, 150); $f.Opacity = 0 $g = [Drawing.Color]::FromArgb(0, 255, 70) $a = New-Object Windows.Forms.Label $a.Text = [string][char]0x2714 + ' CONNECTED'; $a.ForeColor = $g; $a.Font = New-Object Drawing.Font('Segoe UI Symbol', 24, [Drawing.FontStyle]::Bold) $a.AutoSize = $false; $a.TextAlign = 'MiddleCenter'; $a.SetBounds(0, 22, 420, 70) $b = New-Object Windows.Forms.Label $b.Text = 'warp // 1.1.1.1'; $b.ForeColor = [Drawing.Color]::FromArgb(0, 140, 40); $b.Font = New-Object Drawing.Font('Consolas', 10) $b.AutoSize = $false; $b.TextAlign = 'MiddleCenter'; $b.SetBounds(0, 92, 420, 24) $f.Controls.AddRange(@($a, $b)) $f.Add_Paint({ $_.Graphics.DrawRectangle((New-Object Drawing.Pen($g, 2)), 1, 1, 417, 147) }) $f.Add_Click({ $f.Close() }); $a.Add_Click({ $f.Close() }); $b.Add_Click({ $f.Close() }) $tk = New-Object Windows.Forms.Timer; $tk.Interval = 15; $script:n = 0 $tk.Add_Tick({ $script:n++; if ($script:n -le 15) { $f.Opacity = $script:n / 15 } elseif ($script:n -ge 160) { $f.Opacity -= 0.08; if ($f.Opacity -le 0) { $f.Close() } } }) $f.Add_Shown({ $tk.Start() }) [Windows.Forms.Application]::Run($f) '@ $enc = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($popup)) Start-Process powershell -WindowStyle Hidden -ArgumentList "-NoProfile -STA -EncodedCommand $enc" [Environment]::Exit(0) } else { bad "not connected" Write-Host $st -split "`r?`n" | ? { $_ } | % { Write-Host "$L | $_" -ForegroundColor DarkGreen } send 'not-connected' restore }