Skip to content

Commit a4b00c6

Browse files
committed
Added LastBootUpTime to returned PSCustomObject per suggestion by Brett Miller (@BrettMiller_IT).
1 parent 71f6ccf commit a4b00c6

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Functions/Test-WannaCryVulnerability.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#PSScriptInfo
22
33
.Version
4-
2.1
4+
2.2
55
.Guid
66
477aa3f4-0434-4925-9c92-7323066cceb7
77
.Author
@@ -12,7 +12,7 @@
1212
https://github.com/dotps1/PSFunctions
1313
.ReleaseNotes
1414
Replaced Write-Warning with Write-Error so it can be caught in a try catch block.
15-
15+
1616
#>
1717

1818
<#
@@ -41,6 +41,7 @@
4141
PSComputerName : myrig
4242
OperatingSystemCaption : Microsoft Windows 7 Professional
4343
OperatingSystemVersion : 6.1.7601
44+
LastBootUpTime : 5/14/2017 3:38:38 PM
4445
Vulnerable : False
4546
AppliedHotFixID : KB4012212|KB4015546|KB4015549
4647
SMB1FeatureEnabled : False
@@ -51,14 +52,15 @@
5152
PSComputerName : workstation
5253
OperatingSystemCaption : Microsoft Windows 7 Professional
5354
OperatingSystemVersion : 6.1.7601
55+
LastBootUpTime : 5/14/2017 3:38:38 PM
5456
Vulnerable : True
5557
AppliedHotFixID :
5658
SMB1FeatureEnabled : False
5759
SMB1ProtocolEnabled : True
5860
.Notes
59-
Not applicable to windows 10.
61+
WannaCry vulnerability is only applicable to Microsoft Windows 10 1607 and prior, 1702 was not affected.
6062
.Link
61-
https://www.redsocks.eu/news/ransomware-wannacry/
63+
https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
6264
.Link
6365
https://support.microsoft.com/en-us/help/2696547/how-to-enable-and-disable-smbv1,-smbv2,-and-smbv3-in-windows-vista,-windows-server-2008,-windows-7,-windows-server-2008-r2,-windows-8,-and-windows-server-2012
6466
.Link
@@ -147,7 +149,7 @@ process {
147149
foreach ($nameValue in $Name) {
148150
try {
149151
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
152+
$osInformation = Get-WmiObject -ComputerName $nameValue -Class Win32_OperatingSystem -Property Caption, LastBootUpTime, Version -Credential $Credential -ErrorAction Stop
151153
} catch {
152154
Write-Error -Message "Failed to query WMI on '$nameValue'." -RecommendedAction "Verify WMI access is not being blocked by the firewall."
153155
continue
@@ -159,7 +161,7 @@ process {
159161
}
160162

161163
# HotFixes
162-
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Inventory hotfix information" -PercentComplete 40
164+
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Retrieve hotfix information" -PercentComplete 40
163165
$appliedHotFixID = (Get-WmiObject -ComputerName $nameValue -Class Win32_QuickFixEngineering -Credential $Credential).Where({
164166
$_.HotFixID -in $hotFixIDs
165167
}).HotFixID
@@ -193,11 +195,15 @@ process {
193195
} else {
194196
$vulnerable = $true
195197
}
198+
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -Completed
196199

197200
$output = [PSCustomObject]@{
198201
PSComputerName = $nameValue
199202
OperatingSystemCaption = $osInformation.Caption
200203
OperatingSystemVersion = $osInformation.Version
204+
LastBootUpTime = $osInformation.ConvertToDateTime(
205+
$osInformation.LastBootUpTime
206+
)
201207
Vulnerable = $vulnerable
202208
AppliedHotFixID = $appliedHotFixId -join "|"
203209
SMB1FeatureEnabled = $smb1FeatureEnabled
@@ -211,15 +217,15 @@ process {
211217
"ByCimSession" {
212218
foreach ($cimSessionValue in $CimSession) {
213219
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Retrieve operating system caption" -PercentComplete 20
214-
$osInformation = Get-CimInstance -CimSession $cimSessionValue -ClassName Win32_OperatingSystem -Property Caption, Version
220+
$osInformation = Get-CimInstance -CimSession $cimSessionValue -ClassName Win32_OperatingSystem -Property Caption, LastBootUpTime, Version
215221

216222
if ([Version]$osInformation.Version -ge [Version]"10.0.15063") {
217223
Write-Error -Message "$($osInformation.Caption) $($osInformation.Version) is not vulnerable to the WannaCry Exploit."
218224
continue
219225
}
220226

221227
# HotFixes
222-
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Inventory hotfix information" -PercentComplete 40
228+
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Retrieve hotfix information" -PercentComplete 40
223229
$appliedHotFixID = (Get-CimInstance -CimSession $CimSession -ClassName Win32_QuickFixEngineering).Where({
224230
$_.HotFixID -in $hotFixIDs
225231
}).HotFixID
@@ -252,11 +258,15 @@ process {
252258
if ($appliedHotFixId.Count -gt 0 -and -not $smb1FeatureEnabled -and -not $smb1ProtocolEnabled) {
253259
$vulnerable = $false
254260
}
261+
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -Completed
255262

256263
$output = [PSCustomObject]@{
257264
PSComputerName = $cimSessionValue.ComputerName
258265
OperatingSystemCaption = $osInformation.Caption
259266
OperatingSystemVersion = $osInformation.Version
267+
LastBootUpTime = $osInformation.ConvertToDateTime(
268+
$osInformation.LastBootUpTime
269+
)
260270
Vulnerable = $vulnerable
261271
AppliedHotFixID = $appliedHotFixId -join "|"
262272
SMB1FeatureEnabled = $smb1FeatureEnabled

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ PS C:\> Test-WannaCryVulnerability
249249
PSComputerName : myrig
250250
OperatingSystemCaption : Microsoft Windows 7 Professional
251251
OperatingSystemVersion : 6.1.7601
252+
LastBootUpTime : 5/14/2017 3:38:38 PM
252253
Vulnerable : False
253254
AppliedHotFixID : KB4012212|KB4015546|KB4015549
254255
SMB1FeatureEnabled : False
@@ -260,6 +261,7 @@ PS C:\> Get-ADComputer -Identity workstation | Test-WannaCryVulnerability
260261
PSComputerName : workstation
261262
OperatingSystemCaption : Microsoft Windows 7 Professional
262263
OperatingSystemVersion : 6.1.7601
264+
LastBootUpTime : 5/14/2017 3:38:38 PM
263265
Vulnerable : True
264266
AppliedHotFixID :
265267
SMB1FeatureEnabled : False

0 commit comments

Comments
 (0)