Install ps1
Install ps1
Install ps1
#
# CommandoVM Installation Script
#
# To execute this script:
# 1) Open powershell window as administrator
# 2) Allow script execution by running command "Set-ExecutionPolicy Unrestricted"
# 3) Unblock the install script by running "Unblock-File .\install.ps1"
# 4) Execute the script by running ".\install.ps1"
#
###########################################
param (
[string]$password = "",
[string]$profile_file = $null,
[bool]$nochecks = $false
)
$rc = $true
} catch {
$rc = $false
}
$rc
}
.DESCRIPTION
Convert a JSON string into a hash table, without any validation
.OUTPUTS
[hashtable] or $null
#>
Add-Type -Assembly system.web.extensions
$ps_js = New-Object system.web.script.serialization.javascriptSerializer
try {
$result = $ps_js.DeserializeObject($item)
} catch {
$result = $null
}
# Cast dictionary to hashtable
[hashtable] $result
}
.DESCRIPTION
Convert a hashtable to a JSON string, without any validation
.OUTPUTS
[string] or $null
#>
Add-Type -Assembly system.web.extensions
$ps_js = New-Object system.web.script.serialization.javascriptSerializer
$result
}
function Import-JsonFile {
<#
.DESCRIPTION
Load a hashtable from a JSON file
.OUTPUTS
[hashtable] or $null
#>
param([string] $path)
try {
$json = Get-Content $path
$result = ConvertFrom-Json $json
} catch {
$result = $null
}
$result
}
.DESCRIPTION
Make a new installer package named installer. This package uses the custom
packages.json file specified by the user.
User can then call "Install-BoxStarterPackage installer" using the local
repo.
#>
$Tmp = [System.IO.Path]::GetTempFileName()
Write-Host -ForegroundColor Green "packages file is" + $tmp
ConvertTo-Json @{"packages" = $packages} | Out-File -FilePath $Tmp
if ([System.IO.Path]::IsPathRooted($TemplateDir)) {
$ToolsDir = Join-Path $TemplateDir "tools"
} else {
$Here = Get-Location
$ToolsDir = Join-Path (Join-Path $Here $TemplateDir) "tools"
}
$Dest = Join-Path $ToolsDir "packages.json"
function installBoxStarter()
{
<#
.SYNOPSIS
Install BoxStarter on the current system
.DESCRIPTION
Install BoxStarter on the current system. Returns $true or $false to indicate
success or failure. On
fresh windows 7 systems, some root certificates are not installed and updated
properly. Therefore,
this funciton also temporarily trust all certificates before installing
BoxStarter.
#>
# Try to install BoxStarter as is first, then fall back to be over trusing only
if this step fails.
try {
iex ((New-Object
System.Net.WebClient).DownloadString('https://boxstarter.org/bootstrapper.ps1'));
get-boxstarter -Force
return $true
} catch {
}
# https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-
https-error
# Allows current PowerShell session to trust all certificates
# Also a good find: https://www.briantist.com/errors/could-not-establish-trust-
relationship-for-the-ssltls-secure-channel/
try {
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
} catch {
Write-Debug "Failed to add new type"
}
try {
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
} catch {
Write-Debug "Failed to find SSL type...1"
}
try {
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls'
} catch {
Write-Debug "Failed to find SSL type...2"
}
$prevSecProtocol = [System.Net.ServicePointManager]::SecurityProtocol
$prevCertPolicy = [System.Net.ServicePointManager]::CertificatePolicy
Write-Host "[+] Installing Boxstarter"
# Become overly trusting
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object
TrustAllCertsPolicy
# download and instal boxstarter
iex ((New-Object
System.Net.WebClient).DownloadString('https://boxstarter.org/bootstrapper.ps1'));
get-boxstarter -Force
# Restore previous trust settings for this PowerShell session
# Note: SSL certs trusted from installing BoxStarter above will be trusted for
the remaining PS session
[System.Net.ServicePointManager]::SecurityProtocol = $prevSecProtocol
[System.Net.ServicePointManager]::CertificatePolicy = $prevCertPolicy
return $true
}
function Wait-ForInstall ($seconds) {
$doneDT = (Get-Date).AddSeconds($seconds)
while($doneDT -gt (Get-Date)) {
$secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds
$percent = ($seconds - $secondsLeft) / $seconds * 100
Write-Progress -Activity "Please read install notes on console below" -Status
"Beginning install in..." -SecondsRemaining $secondsLeft -PercentComplete $percent
[System.Threading.Thread]::Sleep(500)
}
Write-Progress -Activity "Waiting" -Status "Beginning install..."
-SecondsRemaining 0 -Completed
}
Write-Host "`n"
Write-Host "
____________________________________________________________________________ "
-ForegroundColor Red
Write-Host "|
|" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host "
" -ForegroundColor Green -NoNewline; Write-Host "
|" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host "_________
.___ " -ForegroundColor Green -NoNewline; Write-Host " |"
-ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host "\_ ___ \
____ _____ _____ _____ ____ __| _/____ " -ForegroundColor Green
-NoNewline; Write-Host " |" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host "/ \ \/ /
_ \ / \ / \\__ \ / \ / __ |/ _ \ " -ForegroundColor Green
-NoNewline; Write-Host " |" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host "\
\___( <_> ) Y Y \ Y Y \/ __ \| | \/ /_/ ( <_> )" -ForegroundColor Green
-NoNewline; Write-Host " |" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host " \______
/\____/|__|_| /__|_| (____ /___| /\____ |\____/ " -ForegroundColor Green
-NoNewline; Write-Host " |" -ForegroundColor Red
Write-Host "| " -ForegroundColor Red -NoNewline; Write-Host " \/
\/ \/ \/ \/ \/ " -ForegroundColor Green -NoNewline; Write-
Host " |" -ForegroundColor Red
Write-Host "| C O M P L E T E M A N D I A N T
|" -ForegroundColor Red
Write-Host "| O F F E N S I V E V M
|" -ForegroundColor Red
Write-Host "|
|" -ForegroundColor Red
Write-Host "| Version 2020.1
|" -ForegroundColor Red
Write-Host "| commandovm@fireeye.com
|" -ForegroundColor Red
Write-Host "|
____________________________________________________________________________|"
-ForegroundColor Red
Write-Host "|
|" -ForegroundColor Red
Write-Host "| Created by
|" -ForegroundColor Red
Write-Host "| Jake Barteaux @day1player
|" -ForegroundColor Red
Write-Host "| Proactive Services
|" -ForegroundColor Red
Write-Host "| Blaine Stancill @MalwareMechanic
|" -ForegroundColor Red
Write-Host "| Nhan Huynh
|" -ForegroundColor Red
Write-Host "| FireEye Labs Advanced Reverse Engineering
|" -ForegroundColor Red
Write-Host "|
____________________________________________________________________________|"
-ForegroundColor Red
Write-Host ""
if ([string]::IsNullOrEmpty($profile_file)) {
Write-Host "[+] No custom profile is provided..."
$profile = $null
} else {
Write-Host "[+] Using the following profile $profile_file"
$profile = Import-JsonFile $profile_file
if ($profile -eq $null) {
Write-Error "Invaild configuration! Exiting..."
exit 1
}
# Confirmation message
Write-Warning "[+] You are using a custom profile and list of packages,"
Write-Warning "[+] You will NOT receive new tools automatically when running
choco update."
} else {
Write-Host "`tupdates appear to be in order" -ForegroundColor Green
}
- This install is not 100% unattended. Please monitor the install for possible
failures. If install
fails you may restart the install by re-running the install script with the
following command:
- Install is not complete until the desktop is cleaned, the readme is placed on the
desktop, and the
desktop background is set with the Commando VM logo.
# Boxstarter options
$Boxstarter.RebootOk = $true # Allow reboots?
$Boxstarter.NoPassword = $false # Is this a machine with no login password?
$Boxstarter.AutoLogin = $true # Save my password securely and auto-login after a
reboot
Set-BoxstarterConfig -NugetSources
"https://www.myget.org/F/fireeye/api/v2;https://chocolatey.org/api/v2"
$PackageName = "MyInstaller"
$TemplateDir = $profile.env.TEMPLATE_DIR
$Packages = $profile.packages
Make-InstallerPackage $PackageName $TemplateDir $Packages
Invoke-BoxStarterBuild $PackageName
Install-BoxStarterPackage -PackageName $PackageName -Credential $cred
if ([System.Environment]::OSVersion.Version.Major -eq 6) {
Install-BoxStarterPackage -PackageName commandovm.win7.config.fireeye
-Credential $cred
} elseif ([System.Environment]::OSVersion.Version.Major -eq 10) {
iex "choco upgrade -y commandovm.win10.preconfig.fireeye"
Install-BoxStarterPackage -PackageName commandovm.win10.config.fireeye
-Credential $cred
}
exit 0