Merge branch 'master' into ja3

This commit is contained in:
Chris Long
2019-05-11 01:44:42 -07:00
committed by GitHub
3 changed files with 80 additions and 72 deletions

View File

@@ -1,10 +1,10 @@
if not exist "C:\Windows\Temp\7z1900-x64.msi" ( if not exist "C:\Windows\Temp\7z1900-x64.msi" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL
) )
msiexec /qb /i C:\Windows\Temp\7z1900-x64.msi msiexec /qb /i C:\Windows\Temp\7z1900-x64.msi
if not exist "C:\Windows\Temp\ultradefrag.zip" ( if not exist "C:\Windows\Temp\ultradefrag.zip" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://downloads.sourceforge.net/project/ultradefrag/stable-release/6.1.0/ultradefrag-portable-6.1.0.bin.amd64.zip', 'C:\Windows\Temp\ultradefrag.zip')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://downloads.sourceforge.net/project/ultradefrag/stable-release/6.1.0/ultradefrag-portable-6.1.0.bin.amd64.zip', 'C:\Windows\Temp\ultradefrag.zip')" <NUL
) )
if not exist "C:\Windows\Temp\ultradefrag-portable-6.1.0.amd64\udefrag.exe" ( if not exist "C:\Windows\Temp\ultradefrag-portable-6.1.0.amd64\udefrag.exe" (
@@ -12,8 +12,8 @@ if not exist "C:\Windows\Temp\ultradefrag-portable-6.1.0.amd64\udefrag.exe" (
) )
if not exist "C:\Windows\Temp\SDelete.zip" ( if not exist "C:\Windows\Temp\SDelete.zip" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://download.sysinternals.com/files/SDelete.zip', 'C:\Windows\Temp\SDelete.zip')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://download.sysinternals.com/files/SDelete.zip', 'C:\Windows\Temp\SDelete.zip')" <NUL
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://vagrantboxes.blob.core.windows.net/box/sdelete/v1.6.1/sdelete.exe', 'C:\Windows\Temp\sdelete.exe')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://vagrantboxes.blob.core.windows.net/box/sdelete/v1.6.1/sdelete.exe', 'C:\Windows\Temp\sdelete.exe')" <NUL
) )
if not exist "C:\Windows\Temp\sdelete.exe" ( if not exist "C:\Windows\Temp\sdelete.exe" (

View File

@@ -1,8 +1,8 @@
if not exist "C:\Windows\Temp\7z1900-x64.msi" ( if not exist "C:\Windows\Temp\7z1900-x64.msi" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL
) )
if not exist "C:\Windows\Temp\7z1900-x64.msi" ( if not exist "C:\Windows\Temp\7z1900-x64.msi" (
powershell -Command "Start-Sleep 5 ; (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL powershell -Command "Start-Sleep 5; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900-x64.msi', 'C:\Windows\Temp\7z1900-x64.msi')" <NUL
) )
msiexec /qb /i C:\Windows\Temp\7z1900-x64.msi msiexec /qb /i C:\Windows\Temp\7z1900-x64.msi
@@ -17,7 +17,7 @@ if exist "C:\Users\vagrant\windows.iso" (
) )
if not exist "C:\Windows\Temp\windows.iso" ( if not exist "C:\Windows\Temp\windows.iso" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://softwareupdate.vmware.com/cds/vmw-desktop/ws/15.0.4/12990004/windows/packages/tools-windows.tar', 'C:\Windows\Temp\vmware-tools.tar')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://softwareupdate.vmware.com/cds/vmw-desktop/ws/15.0.4/12990004/windows/packages/tools-windows.tar', 'C:\Windows\Temp\vmware-tools.tar')" <NUL
cmd /c ""C:\Program Files\7-Zip\7z.exe" x C:\Windows\Temp\vmware-tools.tar -oC:\Windows\Temp" cmd /c ""C:\Program Files\7-Zip\7z.exe" x C:\Windows\Temp\vmware-tools.tar -oC:\Windows\Temp"
FOR /r "C:\Windows\Temp" %%a in (VMware-tools-windows-*.iso) DO REN "%%~a" "windows.iso" FOR /r "C:\Windows\Temp" %%a in (VMware-tools-windows-*.iso) DO REN "%%~a" "windows.iso"
rd /S /Q "C:\Program Files (x86)\VMWare" rd /S /Q "C:\Program Files (x86)\VMWare"
@@ -38,7 +38,7 @@ if exist "C:\Users\vagrant\VBoxGuestAdditions.iso" (
) )
if not exist "C:\Windows\Temp\VBoxGuestAdditions.iso" ( if not exist "C:\Windows\Temp\VBoxGuestAdditions.iso" (
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://download.virtualbox.org/virtualbox/5.2.26/VBoxGuestAdditions_5.2.26.iso', 'C:\Windows\Temp\VBoxGuestAdditions.iso')" <NUL powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://download.virtualbox.org/virtualbox/5.2.26/VBoxGuestAdditions_5.2.26.iso', 'C:\Windows\Temp\VBoxGuestAdditions.iso')" <NUL
) )
cmd /c ""C:\Program Files\7-Zip\7z.exe" x C:\Windows\Temp\VBoxGuestAdditions.iso -oC:\Windows\Temp\virtualbox" cmd /c ""C:\Program Files\7-Zip\7z.exe" x C:\Windows\Temp\VBoxGuestAdditions.iso -oC:\Windows\Temp\virtualbox"

