-
Notifications
You must be signed in to change notification settings - Fork 5
/
CVE-2021-36934.ps1
111 lines (98 loc) · 3.04 KB
/
CVE-2021-36934.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
#Requires -RunAsAdministrator
#check if vulnerable
$vulnerable = $false
$LocalUsersGroup = Get-LocalGroup -SID 'S-1-5-32-545'
if ($vulnerable -eq $false) {
$checkPermissions = Get-Acl $env:windir\System32\Config\sam
if ($LocalUsersGroup) {
if ($CheckPermissions.Access.IdentityReference -match $LocalUsersGroup.Name) {
$vulnerable = $true
}
}
}
if ($vulnerable -eq $false) {
$checkPermissions = Get-Acl $env:windir\System32\Config\SYSTEM
if ($LocalUsersGroup) {
if ($CheckPermissions.Access.IdentityReference -match $LocalUsersGroup.Name) {
$vulnerable = $true
}
}
}
if ($vulnerable -eq $false) {
$checkPermissions = Get-Acl $env:windir\System32\Config\SECURITY
if ($LocalUsersGroup) {
if ($CheckPermissions.Access.IdentityReference -match $LocalUsersGroup.Name) {
$vulnerable = $true
}
}
}
#get exsisting shadowcopies
if ($vulnerable) {
function Get-ShadowVolumes {
# Returns a list of volumeIDs and associated drive letters for drives containing shadow copies.
$CurrentVolumes=Get-WmiObject Win32_ShadowStorage -Property Volume
$AllVolumes=Get-WmiObject win32_volume
$ShadowVolumes=[System.Collections.ArrayList]@()
$pattern = 'Volume{.*?}'
foreach ($volume in $CurrentVolumes){
$Volume.volume -match $pattern | Out-Null
$volumeID = $matches[0]
if ($null -ne $volumeID){
$DriveLetter = ($AllVolumes | where-object {$_.deviceid -match $volumeID}).driveletter
$volumeinfo=[PSCustomObject]@{
VolumeID = $volumeID
DriveLetter = $DriveLetter
}
[void]$ShadowVolumes.add($volumeinfo)
}
}
$ShadowVolumes
}
$ShadowVolumes = Get-ShadowVolumes
}
#change permissions and delete shadows
if ($vulnerable) {
icacls c:\windows\system32\config\*.* /inheritance:e
vssadmin delete shadows /quiet /all
}
#check permissions
if ($vulnerable -eq $true) {
$checkPermissions = Get-Acl $env:windir\System32\Config
if ($CheckPermissions.Access.IdentityReference -match $LocalUsersGroup.Name) {
$permissionsSucces = $false
}
else {
$permissionsSucces = $true
}
}
#check shadow
if ($vulnerable -eq $true) {
$checkShadow = Get-WmiObject Win32_ShadowStorage -Property Volume
if ($null -eq $checkShadow) {
$shadowSucces = $true
}
else {
$shadowSucces = $false
}
}
#check if fixed logic
if ($vulnerable -eq $true) {
if ($permissionsSucces -eq $true -and $shadowSucces -eq $true) {
$fixed = $true
}
else {
$fixed = $false
}
}
else {
$fixed = 'Not applicable'
}
#create new shadow
if ($vulnerable -eq $true -and $shadowSucces -eq $true -and $permissionsSucces -eq $true) {
foreach ($volume in $ShadowVolumes){
wmic shadowcopy call create Volume="$($volume.driveletter)\"
}
}
#output data
write-host "vulnerable: $vulnerable"
write-host "Fixed: $fixed"