Files
atomic-red-team/execution-frameworks/Invoke-AtomicRedTeam/install-atomicredteam.ps1
T

95 lines
3.8 KiB
PowerShell
Raw Normal View History

2019-02-06 11:52:40 -07:00
function Install-AtomicRedTeam {
2019-09-12 15:02:29 -06:00
<#
2019-02-06 11:52:40 -07:00
.SYNOPSIS
This is a simple script to download and install Atomic Red Team Invoke-AtomicRedTeam Powershell Framework.
Atomic Function: Install-AtomicRedTeam
Author: Red Canary Research
License: MIT License
Required Dependencies: powershell-yaml
Optional Dependencies: None
.PARAMETER DownloadPath
Specifies the desired path to download Atomic Red Team.
.PARAMETER InstallPath
Specifies the desired path for where to install Atomic Red Team.
2019-11-11 15:26:23 -06:00
.PARAMETER Force
Delete the existing InstallPath before installation if it exists.
2019-02-06 11:52:40 -07:00
.EXAMPLE
Install Atomic Red Team
PS> Install-AtomicRedTeam.ps1
.NOTES
Use the '-Verbose' option to print detailed information.
#>
2019-09-12 15:02:29 -06:00
[CmdletBinding()]
Param(
[Parameter(Mandatory = $False, Position = 0)]
2019-11-11 15:26:23 -06:00
[string]$InstallPath = $( if ($IsLinux -or $IsMacOS) { $Env:HOME + "/AtomicRedTeam" } else { $env:HOMEDRIVE + "\AtomicRedTeam" }),
2019-09-12 15:02:29 -06:00
2019-11-11 15:26:23 -06:00
[Parameter(Mandatory = $False, Position = 1)]
[string]$DownloadPath = $( if ($IsLinux -or $IsMacOS) { $Env:HOME + "/AtomicRedTeam" } else { $env:HOMEDRIVE + "\AtomicRedTeam" }),
2019-02-06 11:52:40 -07:00
2019-11-11 15:26:23 -06:00
[Parameter(Mandatory = $False)]
[switch]$Force = $False # delete the existing install directory and reinstall
2019-09-12 15:02:29 -06:00
)
2019-02-06 11:52:40 -07:00
$modulePath = Join-Path "$InstallPath" "execution-frameworks\Invoke-AtomicRedTeam\Invoke-AtomicRedTeam\Invoke-AtomicRedTeam.psm1"
2019-11-11 15:26:23 -06:00
if ($Force -or -Not (Test-Path -Path $InstallPath )) {
2019-09-12 15:02:29 -06:00
write-verbose "Directory Creation"
2019-11-11 15:26:23 -06:00
if ($Force) {
Try {
if (Test-Path $InstallPath) { Remove-Item -Path $InstallPath -Recurse -Force -ErrorAction Stop | Out-Null }
2019-11-11 15:26:23 -06:00
}
Catch {
Write-Host -ForegroundColor Red $_.Exception.Message
return
}
}
2019-09-12 15:02:29 -06:00
New-Item -ItemType directory -Path $InstallPath | Out-Null
2019-11-11 15:26:23 -06:00
2019-09-12 15:02:29 -06:00
write-verbose "Setting variables for remote URL and download Path"
$url = "https://github.com/redcanaryco/atomic-red-team/archive/master.zip"
2019-11-11 15:26:23 -06:00
$path = Join-Path $DownloadPath "master.zip"
2019-09-12 15:02:29 -06:00
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$webClient = new-object System.Net.WebClient
write-verbose "Beginning download from Github"
$webClient.DownloadFile( $url, $path )
2019-02-06 11:52:40 -07:00
2019-11-11 15:26:23 -06:00
write-verbose "Extracting ART to $InstallPath"
$lp = Join-Path "$DownloadPath" "master.zip"
expand-archive -LiteralPath $lp -DestinationPath "$InstallPath" -Force:$Force
$unzipPath = Join-Path $InstallPath "atomic-red-team-master"
Get-ChildItem $unzipPath -Force | Move-Item -dest $InstallPath
Remove-Item $unzipPath
2019-02-06 11:52:40 -07:00
if (-not (Get-InstalledModule -Name "powershell-yaml" -ErrorAction:SilentlyContinue)) {
write-verbose "Installing powershell-yaml"
Install-Module -Name powershell-yaml -Scope CurrentUser -Force
2019-11-11 15:26:23 -06:00
}
2019-02-06 11:52:40 -07:00
2019-09-12 15:02:29 -06:00
write-verbose "Importing invoke-atomicRedTeam module"
2019-11-11 15:26:23 -06:00
Import-Module $modulePath -Force
2019-02-06 11:52:40 -07:00
2019-11-11 15:26:23 -06:00
Write-Host "Installation of Invoke-AtomicRedTeam is complete. You can now use the Invoke-AtomicTest function" -Fore Yellow
Write-Host "See README at https://github.com/redcanaryco/atomic-red-team/tree/master/execution-frameworks/Invoke-AtomicRedTeam for complete details" -Fore Yellow
2019-02-06 11:52:40 -07:00
2019-09-12 15:02:29 -06:00
}
else {
2019-11-11 15:26:23 -06:00
Write-Host -ForegroundColor Yellow "Atomic Redteam already exists at $InstallPath. No changes were made."
Write-Host -ForegroundColor Cyan "Try the install again with the '-Force' parameter if you want to delete the existing installion and re-install."
Write-Host -ForegroundColor Red "Warning: All files within the install directory ($InstallPath) will be deleted when using the '-Force' parameter."
2019-09-12 15:02:29 -06:00
}
2019-11-11 15:26:23 -06:00
}