-
Notifications
You must be signed in to change notification settings - Fork 166
/
Mitigation.ps1
77 lines (59 loc) · 1.93 KB
/
Mitigation.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
# Fix HiveNightmare ACLs and snapshots
# v1.0
# Originally by unknown and adapted by @doctormay6 and @GossiTheDog
# Schedule to run as SYSTEM in a deployment tool, test locally first
# Do not run on Windows Server in case you use VSS for backups
#change permissions and delete shadows
$checkPermissions = icacls c:\Windows\System32\config\sam
if ($checkPermissions -like '*BUILTIN\Users:(I)(RX*)*') {
icacls c:\windows\system32\config\*.* /inheritance:e
vssadmin delete shadows /quiet /all
$vulnerable = $true
}
else {
$vulnerable = $false
}
#check permissions
if ($vulnerable -eq $true) {
$checkPermissions = icacls C:\windows\system32\config\sam
if ($checkPermissions -like '*BUILTIN\Users:(I)(RX*)*') {
$permissionsSucces = $false
write-host "ACL change failed. Check permissions running script, e.g. run as SYSTEM."
}
else {
$permissionsSucces = $true
Write-Host "Successfully reset permission inheritance on affected files."
}
}
#check shadow
if ($vulnerable -eq $true) {
$checkShadow = Get-WmiObject Win32_ShadowStorage -Property UsedSpace | Select-Object -ExpandProperty UsedSpace
if (0 -eq $checkShadow) {
$shadowSucces = $true
Write-Host "Successfully deleted old volume shadow copies."
}
else {
$shadowSucces = $false
write-host "Shadow deletion failed. Security software may be blocking this action or check running permissions."
}
}
#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) {
wmic shadowcopy call create Volume='C:\'
Write-Host ""
}
#output data
write-host "vulnerable: $vulnerable"
write-host "Fixed: $fixed"