You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Purpose: Detection of jar files vulnerable to log4j RCE vulnerability (CVE-2021-44228)
7
-
Utilizing JNDILookup detection method posted to https://gist.github.com/Neo23x0/e4c8b03ff8cdf1fa63b7d15db6e3860b with some slight modifications to make it more RMM friendly
8
-
9
-
NOTE: Have excluded files within windows\system32\spool\drivers from being scanned due to access denied issues disrupting the output.
5
+
Thanks: Christopher Bledsoe (IPM Computers) for some bugfixes,
6
+
Robby Swartenbroekx (b-Inside) for some ideas,
7
+
Arctic Wolf for coming up with a way to detect patched files
8
+
Purpose: Detection of jar files vulnerable to the "Log4Shell" log4j RCE vulnerability (CVE-2021-44228)
9
+
Originally Utilizing JNDILookup detection method posted to https://gist.github.com/Neo23x0/e4c8b03ff8cdf1fa63b7d15db6e3860b with some slight modifications to make it more RMM friendly
10
+
Log4J 2.15 fixed the original Log4Shell CVE, but was suspectable to CVE-2021-44228 which was elevated to an RCE vulnerability and fixed in Log4J 2.16
11
+
I then adopted a method presented to me on behalf of ArcticWolf (https://github.com/rtkwlf/wolf-tools/blob/main/log4shell/log4shell_deep_scan.ps1) of extracting the JAR/WAR/EAR file to corroborate whether the Log4J 2.16 changes have been applied to a JAR file.
12
+
Robby S then suggested an amendment to be able to track the updated fix in 2.17 for CVE-2021-45105 that was introduced in Log4J 2.16.
10
13
14
+
NOTE: Only scans against NTFS File Format
15
+
RMM Output optimized for N-Central
16
+
Not currently compatible with Powershell 2.0
17
+
Have excluded files within windows\system32\spool\drivers from being scanned due to access denied issues disrupting the output.
11
18
12
19
0.1 Initial Release
13
-
0.1.1 Adeed Dedupe to Vulnerable .JAR Listings
20
+
0.1.1 Added Dedupe to Vulnerable .JAR Listings
14
21
0.1.2 Public Release
15
22
0.1.3 Found that use of -force isn't working for all scans. Have added a non forced mode to see what outputs can be obtained
16
23
0.1.4 Experimenting with Unicode/Robocopy to bypass 260 character file path limit / access denied errors
17
-
0.1.5 added support for pseverything module
24
+
0.1.5 added support for PSEverything module
18
25
0.1.5.1 changed detection to be module based rather than command based
19
26
0.1.5.2 Cleaned up Output
20
27
0.1.6 Have revamped order to PSEverything, Robocopy, GCI
21
28
0.1.6.1 Fixed Typo, Modification for N-Central AMP Output of file names when robocopy is utilized
22
-
0.1.7 Some bugfixes courtesy of Christopher Bledsoe (IPM Computers). Who knew cinaccessible cloud only JAR files would be a thing?
29
+
0.1.7 Some bugfixes courtesy of Christopher Bledsoe (IPM Computers). Who knew inaccessible cloud only JAR files would be an issue?
23
30
won't try checking an empty file path
24
31
should ignore those "placeholder.jar" files in things like dropbox cache
25
32
it uses "|" for the delimiter when reading the CSV/txt file created, so any file paths with "," in them should not get unintentionally split
26
33
0.1.7.1 Excluding spool\drivers jar files from being scanned
27
34
0.1.7.2 Updated gci to use -filter and -file rather than -include after finding it to be much more performant
35
+
0.1.8 Fix for Everything/gci compatibility, Update for Log4j 2.16 update
36
+
0.1.8.1 Improved Try/Catch methodology for when Everything search Fails. Thanks to Robby Swartenbroekx (b-Inside) for the assist.
37
+
0.1.8.2 Made robocopy window hidden by request
38
+
0.1.8.3 Improved Vulnerable File Output for RMM
39
+
0.1.9 Expanded Search Criteria to all fixed drives on a device, and added update for Log4j 2.17 Compatibility (Thx to Robby S)
40
+
0.2 Separated detection of Log4j 2.16 Patched and 2.17 Patched States
41
+
0.2.1 Adding better output for when Everything fails to scan via RMM PS wrapping
42
+
0.2.2 Expanded search to cover .jar/.war/.ear files, and partial fix for oddity with scanning certain file names (Thx to Robby S)
43
+
0.2.3 Adding more error logging to RMM output in order to surface files that aren't being scanned, amended query to exclude drives that aren't formatted to NTFS
44
+
0.2.4 Moved Tasks into Functions, Fixed output bug for number counts.
45
+
0.2.4.1 Changed robocopy export/csv import encoding to fix issue with display of special characters in file names
28
46
#>
29
47
30
-
$Version="0.1.7.2"#14th December 2021
31
-
Write-Host"get-log4jrcevulnerability $version"-foregroundcolor Green
48
+
$Version="0.2.4.1"#21st December 2021
49
+
Write-Host"`nget-log4jrcevulnerability $version"-foregroundcolor Green
32
50
$robocopycsv=$null
51
+
$log4junscanned=$null
52
+
$log4jvulnerablefiles=$null
53
+
$robocopycsvfile="$env:temp\log4jfilescan.csv"
33
54
34
55
35
-
if (get-module-listavailable |where-object {$_.name-like'PSEverything'}) {
36
-
Write-Host"The almighty PSEverything module's Search-Everything command was found.`nDoing a new scan because we can..."-ForegroundColor Yellow
Write-host"See? That only took $([math]::Round($($Timetaken),2)) seconds to scan all Fixed NTFS Drives for .jar/.war/.ear files!"-foregroundcolor Green
69
+
$log4jfilenames=$log4jfilescan
70
+
}
71
+
else {
72
+
$StopWatch.stop()
73
+
Write-Host$($StopWatch.elapsed.totalseconds) -ForegroundColor Red
74
+
Write-Host"Something went wrong with calling PSEverything, lets fallback to the next scan method."-ForegroundColor Yellow
75
+
Throw
76
+
}
77
+
}
78
+
else {
79
+
# Write-Host "Something went wrong with calling PSEverything, lets fallback to the next scan method." -ForegroundColor Yellow
80
+
Throw
81
+
}
82
+
}
83
+
catch {
84
+
#Run when PSEverything isn't found or it gave an error
Write-Host"ERROR: Unable to scan $_"-ForegroundColor Red
144
+
$log4junscanned=$log4junscanned+"<br>ERROR: Unable to scan $_"
145
+
}
146
+
}
147
+
}
148
+
} |select-object-exp Path |sort-object-unique
149
+
}
73
150
}
74
-
else {
75
-
Write-Host"Determining whether any of the $(($log4jfilenames).count) found .jar files are vulnerable to CVE-2021-44228 due to being capable of JNDI lookups..."-ForegroundColor Yellow
Write-Host"$($log4jpotentiallyvulnerablefile|split-path-leaf) has been patched to Log4j 2.15/2.16 which addresses `Log4Shell` (CVE-2021-44228), however is still vulnerable to CVE-2021-45105"-ForegroundColor Red
$log4jvulnerable="$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') OK - 0 Vulnerable JAR files were found"
103
-
write-host"Log4J CVE-2021-44228 Vulnerable Files:`n$log4jvulnerable"-ForegroundColor Green
104
-
} elseif ($log4jvulnerablefiles-ne$null) {
105
-
Write-Host"$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') WARNING - $log4jvulnerablefilecount Vulnerable JAR file(s) were found"-foregroundcolor Red
106
-
write-host"Log4J CVE-2021-44228 Vulnerable Files:`n$log4jvulnerablefiles"-ForegroundColor Red
107
-
$log4jvulnerable=$log4jvulnerablefiles-join'<br>'
212
+
}
213
+
214
+
}
215
+
216
+
FunctionProcess-Output {
217
+
if ($log4jvulnerablefilecount-eq'0') {
218
+
if ($log4junscanned-eq$null) {
219
+
$log4jvulnerable="$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') OK - 0 Vulnerable JAR/WAR/EAR files were found"
220
+
write-host"$log4jvulnerable"-ForegroundColor Green
108
221
}
109
-
# Write-Host "Log4j Files found:`n$log4jfiles"
110
-
$log4jfiles=$log4jfilenames-join'<br>'
222
+
else {
223
+
$log4jvulnerablefilecount='-1'
224
+
}
225
+
}
226
+
227
+
if ($log4jvulnerablefilecount-eq'-1') {
228
+
Write-Host"`n$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') WARNING - Certain Files were unable to be scanned and will require further inspection"-ForegroundColor Yellow
229
+
Write-Host$log4junscanned-ForegroundColor Red
230
+
Write-Host"Vulnerable Files: $log4jvulnerablefilecount"-ForegroundColor Red
231
+
$log4jvulnerable=$log4junscanned
232
+
}
233
+
234
+
if ([decimal]$log4jvulnerablefilecount-ge'1') {
235
+
Write-Host"`n$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') WARNING - $log4jvulnerablefilecount Vulnerable File(s) found:"-foregroundcolor Red
236
+
$log4jvulnerablefiles|Foreach-object ({ Write-Host$_-ForegroundColor Red })
237
+
Write-Host"Recommend that these Files be updated to utilize Log4J 2.17 at the earliest opportunity"-ForegroundColor Cyan
$log4jfiles="$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') OK - No JAR/WAR/EAR Files were found on this device"
253
+
$log4jvulnerable="$(Get-Date-Format 'yyyy-MM-dd HH:mm:ss') OK - No JAR/WAR/EAR Files were found on this device"
254
+
$log4jvulnerablefilecount='0'
255
+
Write-Host"$log4jvulnerable"-ForegroundColor Green
256
+
}
257
+
else {
258
+
Write-Host"Determining whether any of the $(($log4jfilenames).count) jar/war/ear files found are potentially vulnerable to CVE-2021-44228 (Log4Shell) due to being capable of JNDI lookups..."-ForegroundColor Yellow
Write-Host"$log4jpotentiallyvulnerablefilecount Potentially Vulnerable JAR/WAR/EAR file(s) were found:"-foregroundcolor Red
272
+
$log4jpotentiallyvulnerablefiles|Foreach-object ({ Write-Host$_-ForegroundColor Red })
273
+
Write-Host"`nChecking the $($log4jpotentiallyvulnerablefiles.count) potentially vulnerable files for an actual vulnerability now that Log4j 2.17 has been released..."-foregroundcolor Yellow
0 commit comments