Skip to content

Commit dca991b

Browse files
committed
Per Lee Holmes (@lee_holmes) there is still a needed patch for Windows 10 1602 and prior https://twitter.com/Lee_Holmes/status/864604299405410304. Added Operating System Version to returned object.
1 parent 59a6577 commit dca991b

File tree

2 files changed

+43
-52
lines changed

2 files changed

+43
-52
lines changed

Functions/Test-WannaCryVulnerability.ps1

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#PSScriptInfo
22
33
.Version
4-
1.4
4+
2.0
55
.Guid
66
477aa3f4-0434-4925-9c92-7323066cceb7
77
.Author
@@ -11,7 +11,7 @@
1111
.ProjectUri
1212
https://github.com/dotps1/PSFunctions
1313
.ReleaseNotes
14-
Moved ComputerName connectivity test to the parameter validation. Added Write-Progress output for the steps being completed.
14+
Per Lee Holmes (@lee_holmes) there is still a needed patch for Windows 10 1602 and prior. Added Operating System Version to returned object.
1515
1616
#>
1717

@@ -38,21 +38,23 @@
3838
.Example
3939
PS C:\> Test-WannaCryVulnerability
4040
41-
PSComputerName : myrig
42-
OperatingSystem : Microsoft Windows 7 Professional
43-
Vulnerable : False
44-
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
45-
SMB1FeatureEnabled : False
46-
SMB1ProtocolEnabled : False
41+
PSComputerName : myrig
42+
OperatingSystemCaption : Microsoft Windows 7 Professional
43+
OperatingSystemVersion : 6.1.7601
44+
Vulnerable : False
45+
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
46+
SMB1FeatureEnabled : False
47+
SMB1ProtocolEnabled : False
4748
.Example
4849
PS C:\> Get-ADComputer -Identity workstation | Test-WannaCryVulnerability
4950
50-
PSComputerName : workstation
51-
OperatingSystem : Microsoft Windows 7 Professional
52-
Vulnerable : True
53-
AppliedHotFixIds :
54-
SMB1FeatureEnabled : False
55-
SMB1ProtocolEnabled : True
51+
PSComputerName : workstation
52+
OperatingSystemCaption : Microsoft Windows 7 Professional
53+
OperatingSystemVersion : 6.1.7601
54+
Vulnerable : True
55+
AppliedHotFixIds :
56+
SMB1FeatureEnabled : False
57+
SMB1ProtocolEnabled : True
5658
.Notes
5759
Not applicable to windows 10.
5860
.Link
@@ -135,20 +137,7 @@ begin {
135137
"KB4015546",
136138
"KB4015547",
137139
"KB4015548",
138-
"KB4015549",
139-
"KB4015550",
140-
"KB4015551",
141-
"KB4015552",
142-
"KB4015553",
143-
"KB4015554",
144-
"KB4016635",
145-
"KB4019213",
146-
"KB4019214",
147-
"KB4019215",
148-
"KB4019216",
149-
"KB4019263",
150-
"KB4019264",
151-
"KB4019472"
140+
"KB4015549"
152141
)
153142
}
154143

