# Install attackscout-agent on Windows from the GitHub releases, after checking # its SHA-256 against checksums.txt. No administrator rights needed. # # irm https://raw.githubusercontent.com/AttackScout/attackscout-agent/main/install.ps1 | iex # # Environment: # ATTACKSCOUT_VERSION version to install, for example 0.2.3 (default: latest) # ATTACKSCOUT_INSTALL_DIR target directory (default: %LOCALAPPDATA%\Programs\attackscout-agent), # added to the user PATH when missing # ATTACKSCOUT_NO_MODIFY_PATH set to 1 to leave the user PATH unchanged # # The script downloads two files from github.com and writes one binary. It # sends nothing else, and the tool itself uses no network by default. $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $repo = 'AttackScout/attackscout-agent' $arch = switch ($env:PROCESSOR_ARCHITECTURE) { 'AMD64' { 'amd64' } 'ARM64' { 'arm64' } default { throw "unsupported architecture $($env:PROCESSOR_ARCHITECTURE) (amd64 and arm64 only)" } } $version = if ($env:ATTACKSCOUT_VERSION) { $env:ATTACKSCOUT_VERSION } else { 'latest' } $version = $version.TrimStart('v') if ($version -eq 'latest') { # /releases/latest redirects to /releases/tag/vX.Y.Z: no API call, no rate limit. $req = [System.Net.HttpWebRequest]::Create("https://github.com/$repo/releases/latest") $req.AllowAutoRedirect = $false $resp = $req.GetResponse() $location = $resp.Headers['Location'] $resp.Close() if (-not $location -or $location -notmatch '/tag/v?([0-9A-Za-z.\-]+)$') { throw 'cannot find the latest version (set ATTACKSCOUT_VERSION)' } $version = $Matches[1] } if ($version -notmatch '^[0-9A-Za-z.\-]+$') { throw "invalid version $version" } $archive = "attackscout-agent_${version}_windows_${arch}.zip" $base = "https://github.com/$repo/releases/download/v$version" $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("attackscout-agent-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host "downloading $archive" try { Invoke-WebRequest -UseBasicParsing -Uri "$base/$archive" -OutFile (Join-Path $tmp $archive) Invoke-WebRequest -UseBasicParsing -Uri "$base/checksums.txt" -OutFile (Join-Path $tmp 'checksums.txt') } catch { throw "cannot download ${archive}: does version $version exist? ($($_.Exception.Message))" } $want = $null foreach ($line in Get-Content (Join-Path $tmp 'checksums.txt')) { $parts = $line -split '\s+' if ($parts.Count -ge 2 -and $parts[1] -eq $archive) { $want = $parts[0].ToLowerInvariant() } } if (-not $want) { throw "$archive is not listed in checksums.txt" } $got = (Get-FileHash -Algorithm SHA256 (Join-Path $tmp $archive)).Hash.ToLowerInvariant() if ($want -ne $got) { throw "checksum mismatch for ${archive}: expected $want, got $got" } Write-Host 'checksum ok' Expand-Archive -Path (Join-Path $tmp $archive) -DestinationPath (Join-Path $tmp 'x') -Force $dir = if ($env:ATTACKSCOUT_INSTALL_DIR) { $env:ATTACKSCOUT_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\attackscout-agent' } New-Item -ItemType Directory -Force -Path $dir | Out-Null Copy-Item -Force (Join-Path $tmp 'x\attackscout-agent.exe') (Join-Path $dir 'attackscout-agent.exe') Write-Host "installed $dir\attackscout-agent.exe" $userPath = [string][Environment]::GetEnvironmentVariable('Path', 'User') if ($env:ATTACKSCOUT_NO_MODIFY_PATH -ne '1' -and -not (($userPath -split ';') -contains $dir)) { [Environment]::SetEnvironmentVariable('Path', (($userPath.TrimEnd(';'), $dir) -join ';').TrimStart(';'), 'User') $env:Path = "$env:Path;$dir" Write-Host "added $dir to the user PATH (open a new terminal to use it)" } & (Join-Path $dir 'attackscout-agent.exe') version } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue }