Skip to content

Commit 5bf02d5

Browse files
committed
Adjust L4J script, add logic to read md5s
1 parent 888c641 commit 5bf02d5

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Find-L4JVulnerabilities.ps1

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ if($EverythingSearch) {
396396
Write-Log -Text "Robocopy search failed. Falling back to Get-ChildItem." -Type WARN
397397
$filesDetected = Get-ChildItem -path "$drive\" -Recurse -Force -ErrorAction 0 | Where-Object {$_.Extension -in ".jar",".log",".txt"} | Select-Object -ExpandProperty FullName
398398
Write-Log -Text "Get-ChildItem found $($filesDetected.Count) files to scan on '$drive\'"
399+
$arrFiles += $filesDetected
399400
}
400401
}
401402
}
@@ -415,7 +416,6 @@ $MD5_BAD = @{
415416
"f1d630c48928096a484e4b95ccb162a0" = "log4j 2.14.0 - 2.14.1"
416417
"5d253e53fa993e122ff012221aa49ec3" = "log4j 2.15.0"
417418
"ba1cf8f81e7b31c709768561ba8ab558" = "log4j 2.16.0"
418-
'1B6E6DD47D8084ABDE61CAA28C96B7A3' = "log4j test-reallynotbad"
419419
}
420420

421421
# Known GOOD
@@ -424,6 +424,7 @@ $MD5_GOOD = @{
424424
"3c3a43af0930a658716b870e66db1569" = "log4j 2.17.1"
425425
}
426426

427+
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
427428
Write-Log -Text "Scanning for JAR files containing potentially insecure Log4j code."
428429
$arrFiles | Where-Object {$_ -match '\.jar$'} | ForEach-Object {
429430
Write-Verbose -Message "Running insecure code scan on file '$_'"
@@ -434,8 +435,8 @@ $arrFiles | Where-Object {$_ -match '\.jar$'} | ForEach-Object {
434435
remove-item -Path $env:TEMP\extract -Recurse -Force -ErrorAction SilentlyContinue
435436
New-Item -ItemType Directory -Path $env:TEMP\extract | Out-Null
436437
}
437-
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
438-
[System.IO.Compression.ZipFile]::ExtractToDirectory($_, "$env:TEMP\extract") | Out-Null
438+
Remove-Item $env:TEMP\extract -Recurse -Force
439+
[System.IO.Compression.ZipFile]::ExtractToDirectory($_, "$env:TEMP\extract") 2>$null | Out-Null
439440
$Files = Get-ChildItem $env:TEMP\extract -Recurse | Where-Object -Property Name -match 'JNDIManager.class'
440441
If ($Files) {
441442
foreach ($file in $files) {
@@ -444,24 +445,20 @@ $arrFiles | Where-Object {$_ -match '\.jar$'} | ForEach-Object {
444445
if ($checksum -in $MD5_BAD.keys ) {
445446
Write-Log -Text "MD5 found in bad list referencing $($MD5_BAD.$checksum)" -Type WARN
446447
#if it's bad, check for jndilookup.class, it will be two directories up under the lookup directory.
447-
$path = Get-Childitem ($File.PSParentPath).replace("\$($file.directory.name)", '')
448+
$ItemPath = Get-item ($File.PSParentPath).replace("\$($file.directory.name)", '')
449+
if (Test-Path "$($ItemPath.PSParentPath)\lookup\JndiLookup.class"){Write-Host "lookupclass file found on $_"; $script:varDetection = 1 } else {if($script:varDetection = 1){$script:Vardetection = 1} else {$script:varDetection = 0}}
448450

449-
$script:varDetection = 1
450451
} elseif ($checksum -in $MD5_GOOD.keys) {
451452
Write-Log -Text "MD5 found in good list referencing $($MD5_BAD.$checksum)" -Type Log
452-
$script:varDetection = 0
453+
if($script:varDetection = 1){$script:Vardetection = 1} else {$script:varDetection = 0}
453454
} else {
454455
Write-Log -Text 'MD5 was not found in any list' -Type Log
455-
$script:varDetection = 0
456+
if($script:varDetection = 1){$script:Vardetection = 1} else {$script:varDetection = 0}
456457
}
457458
}
458459
}
459460
}
460461

461-
462-
if (Select-String -Quiet -Path $_ "JndiLookup.class") {
463-
Write-Log -Text "! ALERT: Potentially vulnerable file at $($_)!" -Type WARN
464-
}
465462
#endregion
466463
if(-not $skipYARA) {
467464
#scan ii: YARA for logfiles & JARs

0 commit comments

Comments
 (0)