136
build.ps1
View File

@@ -25,6 +25,9 @@
.PARAMETER PackerPath .PARAMETER PackerPath
The full path to the packer executable. Default is C:\Hashicorp\packer.exe The full path to the packer executable. Default is C:\Hashicorp\packer.exe
.PARAMETER PackerOnly
This switch skips deploying boxes with vagrant after being built by packer
.PARAMETER VagrantOnly .PARAMETER VagrantOnly
This switch skips building packer boxes and instead downloads from Vagrant Cloud This switch skips building packer boxes and instead downloads from Vagrant Cloud
@@ -48,6 +51,7 @@ Param(
[ValidateSet('virtualbox', 'vmware_desktop')] [ValidateSet('virtualbox', 'vmware_desktop')]
[string]$ProviderName, [string]$ProviderName,
[string]$PackerPath = 'C:\Hashicorp\packer.exe', [string]$PackerPath = 'C:\Hashicorp\packer.exe',
[switch]$PackerOnly,
[switch]$VagrantOnly [switch]$VagrantOnly
) )
@@ -186,52 +190,54 @@ function preflight_checks {
break break
} }
} }
Write-Host '[preflight_checks] Checking if Vagrant is installed' if (!($PackerOnly)) {
check_vagrant Write-Host '[preflight_checks] Checking if Vagrant is installed'
check_vagrant
Write-Host '[preflight_checks] Checking for pre-existing boxes..' Write-Host '[preflight_checks] Checking for pre-existing boxes..'
if ((Get-ChildItem "$DL_DIR\Boxes\*.box").Count -gt 0) { if ((Get-ChildItem "$DL_DIR\Boxes\*.box").Count -gt 0) {
Write-Host 'You seem to have at least one .box file present in the Boxes directory already. If you would like fresh boxes downloaded, please remove all files from the Boxes directory and re-run this script.' Write-Host 'You seem to have at least one .box file present in the Boxes directory already. If you would like fresh boxes downloaded, please remove all files from the Boxes directory and re-run this script.'
}
# Check to see that no vagrant instances exist
Write-Host '[preflight_checks] Checking for vagrant instances..'
$CurrentDir = Get-Location
Set-Location "$DL_DIR\Vagrant"
if (($(vagrant status) | Select-String -Pattern "not[ _]created").Count -ne 4) {
Write-Error 'You appear to have already created at least one Vagrant instance. This script does not support already created instances. Please either destroy the existing instances or follow the build steps in the README to continue.'
break
}
Set-Location $CurrentDir
# Check available disk space. Recommend 80GB free, warn if less
Write-Host '[preflight_checks] Checking disk space..'
$drives = Get-PSDrive | Where-Object {$_.Provider -like '*FileSystem*'}
$drivesList = @()
forEach ($drive in $drives) {
if ($drive.free -lt 80GB) {
$DrivesList = $DrivesList + $drive
} }
}
if ($DrivesList.Count -gt 0) { # Check to see that no vagrant instances exist
Write-Output "The following drives have less than 80GB of free space. They should not be used for deploying DetectionLab" Write-Host '[preflight_checks] Checking for vagrant instances..'
forEach ($drive in $DrivesList) { $CurrentDir = Get-Location
Write-Output "[*] $($drive.Name)" Set-Location "$DL_DIR\Vagrant"
} if (($(vagrant status) | Select-String -Pattern "not[ _]created").Count -ne 4) {
Write-Output "You can safely ignore this warning if you are deploying DetectionLab to a different drive." Write-Error 'You appear to have already created at least one Vagrant instance. This script does not support already created instances. Please either destroy the existing instances or follow the build steps in the README to continue.'
}
# Ensure the vagrant-reload plugin is installed
Write-Host '[preflight_checks] Checking if vagrant-reload is installed..'
if (-Not (vagrant plugin list | Select-String 'vagrant-reload')) {
Write-Output 'The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.'
(vagrant plugin install 'vagrant-reload')
if ($LASTEXITCODE -ne 0) {
Write-Error 'Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.'
break break
} }
Set-Location $CurrentDir
# Check available disk space. Recommend 80GB free, warn if less
Write-Host '[preflight_checks] Checking disk space..'
$drives = Get-PSDrive | Where-Object {$_.Provider -like '*FileSystem*'}
$drivesList = @()
forEach ($drive in $drives) {
if ($drive.free -lt 80GB) {
$DrivesList = $DrivesList + $drive
}
}
if ($DrivesList.Count -gt 0) {
Write-Output "The following drives have less than 80GB of free space. They should not be used for deploying DetectionLab"
forEach ($drive in $DrivesList) {
Write-Output "[*] $($drive.Name)"
}
Write-Output "You can safely ignore this warning if you are deploying DetectionLab to a different drive."
}
# Ensure the vagrant-reload plugin is installed
Write-Host '[preflight_checks] Checking if vagrant-reload is installed..'
if (-Not (vagrant plugin list | Select-String 'vagrant-reload')) {
Write-Output 'The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.'
(vagrant plugin install 'vagrant-reload')
if ($LASTEXITCODE -ne 0) {
Write-Error 'Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.'
break
}
}
} }
Write-Host '[preflight_checks] Finished.' Write-Host '[preflight_checks] Finished.'
} }
@@ -262,11 +268,11 @@ function move_boxes {
Write-Host "[move_boxes] Running.." Write-Host "[move_boxes] Running.."
Move-Item -Path $DL_DIR\Packer\*.box -Destination $DL_DIR\Boxes Move-Item -Path $DL_DIR\Packer\*.box -Destination $DL_DIR\Boxes
if (-Not (Test-Path "$DL_DIR\Boxes\windows_10_$PackerProvider.box")) { if (-Not (Test-Path "$DL_DIR\Boxes\windows_10_$PackerProvider.box")) {
Write-Error "Windows 10 box is missing from the Boxes directory. Qutting." Write-Error "Windows 10 box is missing from the Boxes directory. Quitting."
break break
} }
if (-Not (Test-Path "$DL_DIR\Boxes\windows_2016_$PackerProvider.box")) { if (-Not (Test-Path "$DL_DIR\Boxes\windows_2016_$PackerProvider.box")) {
Write-Error "Windows 2016 box is missing from the Boxes directory. Qutting." Write-Error "Windows 2016 box is missing from the Boxes directory. Quitting."
break break
} }
Write-Host "[move_boxes] Finished." Write-Host "[move_boxes] Finished."
@@ -387,27 +393,29 @@ if (!($VagrantOnly)) {
move_boxes move_boxes
} }
# Vagrant up each box and attempt to reload one time if it fails if (!($PackerOnly)) {
forEach ($VAGRANT_HOST in $LAB_HOSTS) { # Vagrant up each box and attempt to reload one time if it fails
Write-Host "[main] Running vagrant_up_host for: $VAGRANT_HOST" forEach ($VAGRANT_HOST in $LAB_HOSTS) {
$result = vagrant_up_host -VagrantHost $VAGRANT_HOST Write-Host "[main] Running vagrant_up_host for: $VAGRANT_HOST"
Write-Host "[main] vagrant_up_host finished. Exitcode: $result" $result = vagrant_up_host -VagrantHost $VAGRANT_HOST
if ($result -eq '0') { Write-Host "[main] vagrant_up_host finished. Exitcode: $result"
Write-Output "Good news! $VAGRANT_HOST was built successfully!" if ($result -eq '0') {
} Write-Output "Good news! $VAGRANT_HOST was built successfully!"
else {
Write-Warning "Something went wrong while attempting to build the $VAGRANT_HOST box."
Write-Output "Attempting to reload and reprovision the host..."
Write-Host "[main] Running vagrant_reload_host for: $VAGRANT_HOST"
$retryResult = vagrant_reload_host -VagrantHost $VAGRANT_HOST
if ($retryResult -ne 0) {
Write-Error "Failed to bring up $VAGRANT_HOST after a reload. Exiting"
break
} }
else {
Write-Warning "Something went wrong while attempting to build the $VAGRANT_HOST box."
Write-Output "Attempting to reload and reprovision the host..."
Write-Host "[main] Running vagrant_reload_host for: $VAGRANT_HOST"
$retryResult = vagrant_reload_host -VagrantHost $VAGRANT_HOST
if ($retryResult -ne 0) {
Write-Error "Failed to bring up $VAGRANT_HOST after a reload. Exiting"
break
}
}
Write-Host "[main] Finished for: $VAGRANT_HOST"
} }
Write-Host "[main] Finished for: $VAGRANT_HOST"
}
Write-Host "[main] Running post_build_checks" Write-Host "[main] Running post_build_checks"
post_build_checks post_build_checks
Write-Host "[main] Finished post_build_checks" Write-Host "[main] Finished post_build_checks"
}