Skip to content

Commit

Permalink
Add update-labs script for 504.24.1 to replace update-wiki.ps1 to use…
Browse files Browse the repository at this point in the history
… TCP/22 for updates
  • Loading branch information
joswr1ght committed May 27, 2024
1 parent dd1ac8b commit 964105b
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
130 changes: 130 additions & 0 deletions update-labs/sec504/dist/update-wiki.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## This script allows the user to update the lab wiki files.
## Based on JLW's update wiki script used on Slingshot VM
## Mick Douglas, @BetterSafetyNet -- 20190327
## Continued maintenance - Joshua Wright -- 20210804

$Branch = "MajorUpdate2023.1"

function Check-NetConnection {
$ProgressPreference = 'SilentlyContinue'
$OnlineCheckResult = Test-NetConnection 8.8.8.8
if ($OnlineCheckResult.PingSucceeded -eq $FALSE) {

# Try again using 4.4.4.4
$OnlineCheckResult = Test-NetConnection 4.4.4.4
if ($OnlineCheckResult.PingSucceeded -eq $FALSE) {

# One last test using www.sans.org on TCP/443
$OnlineCheckResult = Test-NetConnection -Port 443 -ComputerName "www.sans.org"
if ($OnlineCheckResult.PingSucceeded -eq $FALSE) {
# This failed, so try and revert network connection settings back to static
netsh int ip set address "Ethernet" static 10.10.0.1 255.255.0.0 0.0.0.0 1
# Disable turning off firewall; blocked from starting using Process Hacker 2
# https://twitter.com/jonasLyk/status/1368361467796463619?t=qF8bjxn0QrrqHFHJO2yqbg&s=19
#Get-NetFirewallProfile | Set-NetFirewallProfile -enabled False
netsh interface ipv4 show config "Ethernet"

Write-Error "It looks like your system isn't connected to the Internet. Please see the lab"
Write-Error "manual for steps to connect this virtual machine to the network."
Write-Error "If you continue to have trouble, please contact an instructor or email "
Write-Error "[email protected]. Thank you!"
exit
}
}
}
}

function Check-AdminStatus {
$IsRunningAsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ( -not $IsRunningAsAdmin) {
Write-Host -ForegroundColor red "Please run this script as Administrator. Exit your PowerShell prompt and run again with Administrator privileges."
exit 1
}
}

function Check-PowerShellISE {

if ( $host.name -match "ISE") {
Write-Host -ForegroundColor red "PowerShell ISE is not supported for this script."
exit 1
}
}

function Run-Update {
$TargetDir = "C:\wiki"
$GitURL="ssh://[email protected]/joswr1ght/SANS-504-Student-Wiki"
if(!(Test-Path -Path $TargetDir)){
New-Item -ItemType directory -Path $TargetDir
if (!($?)) {
Write-Error "Unable to create $TargetDir"
exit
}
git clone --depth 1 -b $Branch $GitURL $TargetDir
if (!($?)) {
Write-Error "Unable to clone into $TargetDir"
exit
}
git checkout $Branch
}

Set-Location $TargetDir
if (!($?)) {
Write-Error "Unable to cd into $TargetDir. Remove the directory and try again."
exit
}

git reset HEAD --hard
if (!($?)) {
Write-Error "Cannot perform reset on $TargetDir"
exit
}

git pull
if (!($?)) {
Write-Error "Unable to update $TargetDir"
exit
}
git checkout $Branch
if (!($?)) {
Write-Error "Unable to checkout $Branch branch"
exit
}

}



# Check admin status
Check-AdminStatus

# Check for PowerShell ISE
Check-PowerShellISE

# Change to DHCP, obtain IP
Write-Host "Resetting IP Address and Subnet Mask For DHCP"
netsh int ip set address name = "Ethernet" source = dhcp | Out-Null

Write-Host "Resetting DNS For DHCP"
netsh int ip set dns name = "Ethernet" source = dhcp | Out-Null

Write-Host "Resetting Windows Internet Name Service (WINS) For DHCP"
netsh int ip set wins name = "Ethernet" source = dhcp | Out-Null
#Get-NetFirewallProfile | Set-NetFirewallProfile -enabled False

Start-Sleep 3

# Check network status
Check-NetConnection

Write-Host "Running update.`n"

$OrigDir = $PSScriptRoot
Run-Update
Set-Location $OrigDir

# Restore static IP
Write-Host "`nRestoring static IP for lab use."
netsh int ip set address "Ethernet" static 10.10.0.1 255.255.0.0 0.0.0.0 1 | Out-Null
#Get-NetFirewallProfile | Set-NetFirewallProfile -enabled False

Write-Host "`nDone."
3 changes: 3 additions & 0 deletions update-labs/sec504/update-labs-504.24.1.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Update the Windows 10 VM as needed to address lab problems.

# Replace update-wiki.ps1 with an edit to SSH over port 22 instead of 443.
iwr https://joswr1ght.github.io/update-labs/sec504/dist/update-wiki.ps1 -OutFile C:\Tools\update-wiki.ps1
Write-Host "Update complete!"

0 comments on commit 964105b

Please sign in to comment.