-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiis-vuln-check.ps1
464 lines (376 loc) · 19.9 KB
/
iis-vuln-check.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
################################Ignore Self Signed Certificates################################################
# Create a custom SSL validation callback that accepts all certificates
Add-Type -TypeDefinition @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class SSLValidator {
public static void Ignore() {
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(
delegate { return true; }
);
}
}
"@
# Call the SSL validation callback to ignore certificate validation
[SSLValidator]::Ignore()
################################Ignore Self Signed Certificates################################################
function CheckSecurityHeaders {
param (
[string]$url
)
$response = Invoke-WebRequest -Uri $url
if ($response -eq $null) {
throw "Failed to retrieve headers from $url"
}
$headers = $response.Headers
if ($headers -eq $null) {
throw "Failed to retrieve headers from the response"
}
$requiredHeaders = @{
"Strict-Transport-Security" = "CVE-2019-13498 :`nNot using HTTP Strict Transport Security (HSTS) may lead to man-in-the-middle (MITM) attacks."
"X-Content-Type-Options" = "CVE-2018-17031 : `nan attacker can use a crafted .eml file to trigger MIME type sniffing, which leads to XSS, as demonstrated by Internet Explorer, `nbecause an X-Content-Type-Options: nosniff header is not sent."
"X-Frame-Options" = "CVE-2022-3260 : `nThe response header has not enabled X-FRAME-OPTIONS, Which helps prevents against Clickjacking attack."
"X-XSS-Protection" = "CVE-2018-7504 : `nThe X-XSS-Protection response header is not set to block, allowing attempts at reflected cross-site scripting"
"Content-Security-Policy" = "CVE-2018-5164 : `nContent Security Policy (CSP) is not applied correctly to all parts of multipart content sent with the multipart/x-mixed-replace MIME type"
}
$missingHeaders = @()
foreach ($header in $requiredHeaders.GetEnumerator()) {
if (!$headers.ContainsKey($header.Key)) {
$missingHeaders += [PSCustomObject]@{
Header = $header.Key
CVE = $header.Value
}
}
}
return $missingHeaders
}
function CheckInsecureCookies {
param(
[string]$url
)
$response = Invoke-WebRequest -Uri $url
$cookies = $response.Headers["Set-Cookie"]
$insecureCookies = @()
$cookiesWithoutHttpOnly = @()
$cookiesWithoutSameSite = @()
foreach ($cookie in $cookies) {
if ($cookie -notlike "*Secure*") {
$cookieName = ($cookie -split ";")[0]
$insecureCookies += $cookieName
}
if ($cookie -notlike "*HttpOnly*") {
$cookieName = ($cookie -split ";")[0]
$cookiesWithoutHttpOnly += $cookieName
}
if ($cookie -notlike "*SameSite*") {
$cookieName = ($cookie -split ";")[0]
$cookiesWithoutSameSite += $cookieName
}
}
$result = @{
"InsecureCookies" = $insecureCookies
"CookiesWithoutHttpOnly" = $cookiesWithoutHttpOnly
"CookiesWithoutSameSite" = $cookiesWithoutSameSite
}
return $result
}
function CheckIISAndASPNETVersions {
param(
[string]$url
)
$headers = Invoke-WebRequest -Uri $url | Select-Object -ExpandProperty Headers
$iisVersion = $headers['Server']
$aspNetVersion = $headers['X-AspNet-Version']
$aspPoweredBy = $headers['X-Powered-By']
$result = @{}
if ($iisVersion) {
$result['IISVersion'] = $iisVersion
}
if ($aspNetVersion) {
$result['ASPNETVersion'] = $aspNetVersion
}
if ($aspNetVersion) {
$result['X-Powered-By'] = $aspPoweredBy
}
return $result
Write-Host "Following Header needs to be remove: " $result -ForegroundColor Red
}
function CheckTLSVersions {
param(
[string]$url
)
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "HEAD"
try {
$response = $request.GetResponse()
$tlsVersion = $response.ProtocolVersion
if ($tlsVersion -eq "Tls" -or $tlsVersion -eq "Tls11") {
return $true
} else {
return $false
}
} catch {
# In case of an error, assume that TLS 1.0 or TLS 1.1 is not supported.
return $false
}
}
function CheckHttpsRedirect {
param (
[string]$url
)
$response = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction SilentlyContinue
if ($response -eq $null) {
return $false
}
$statusCode = $response.StatusCode
if ($statusCode -eq 301 -or $statusCode -eq 302) {
return $true
} else {
return $false
}
}
$targetUrl = Read-Host "Domain to check (e.g., example.com)"
$successCount = 10
$output = @()
$output += "`n`n`nVULNERABILITY REPORT FOR DOMAIN: $targetUrl`n`n`n"
# Replace 'http://example.com' with the URL of your ASP.NET app
# Prompt the user for the domain to check
# Add "https://" to the beginning if not provided by the user
if (-not ($targetUrl -like "https://*") -and -not ($targetUrl -like "http://*")) {
$targetUrl = "http://$targetUrl"
}
$output += "`n`nHTTP to HTTPS Redirect Result:"
$isHttpsRedirect = CheckHttpsRedirect -url $targetUrl
if ($isHttpsRedirect) {
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " -ForegroundColor Green
Write-Host "Domain is redirected to HTTPS scheme." -ForegroundColor Green
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " -ForegroundColor Green
$output += "`nDomain is redirected to HTTPS scheme."
} else {
Write-Host "------------------------------------------------------------------ " -ForegroundColor Red
Write-Host "No HTTPS redirect found! Go Check CVE-2022-22797" -ForegroundColor Red
Write-Host "------------------------------------------------------------------ " -ForegroundColor Red
$successCount = $successCount-0.5
$output += "`nNo HTTPS redirect found! Go Check CVE-2022-22797"
$output +="`nRisk: MEDIUM."
$output+= "`n1.Install the URL Rewrite Module:
`nIf you haven't already installed the URL Rewrite Module, you can download and install it from the Microsoft website or use the Web Platform Installer.
`n2.Open IIS Manager:
Open Internet Information Services (IIS) Manager on your server.
`n3.Select Your Website:
`nIn the left-hand pane, navigate to your website (or the specific application) for which you want to enforce HTTPS.
`n4.Open URL Rewrite Feature:
`nDouble-click on the URL Rewrite feature in the middle pane.
`n5.Add a Rule:
`nIn the URL Rewrite module, click Add Rule(s) on the right-hand side.
`n6.Choose Blank Rule:
`nSelect Blank Rule from the Inbound Rule templates.
`n7.Configure the Rule:
`nFill in the following details:
`nName: Give your rule a name (e.g., HTTP to HTTPS Redirect).
`nRequested URL: Choose Matches the Pattern.
`nUsing: Choose Regular Expressions.
`nPattern: Use (.*) to match any URL.
`nIgnore case: Checked.
`nAction Type: Choose Redirect.
`nRedirect URL: Use https://{HTTP_HOST}/{R:1} to redirect to HTTPS.
`nRedirect type: Choose Permanent (301) for a permanent redirect.
`n7.Click Apply in the right-hand pane to save the rule and apply it to your website."
}
$output += "`n----------------------------------------------------------------"
$output += "`nMissing Security Headers Result:"
$missingHeaders = CheckSecurityHeaders -url $targetUrl
$insecureCookiesResult = CheckInsecureCookies -url $targetUrl
$insecureCookies = $insecureCookiesResult["InsecureCookies"]
$cookiesWithoutHttpOnly = $insecureCookiesResult["CookiesWithoutHttpOnly"]
$iisAndAspNetVersions = CheckIISAndASPNETVersions -url $targetUrl
$missingHeaders = CheckSecurityHeaders -url $targetUrl
if ($missingHeaders.Count -gt 0) {
Write-Host "Missing The Following Security Headers:"
$missingHeaders | Format-Table -AutoSize -Property Header, CVE
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " -ForegroundColor DarkYellow
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " -ForegroundColor DarkYellow
$successCount = $successCount-3
$headers = $missingHeaders | ForEach-Object { $_.Header }
$cves = $missingHeaders | ForEach-Object { $_.CVE }
$output += "`nMissing security headers: `n$($headers -join ', ')`nRelated CVE's: `n$($cves -join ', ')`n"
$output +="`nRisk: HIGH."
$output +="`nPossible Solution: `nOn IIS, go to Response Headers, right click and add the desired header name and its value."
} else {
Write-Host "All required security headers are present." -ForegroundColor Green
$output += "`nAll required security headers are present."
}
$output += "`n----------------------------------------------------------------"
$output += "`nInsecure Cookies Check:"
if ($insecureCookies.Count -gt 0) {
Write-Host "------------------------------------------------------------------ "
Write-Host "Insecure cookies found:"
$insecureCookies | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount--
$output += "`nInsecure cookies found: $insecureCookies"
$output +="`nInsecure cookies can lead to various security risks, including session hijacking, cross-site scripting (XSS) attacks, and man-in-the-middle attacks."
$output +="`nRisk: Medium."
} else {
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "No Insecured cookies found." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output += "`nNo Insecured cookies found."
}
if ($cookiesWithoutHttpOnly.Count -gt 0) {
Write-Host "------------------------------------------------------------------ "
Write-Host "Cookies without HttpOnly attribute found:"
$cookiesWithoutHttpOnly | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount-0.5
$output += "`nCookies without HttpOnly attribute found: $cookiesWithoutHttpOnly "
$output += "`nVulnerability Description:Not using the HttpOnly attribute may lead to client-side scripts to access cookies, increasing the risk of XSS attacks"
$output += "`nRisk: MEDIUM"
} else {
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "Did not find and cookies without HttpOnly attribute." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output += "`nDid not find and cookies without HttpOnly attribute."
}
if ($cookiesWithoutSameSite.Count -gt 0) {
Write-Host "------------------------------------------------------------------ "
Write-Host "Cookies without SameSite attribute found:"
$cookiesWithoutHttpOnly | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount-0.5
$output += "`nCookies without HttpOnly attribute found: $cookiesWithoutSameSite "
$output += "`nThe SameSite attribute is a relatively new feature in web browsers that helps control how cookies are sent in cross-origin requests.
`nNot using the SameSite attribute for cookies can introduce security risks, particularly related to Cross-Site Request Forgery (CSRF) attacks and user privacy. "
$output += "`nRisk: MEDIUM"
} else {
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "Did not find and cookies without SameSite attribute." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output += "`nDid not find and cookies without SameSite attribute."
}
$output += "`n----------------------------------------------------------------"
$output += "`nHeaders Containing Information Disclosure about Web Server:"
if ($iisAndAspNetVersions['IISVersion']) {
Write-Host "------------------------------------------------------------------ "
Write-Host "`nIIS Version Header Found: $($iisAndAspNetVersions['IISVersion']). Go Check "
Write-Host "CVE-2020-0645" -ForegroundColor Red -NoNewline
Write-Host ", " -NoNewline
Write-Host "CVE-2011-5279" -ForegroundColor Red
$output += "`nIIS Version Header Found: $($iisAndAspNetVersions['IISVersion']). Realted Vulnerabilities: `nCVE-2020-0645 `nCVE-2011-5279"
Write-Host "------------------------------------------------------------------ "
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host " `nSuggested Solution`n: `n1.Open IIS `n2.Click on Server Name.`n3.Open the Configuration Editor `n4.Open the dropdown `n7.go to System.Web/Security `n8.switch RemoveServerHeader to true." -ForegroundColor Green
$output += "`nSuggested Solution`n: `n1.Open IIS `n2.Click on Server Name.`n3.Open the Configuration Editor `n4.Open the dropdown `n7.go to System.Web/Security `n8.switch RemoveServerHeader to true.
and click on 'Save."
$output +="`nRisk: MEDIUM."
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$successCount = $successCount-0.5
}
else{
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "No IIS Version Header ['IISVersion'] Was Found." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output += "No IIS Version Header ['IISVersion'] Was Found."
}
if ($iisAndAspNetVersions['ASPNETVersion']) {
Write-Host "------------------------------------------------------------------ "
Write-Host "`nWarning: ASP.NET Header Version Was Found: $($iisAndAspNetVersions['ASPNETVersion'])" -ForegroundColor DarkYellow
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount-0.5
$output +="`nWarning: ASP.NET Header Version Was Found: $($iisAndAspNetVersions['ASPNETVersion'])"
$output +="`nRisk: MEDIUM."
$output += "`n Solution: `n1.Open the web.config file of your ASP.NET web application. `nLocate the <system.web> section, and within it, add the following:
`n<httpRuntime> :
`n<system.web>
`n<httpRuntime enableVersionHeader='false'/>
`n</system.web>"
}
else{
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "No ASP.NET Version Header ['ASPNETVersion'] Was Found." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output +="`nNo ASP.NET Version Header ['ASPNETVersion'] Was Found."
}
if ($iisAndAspNetVersions['X-Powered-By']) {
Write-Host "------------------------------------------------------------------ "
Write-Host "`nWarning: ASP.NET Header Version Was Found: $($iisAndAspNetVersions['X-Powered-By']). Go Check CWE-200 for more details." -ForegroundColor DarkYellow
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount-1
$output +="`nWarning: ASP.NET Header Version Was Found: $($iisAndAspNetVersions['X-Powered-By']).Warning: An X-Powered-By header was found. Value: $XPoweredBy. `nRelated vulnerability: `nCWE-200. `nShort Description:The web/application server is leaking information via one or more X-Powered-By HTTP response headers.
`nAccess to such information may facilitate attackers identifying other frameworks/components your web application is reliant
`nupon and the vulnerabilities such components may be subject to."
$output +="`nRisk: MEDIUM."
$output += "`nSuggested Solution: `n1.Open IIS `n2.Click on Server Name 3.`n4.Click On Response Headers `n5.Right click on the X-Powered-By and Remove it."
}
else{
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "No Framework Header ['X-Powered-By'] Was Found." -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output +="`nNo Framework Header ['X-Powered-By'] Was Found."
}
$output += "`n----------------------------------------------------------------"
$output += "`n----------------------------------------------------------------"
$output += "`n`n`n`nTLS Version Check:"
$insecureTLS = CheckTLSVersions -url $targetUrl
if ($insecureTLS) {
Write-Host "------------------------------------------------------------------ "
Write-Host "`nWarning: Insecure TLS version (TLS 1.0 or TLS 1.1) is supported by the domain SSL certificate. `n Consider using an SSL with a higher TLS version." -ForegroundColor -ForegroundColor DarkYellow
Write-Host "`nRisk: HIGH"
Write-Host "------------------------------------------------------------------ "
$successCount = $successCount-1
$output += "`n`nWarning: Insecure TLS version (TLS 1.0 or TLS 1.1) is supported by the domain SSL certificate. `n Consider using an SSL with a higher TLS version."
$output +="`nRisk: HIGH."
}
else{
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
Write-Host "No 1.1 or 1.0 TLS versions found on target domain: " $targetUrl -ForegroundColor Green
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
$output += "`n`nNo 1.1 or 1.0 TLS versions found on target domain: $targetUrl "
}
$output += "`n`nAfter Everything Checked, this is the following calculted score:"
# Check if all checks were successful (all results are green)
if ($successCount -eq 10) {
Write-Host "Total result score: 10/10" -ForegroundColor Green
$output += "`n`n`nTotal result score: $successCount/10"
} elseif ($successCount -gt 6) {
Write-Host "Total result score: $successCount/10" -ForegroundColor DarkYellow
$output += "`n`n`nTotal result score: $successCount/10"
} else {
Write-Host "Total result score: $successCount/10" -ForegroundColor Red
$output += "`n`n`nTotal result score: $successCount/10"
}
$output += "`n----------------------------------------------------------------"
function ConvertTo-PDF {
param (
[string]$Source,
[string]$Destination
)
try {
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$doc = $word.Documents.Open($Source)
$doc.SaveAs([ref]$Destination, [ref]17)
$doc.Close()
$word.Quit()
Write-Host "PDF created: $Destination" -ForegroundColor Green
}
catch {
Write-Host "Failed to create PDF: $_" -ForegroundColor Red
}
}
# Prompt the user to export a PDF results file
$exportToPdf = Read-Host "Would you like to export a PDF results file (y/n)?"
if ($exportToPdf -eq "y" -or $exportToPdf -eq "Y") {
# Save the output to a text file
$outputFilePath = "$env:TEMP\script_output.txt"
$output | Out-File -FilePath $outputFilePath -Encoding UTF8
# Convert the text file to PDF
$pdfFilePath = Read-Host "Enter the PDF file path to save the results (e.g., C:\Path\To\Results.pdf)"
ConvertTo-PDF -Source $outputFilePath -Destination $pdfFilePath
}
else {
Write-Host "Done checking."
}