@@ -157,16 +146,15 @@ process {
157146
"ByComputerName" {
158147
foreach ($nameValue in $Name) {
159148
try {
160-
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Retrieve operating system caption" -PercentComplete 20
161-
$osCaption = Get-WmiObject -ComputerName $nameValue -Class Win32_OperatingSystem -Property Caption -Credential $Credential -ErrorAction Stop |
162-
Select-Object -ExpandProperty Caption
149+
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Retrieve operating system information" -PercentComplete 20
150+
$osInformation = Get-WmiObject -ComputerName $nameValue -Class Win32_OperatingSystem -Property Caption, Version -Credential $Credential -ErrorAction Stop
163151
} catch {
164-
Write-Error -Message "Failed to contact WMI on '$nameValue'." -RecommendedAction "Verify WS-MAN is not being blocked by the firewall."
152+
Write-Error -Message "Failed to query WMI on '$nameValue'." -RecommendedAction "Verify WMI access is not being blocked by the firewall."
165153
continue
166154
}
167155

168-
if ($osCaption -match "Windows 10") {
169-
Write-Warning -Message "$osCaption is not vulnerable to WannaCry."
156+
if ([Version]$osInformation.Version -ge [Version]"10.0.15063") {
157+
Write-Warning -Message "$($osInformation.Caption) $($osInformation.Version) is not vulnerable to the WannaCry Exploit."
170158
continue
171159
}
172160

@@ -208,7 +196,8 @@ process {
208196

209197
$output = [PSCustomObject]@{
210198
PSComputerName = $nameValue
211-
OperatingSystem = $osCaption
199+
OperatingSystemCaption = $osInformation.Caption
200+
OperatingSystemVersion = $osInformation.Version
212201
Vulnerable = $vulnerable
213202
AppliedHotFixIds = $appliedHotFixIds -join "|"
214203
SMB1FeatureEnabled = $smb1FeatureEnabled
@@ -222,11 +211,10 @@ process {
222211
"ByCimSession" {
223212
foreach ($cimSessionValue in $CimSession) {
224213
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Retrieve operating system caption" -PercentComplete 20
225-
$osCaption = Get-CimInstance -CimSession $cimSessionValue -ClassName Win32_OperatingSystem -Property Caption |
226-
Select-Object -ExpandProperty Caption
214+
$osInformation = Get-CimInstance -CimSession $cimSessionValue -ClassName Win32_OperatingSystem -Property Caption, Version
227215

228-
if ($osCaption -match "Windows 10") {
229-
Write-Error -Message "$osCaption is not vulnerable to WannaCry."
216+
if ([Version]$osInformation.Version -ge [Version]"10.0.15063") {
217+
Write-Error -Message "$($osInformation.Caption) $($osInformation.Version) is not vulnerable to the WannaCry Exploit."
230218
continue
231219
}
232220

@@ -267,7 +255,8 @@ process {
267255

268256
$output = [PSCustomObject]@{
269257
PSComputerName = $cimSessionValue.ComputerName
270-
OperatingSystem = $osCaption
258+
OperatingSystemCaption = $osInformation.Caption
259+
OperatingSystemVersion = $osInformation.Version
271260
Vulnerable = $vulnerable
272261
AppliedHotFixIds = $appliedHotFixIds -join "|"
273262
SMB1FeatureEnabled = $smb1FeatureEnabled

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,22 @@ Test for applicable patches to prevent the WannaCry malware. Tests for SMB1 pro
246246
```
247247
PS C:\> Test-WannaCryVulnerability
248248
249-
PSComputerName : myrig
250-
OperatingSystem : Microsoft Windows 7 Professional
251-
Vulnerable : False
252-
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
253-
SMB1FeatureEnabled : False
254-
SMB1ProtocolEnabled : False
249+
PSComputerName : myrig
250+
OperatingSystemCaption : Microsoft Windows 7 Professional
251+
OperatingSystemVersion : 6.1.7601
252+
Vulnerable : False
253+
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
254+
SMB1FeatureEnabled : False
255+
SMB1ProtocolEnabled : False
255256
256257
257258
PS C:\> Get-ADComputer -Identity workstation | Test-WannaCryVulnerability
258259
259-
PSComputerName : workstation
260-
OperatingSystem : Microsoft Windows 7 Professional
261-
Vulnerable : True
262-
AppliedHotFixIds :
263-
SMB1FeatureEnabled : False
264-
SMB1ProtocolEnabled : True
260+
PSComputerName : workstation
261+
OperatingSystemCaption : Microsoft Windows 7 Professional
262+
OperatingSystemVersion : 6.1.7601
263+
Vulnerable : True
264+
AppliedHotFixIds :
265+
SMB1FeatureEnabled : False
266+
SMB1ProtocolEnabled : True
265267
```

0 commit comments

Comments
 (0)