Skip to content

Commit 3137a46

Browse files
committed
fix: 🐛 Guard VBS registry edits
Wrap both the HypervisorEnforcedCodeIntegrity writes and the optional memory-integrity enablement in Test-Path checks so the script skips gracefully on systems where those registry branches were never provisioned
1 parent 35e27b7 commit 3137a46

File tree

1 file changed

+36
-27
lines changed
  • src/playbook/Executables/AtlasModules/Scripts/ScriptWrappers

1 file changed

+36
-27
lines changed

src/playbook/Executables/AtlasModules/Scripts/ScriptWrappers/ConfigVBS.ps1

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ if ($DisableAllVBS) {
1414
Write-Warning "Disabling VBS features..."
1515

1616
# Memory Integrity
17-
New-ItemProperty -Path $memIntegrity -Name "Enabled" -Value 0 -PropertyType DWORD -Force # Need to be forced since Windows 11 24H2
17+
if (Test-Path $memIntegrity) {
18+
# Need to be forced since Windows 11 24H2
19+
New-ItemProperty -Path $memIntegrity -Name "Enabled" -Value 0 -PropertyType DWORD -Force
20+
} else {
21+
Write-Verbose "Memory Integrity registry path not found."
22+
}
1823

1924
# Kernel-mode Hardware-enforced Stack Protection (Windows 11 only)
2025
if (Test-Path $kernelShadowStacks) {
@@ -38,8 +43,12 @@ if ($DisableAllVBS) {
3843
exit
3944
} elseif ($EnableMemoryIntegrity) {
4045
Write-Warning "Enabling memory integrity..."
41-
Set-ItemProperty -Path $memIntegrity -Name "Enabled" -Value 1 -Type DWord
42-
Set-ItemProperty -Path $memIntegrity -Name "WasEnabledBy" -Value 2 -Type DWord
46+
if (Test-Path $memIntegrity) {
47+
Set-ItemProperty -Path $memIntegrity -Name "Enabled" -Value 1 -Type DWord
48+
Set-ItemProperty -Path $memIntegrity -Name "WasEnabledBy" -Value 2 -Type DWord
49+
} else {
50+
Write-Warning "Memory Integrity registry path not found."
51+
}
4352
exit
4453
}
4554

@@ -49,13 +58,13 @@ $pages = @(
4958
Commands = {
5059
$SecurityServicesRunning = (Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard).SecurityServicesRunning
5160
$VirtualizationBasedSecurityStatus = (Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard).VirtualizationBasedSecurityStatus
52-
61+
5362
$VirtualizationBasedSecurityStatusList = @(
5463
"VBS isn't enabled",
5564
"VBS is enabled but not running",
5665
"VBS is enabled and running"
5766
)
58-
67+
5968
$VirtualizationBasedSecurityRunningFeatures = @(
6069
"None",
6170
"Windows Defender Credential Guard",
@@ -70,7 +79,7 @@ $pages = @(
7079
Write-Host "$feature`n"
7180
}
7281
}
73-
82+
7483
Write-Host "Notes: " -ForegroundColor Yellow -NoNewLine
7584
Write-Host "Some features here are exclusive to Windows 11, you will be mostly looking at Memory Integrity on Windows 10."
7685
Write-Host " Please note that on older CPUs especially, features like Memory Integrity will reduce performance significantly.`n"
@@ -81,18 +90,18 @@ $pages = @(
8190
} else {
8291
Write-Host "`nVirtualization Based Security features currently running:`n" -ForegroundColor Yellow
8392
}
84-
93+
8594
foreach ($feature in $VirtualizationBasedSecurityRunningFeatures) {
8695
if ($feature -eq "None") {
8796
continue
8897
}
89-
98+
9099
Write-Host " - " -NoNewLine
91-
100+
92101
if ($SecurityServicesRunning -contains $VirtualizationBasedSecurityRunningFeatures.IndexOf($feature)) {
93102
Write-Host "$feature is running" -ForegroundColor Green
94103
} else {
95-
# $($VirtualizationBasedSecurityRunningFeatures.IndexOf($feature)).
104+
# $($VirtualizationBasedSecurityRunningFeatures.IndexOf($feature)).
96105
Write-Host "$feature is not running" -ForegroundColor Red
97106
}
98107
}
@@ -110,27 +119,27 @@ $pages = @(
110119
"System Guard Secure Launch",
111120
"SMM Firmware Measurement"
112121
)
113-
122+
114123
Write-Host "Note: " -ForegroundColor Yellow -NoNewLine
115124
Write-Host "These are the features configured on startup."
116-
125+
117126
if ($SecurityServicesConfigured -contains '0') {
118127
Write-Host "`nNo Virtualization Based Security features are configured.`n" -ForegroundColor Green
119128
} else {
120129
Write-Host "`nVirtualization Based Security features configured:`n" -ForegroundColor Yellow
121130
}
122-
131+
123132
foreach ($feature in $VirtualizationBasedSecurityConfiguredFeatures) {
124133
if ($feature -eq "None") {
125134
continue
126135
}
127-
136+
128137
Write-Host " - " -NoNewLine
129-
138+
130139
if ($SecurityServicesConfigured -contains $VirtualizationBasedSecurityConfiguredFeatures.IndexOf($feature)) {
131140
Write-Host "$feature is configured" -ForegroundColor Green
132141
} else {
133-
# $($VirtualizationBasedSecurityConfiguredFeatures.IndexOf($feature)).
142+
# $($VirtualizationBasedSecurityConfiguredFeatures.IndexOf($feature)).
134143
Write-Host "$feature is not configured" -ForegroundColor Red
135144
}
136145
}
@@ -157,18 +166,18 @@ $pages = @(
157166
} else {
158167
Write-Host "Security features needed for Virtualization Based Security:`n" -ForegroundColor Yellow
159168
}
160-
169+
161170
foreach ($feature in $VirtualizationBasedSecurityRequiredSecurity) {
162171
if ($feature -eq "None") {
163172
continue
164173
}
165-
174+
166175
Write-Host " - " -NoNewLine
167-
176+
168177
if ($RequiredSecurityProperties -contains $VirtualizationBasedSecurityRequiredSecurity.IndexOf($feature)) {
169178
Write-Host "$feature is required" -ForegroundColor Green
170179
} else {
171-
# $($VirtualizationBasedSecurityRequiredSecurity.IndexOf($feature)).
180+
# $($VirtualizationBasedSecurityRequiredSecurity.IndexOf($feature)).
172181
Write-Host "$feature is not required" -ForegroundColor Red
173182
}
174183
}
@@ -196,18 +205,18 @@ $pages = @(
196205
} else {
197206
Write-Host "Security features available for Virtualization Based Security:`n" -ForegroundColor Yellow
198207
}
199-
208+
200209
foreach ($feature in $VirtualizationBasedSecurityAvailableSecurity) {
201210
if ($feature -eq "None") {
202211
continue
203212
}
204-
213+
205214
Write-Host " - " -NoNewLine
206-
215+
207216
if ($AvailableSecurityProperties -contains $VirtualizationBasedSecurityAvailableSecurity.IndexOf($feature)) {
208217
Write-Host "$feature is available" -ForegroundColor Green
209218
} else {
210-
# $($VirtualizationBasedSecurityAvailableSecurity.IndexOf($feature)).
219+
# $($VirtualizationBasedSecurityAvailableSecurity.IndexOf($feature)).
211220
Write-Host "$feature is not available" -ForegroundColor Red
212221
}
213222
}
@@ -238,17 +247,17 @@ function Wait-Key {
238247
Wait-Key
239248
}
240249
}
241-
250+
242251
Show-Page
243252
}
244253

245254
function Show-Page {
246255
Clear-Host
247256
$currentPage = $pages[$currentPageIndex]
248257
$Host.UI.RawUI.WindowTitle = "$($currentPage.Title)"
249-
258+
250259
& $currentPage.Commands
251-
260+
252261
# Write-Host "`nCurrent Page: $($currentPage.Title)" -ForegroundColor Yellow
253262
Write-Host "`n------------- Page $($currentPageIndex + 1) -------------" -ForegroundColor Yellow
254263
Write-Host "(n) Next Page || (b) Previous Page"

0 commit comments

Comments
 (0)