-
Notifications
You must be signed in to change notification settings - Fork 19
/
Resolve-WindowsSpeculativeExecutionConf.ps1
241 lines (190 loc) · 10.3 KB
/
Resolve-WindowsSpeculativeExecutionConf.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<#
.NAME
Resolve-WindowsSpeculativeExecutionConf
.SYNOPSIS
This cmdlet is used for mitigating the following vulnerabilities:
- Branch Target Injection (BTI) (CVE-2017-5715)
- Bounds Check Bypass (BCB) (CVE-2017-5753)
- Rogue Data Cache Load (RDCL) (CVE-2017-5754)
- Rogue System Register Read (RSRE) (CVE-2018-3640)
- Speculative Store Bypass (SSB) (CVE-2018-3639)
- L1 Terminal Fault (L1TF) (CVE-2018-3615, CVE-2018-3620, CVE-2018-3646)
- Microarchitectural Data Sampling Uncacheable Memory (MDSUM) (CVE-2019-11091)
- Microarchitectural Store Buffer Data Sampling (MSBDS) (CVE-2018-12126)
- Microarchitectural Load Port Data Sampling (MLPDS) (CVE-2018-12127)
- Microarchitectural Fill Buffer Data Sampling (MFBDS) (CVE-2018-12130)
- TSX Asynchronous Abort (TAA) (CVE-2019-11135)
.SYNTAX
Resolve-WindowsSpeculativeExecutionConf [<CommonParameters>]
.PARAMETERS
-Restart [<SwitchParameter>]
This switch parameter is used to restart the computer after the registry changes are made in order
to apply the changes as soon as possible.
-DisableHyperThreading [<SwitchParameter>]
This switch parameter is used to set the registry settings in a way that will disable hyper threading
as well as mitigate the CVE's the processor is vulnerable too.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
.EXAMPLE
.EXAMPLE 1
Resolve-WindowsSpeculativeExecutionConf
This example mitigates a variety of
.NOTES
Author: Rob Osborne
Alias: tobor
Contact: [email protected]
.INPUTS
None
.OUTPUTS
None
.LINK
https://support.microsoft.com/en-us/help/4073119/protect-against-speculative-execution-side-channel-vulnerabilities-in
https://support.microsoft.com/en-us/help/4072698/windows-server-speculative-execution-side-channel-vulnerabilities
https://github.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://osbornepro.com
https://www.credly.com/users/roberthosborne/badges
https://writeups.osbornepro.com
#>
Function Resolve-WindowsSpeculativeExecutionConf {
[CmdletBinding()]
param(
[Parameter(
Mandatory=$False)] # End Parameter
[Switch][bool]$Restart,
[Parameter(
Mandatory=$False)] # End Parameter
[Switch][bool]$DisableHyperThreading) # End param
$Processor = Get-CimInstance -ClassName 'Win32_Processor'
$HyperVState = (Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-All' -Online).State
$HyperThreading = ($Processor | Measure-Object -Property "NumberOfLogicalProcessors" -Sum).Sum -gt ($Processor | Measure-Object -Property "NumberOfCores" -Sum).Sum
$RegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
$HyperRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization"
$Override = "FeatureSettingsOverride"
$OverrideMask = "FeatureSettingsOverrideMask"
$MinVerCpu = "MinVmVersionForCpuBasedMitigations"
If (!(Test-Path -Path "$RegistryPath"))
{
Write-Verbose "[!] Registry location does not exist. Creating Registry Item $RegistryPath"
New-Item -Path "$RegistryPath"
} # End If
If ($Processor -like "*Intel*")
{
$OverrideValue = 72
$OverrideMakValue = 3
} # End If
ElseIf ($Processor -like "*AMD*")
{
$OverrideValue = 72
$OverrideMakValue = 3
} # End ElseIf
ElseIf ($Processor -like "*ARM*")
{
$OverrideValue = 64
$OverrideMakValue = 3
} # End ElseIf
If ($HyperThreading -eq 'False')
{
Write-Verbose "[*] Hyper Threading is disabled. "
$OverrideValue = 8264
} # End If
# CVE-2018-3639 CVE-2017-5715 CVE-2017-5754
Write-Verbose "[*] Enabling mitigations for CVE-2018-3639 (Speculative Store Bypass), CVE-2017-5715 (Spectre Variant 2), and CVE-2017-5754 (Meltdown)"
If ($OverrideValue -ne (Get-ItemProperty -Path "$RegistryPath").FeatureSettingsOverride)
{
Write-Verbose "[*] FeatureSettingsOverride value is being changed to 8 as suggested by Microsoft`n VALUE: $OverrideValue"
New-ItemProperty -Path "$RegistryPath" -Name $Override -Value $OverrideValue -PropertyType 'DWORD'
} # End If
If ($OverrideMakValue -ne (Get-ItemProperty -Path "$RegistryPath").FeatureSettingsOverrideMask)
{
Write-Verbose "[*] FeatureSettingsOverride value is being changed to 3 as suggested by Microsoft`nVALUE: $OverrideMakValue"
New-ItemProperty -Path "$RegistryPath" -Name $OverrideMask -Value $OverrideMakValue -PropertyType 'DWORD'
} # End If
If ($HyperVState -eq 'Enabled')
{
Write-Verbose "[*] Hyper-V is enabled on the device. Mitigating risk to this application`nVALUE: 1.0`n"
Write-Output 'If this is a Hyper-V host and the firmware updates have been applied: Fully shut down all Virtual Machines. This enables the firmware-related mitigation to be applied on the host before the VMs are started. The VMs are also updated when they are restarted'
New-ItemProperty -Path "$HyperRegPath" -Name $MinVerCpu -PropertyType "String" -Value "1.0"
} # End If
If ($Restart.IsPresent)
{
Write-Verbose "[*] -Restart switch was defined. Restarting Computer in 5 seconds..."
Start-Sleep -Seconds 5
Restart-Computer -Force
} # End If
} # End Function Resolve-WindowsSpeculativeExecutionConf
# SIG # Begin signature block
# MIIM9AYJKoZIhvcNAQcCoIIM5TCCDOECAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUSwpVZbl2U0TQoy5ulOC6/Acl
# cgegggn7MIIE0DCCA7igAwIBAgIBBzANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UE
# BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY
# BgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMTEwLwYDVQQDEyhHbyBEYWRkeSBSb290
# IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTExMDUwMzA3MDAwMFoXDTMx
# MDUwMzA3MDAwMFowgbQxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMw
# EQYDVQQHEwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjEt
# MCsGA1UECxMkaHR0cDovL2NlcnRzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkvMTMw
# MQYDVQQDEypHbyBEYWRkeSBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IC0g
# RzIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC54MsQ1K92vdSTYusw
# ZLiBCGzDBNliF44v/z5lz4/OYuY8UhzaFkVLVat4a2ODYpDOD2lsmcgaFItMzEUz
# 6ojcnqOvK/6AYZ15V8TPLvQ/MDxdR/yaFrzDN5ZBUY4RS1T4KL7QjL7wMDge87Am
# +GZHY23ecSZHjzhHU9FGHbTj3ADqRay9vHHZqm8A29vNMDp5T19MR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