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.

$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,.

Recent Articles

Automating with PowerShell: making stolen tokens useless with Global Secure Access

Last week I watched Merill Fernando talk to Alex Pavlovsky and Marilee Tuscak from the Entra team about something I’d kinda put under the “needs a GSA licence” branch and i’d check it out later, turns out that like most people, I half-assed the documentation and it turns out it doesn’t. There’s two features that come with any P1 license; Compliant network check and Source IP Restoration. So BP, P1, or even frontline worker licenses already have this.

CIPP ❤️ #IntuneForMSPs

We’re Joining #IntuneForMSPs 🎉

Being invited by Microsoft to join a global initiative is a big moment for us, and we want to be clear about why it matters. #IntuneForMSPs is Microsoft’s program to help MSPs deliver Microsoft 365, Intune, and Copilot services at scale, and CIPP is now part of it, bringing the largest MSP community in the channel directly to Microsoft.

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)