This repository has been archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
CVE-2020-1350-checker.ps1
203 lines (180 loc) · 7.7 KB
/
CVE-2020-1350-checker.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
<#
.SYNOPSIS
Checks if your DNS Server is vulnerable for the Remote Code Execution in the Windows DNS Service.
.DESCRIPTION
Script is checking if the CVE-2020-1350 is applicable to your Windows Server and whether the proper Windows Update(s) is installed or not.
.EXAMPLE
PS C:\> .\CVE-2020-1350-checker.ps1
.NOTES
Created by: T13nn3s
Date: 15-07-2020
Check my blog: https://binsec.nl
Last update: 18-07-2020
#>
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
function CheckForDNSServer {
Write-Host "[*] Checking for the Windows DNS Service..."
$DNSService = Get-Service | where-object { $_.name -like "DNS" } -ErrorAction SilentlyContinue
if ($DNSService.Status -eq "Running") {
Write-Host "[+] This server is acting as an Windows DNS Server. CVE-2020-1350 is applicable to this Windows Server." -ForegroundColor Green
}
Else {
Write-Host "[+] This server is not acting as an Windows DNS Server. CVE-2020-1350 is not applicable to this Windows Server." -ForegroundColor Green
Pause
break
}
}# End CheckForDNSServer function
function CheckIfUpdateIsInstalled {
Write-Host "[*] Checking Windows Version..."
$OSVersion = (Get-Itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
if (($OSVersion -eq "Windows Server 2012 Standard") -or ($OSVersion -eq "Windows Server 2012 Datacenter")) {
Write-Host "[*] Windows Server 2012 detected..."
Write-Host "[*] Check if security update or monthley rollup is installed..."
$monthley_W2K2 = Get-HotFix -Id KB4565537 -ErrorAction SilentlyContinue
$security_W2K2 = Get-HotFix -Id KB4565535 -ErrorAction SilentlyContinue
if ($monthley_W2K2) {
Write-Host "[*] *** Windows Update $($monthley_W2K2.HotFixID) is installed on $($monthley_W2K2.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
elseif ($security_W2K2) {
Write-Host "[*] *** Windows Update $($security_W2K2.HotFixID) is installed on $($security_W2K2.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
}
elseif ($OSVersion -like "Windows Server 2012 R2*") {
"[*] Windows Server 2012 R2 detected..."
Write-Host "[*] Check if security update or monthley rollup is installed..."
$monthley_W2K2R2 = Get-HotFix -Id KB4565541 -ErrorAction SilentlyContinue
$security_W2K2R2 = Get-HotFix -Id KB4565540 -ErrorAction SilentlyContinue
if ($monthley_W2K2R2) {
Write-Host "[*] *** Windows Update $($monthley_W2K2R2.HotFixID) is installed on $($monthley_W2K2R2.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
elseif ($security_W2K2R2) {
Write-Host "[*] *** Windows Update $($security_W2K2R2.HotFixID) is installed on $($security_W2K2R2.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
}
elseif ($OSVersion -like "Windows Server 2016*") {
"[*] Windows Server 2016 detected..."
Write-Host "[*] Check if security update or monthley rollup is installed..."
$security_W2K16 = Get-HotFix -Id KB4565511 -ErrorAction SilentlyContinue
if ($security_W2K16) {
Write-Host "[*] *** Windows Update $($security_W2K16.HotFixID) is installed on $($security_W2K16.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
elseif ($OSVersion -like "Windows Server 2019*") {
"[+] Windows Server 2019 detected..."
Write-Host "[*] Check if security update or monthley rollup is installed..."
$security_W2K16 = Get-HotFix -Id KB4558998 -ErrorAction SilentlyContinue
if ($security_W2K16) {
Write-Host "[*] *** Windows Update $($security_W2K16.HotFixID) is installed on $($security_W2K16.InstalledOn). You're not vulnerable ***"
Write-Host "[+] No workaround needed."
break
}
}
Else {
Write-Host "[-] Windows Update $($kb) is not installed."
}
}
} # End function CheckIfUpdateIsInstalled
function Get-Menu {
param (
[string]$title = "Workaround for CVE-2020-1350"
)
Write-Host ""
Write-Host "================ $title ================"
Write-Host "1: Press '1' for check if this service is vulnerable for CVE-2020-1350"
Write-Host "2: Press '2' to apply the CVE-2020-1350 workaround to this server (NOTICE: THe Windows DNS Service will be restarted!)"
Write-Host "Q: Press 'Q' to quit."
} # End function Get-Menu
function Get-RegistryValue {
param
(
[Parameter(Mandatory = $true)]
$RegistryKey
)
$key = Get-Item -Path "Registry::$RegistryKey"
$key.GetValueNames() |
ForEach-Object {
$name = $_
$rv = 1 | Select-Object -Property Name, Type, Value
$rv.Name = $name
$rv.Type = $key.GetValueKind($name)
$rv.Value = $key.GetValue($name)
$rv
}
} # End function Get-RegistryValue
function CheckRegDNS {
param (
[string]$reg = "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters\"
)
$size = "0xFF00"
$check = Get-ItemProperty -Path $reg -Name "TcpReceivePacketSize" -ErrorAction SilentlyContinue
$check_dword = Get-RegistryValue "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNS\Parameters\" | Where-Object { $_.name -eq "TcpReceivePacketSize" } -ErrorAction SilentlyContinue
if (($check.TcpReceivePacketSize -eq $size) -and ($check_dword.type -eq "DWORD")) {
Write-Host "[+] TcpReceivePacketSize size is set to $($size) and is DWORD"
Write-Host "[+] You're not vulnerable." -ForegroundColor Green
break
}
elseif ($check.TcpReceivePacketSize -eq $null) {
Write-Host "[+] TcpReceivePacketSize size is not existing..."
Write-Host "[-] You're vulnerable." -f yellow
}
Else {
Write-Host "[*] Workaround is not applied. Please apply workaround (DNS Service is being restarted!) or install the Security Update."
Write-Host "[-] You're vulnerable." -f yellow
}
} # End function CheckRegDNS
function SetDNSRegWorkaround {
Write-Host "[*] Setting the workaround in the registry..."
$reg = "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters"
$value = "0xFF00"
try {
Set-ItemProperty -Path $reg -name TcpReceivePacketSize -Type DWORD -value $value -Force
Write-Host "[+] Setting the workaround in the registry...Done"
}
Catch {
$err = $_.Exception.Message
Write-Error $err
}
# Restarting DNS Service
Write-Host "[*] Restarting Windows DNS Service..."
try {
restart-service DNS
Write-Host "[+] DNS Service is restarted"
}
Catch {
$err = $_.Exception.Message
Write-Error $err
}
CheckRegDNS
} # End SetDNSRegWorkaround
CheckForDNSServer
CheckIfUpdateIsInstalled
Do {
Get-Menu
$HumanInput = Read-Host "Please make a selection"
switch ($HumanInput) {
'1' {
Write-Host 'You chose option #1'
CheckRegDNS
} '2' {
Write-Host 'You chose option #2'
SetDNSRegWorkaround
} 'Q' {
return
}
}
pause
}
until ($HumanInput -eq 'q')