Featured image of post Monitoring with PowerShell: Detecting Log4J files

Monitoring with PowerShell: Detecting Log4J files

Hey all, so this is a pretty quick one, to add onto the already many scripts released for this. In this script we’re trying to get all the files that could suffer from the Log4J issue in CVE-2021-44228. I’m saying could, because the script detects a class that is also used in other products, Hence it might end up with some minor false positives.

The script uses “Everything” by Voidtools which is a rapid search tool that can index all files on Windows much faster than anything else. I suggest you host the portable version somewhere yourself so you are able to control exactly which version get’s installed, and you can do your due diligence on there.

As always, I assume you are executing this script as system, from your RMM tooling.

 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
$PortableEverythingURL = "https://www.voidtools.com/Everything-1.4.1.1009.x64.zip"

Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Invoke-WebRequest -UseBasicParsing -Uri $PortableEverythingURL -OutFile "$($ENV:TEMP)\Everything.zip"
Expand-Archive "$($ENV:TEMP)\Everything.zip" -DestinationPath $($ENV:Temp) -Force
if (!(Get-Service "Everything Client" -ErrorAction SilentlyContinue)) {
& "$($ENV:TEMP)\everything.exe" -install-client-service
& "$($ENV:TEMP)\everything.exe" -reindex
start-sleep 3
Install-Module PSEverything
}
else {
& "$($ENV:TEMP)\everything.exe" -reindex
Install-Module PSEverything

}
$ScanResults = search-everything -global -extension jar
if ($ScanResults) {
Write-Host "Potential vulnerable JAR files found. Please investigate:"
Write-Host "all Results:"
$scanresults
    Write-Host "All Results with vulnerable class:"
($ScanResults | ForEach-Object { Select-String "JndiLookup.class" $\_ }).path
}
else {
Write-Host "Did not find any vulnerable files."
}

you can easily implement this script in most RMM systems, and get a quick overview of places you might have log4j active. This is just one of many solutions, Also check out some other solutions by one of my friends, Prejay Shah here. This one uses Search-Everything, but fails back to get-childitem if that is not working.

As always, Happy PowerShelling,.

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy