r/PowerShell • • Dec 18 '21

Here is a Simple Script to detect for potential Log4J Vulnerabilities. I was scanning hashes earlier in the week but that proved unreliable so this just looks for known versions and unpacks to check for the class. Its been quick and reliable so far, just sharing as another option - good luck all!

https://github.com/shawnparslow/Log4jPowerShellScanner/blob/main/ScanLog4JFiles.ps1
138 Upvotes

16 comments sorted by

17

u/[deleted] Dec 18 '21

I'm working on one that uses "Everything" to find all jar files and anything that has log4j in the name and searches the content for the class name. I works but I need to pretty it up.

4

u/[deleted] Dec 18 '21

Interesting, would love to see it. My understanding (from the LunaSec write up at least) is that its only specific versions impacted. Is the class name present in un-impacted versions that would cause false positives? Unless there is a way to fingerprint the class. I am just trying to learn with all this.

4

u/dthmtlgod Dec 18 '21

that is what we did as well.

3

u/[deleted] Dec 18 '21

That app is black magic.

2

u/nickadam Dec 19 '21

perfect description

0

u/[deleted] Dec 18 '21

[deleted]

1

u/[deleted] Dec 18 '21

From my understanding it's not in fixed versions but I'm not acting on anything and just recording the results and reviewing manually. Only a few hundred devices in my environment.

9

u/GrowABrain3 Dec 18 '21

This doesn't work, you have no clue what the filename will look like. You need to search for all .jar and .war files and then select-string for jdnilookup.class inside all of those, and then it might still not work.

but going for log4j-core-version will not work.

2

u/[deleted] Dec 18 '21

Thanks for the feedback, I am still looking at making some changes (I had an earlier version that just checked known sha1). What is in place should find known off-the-shelf named/versioned jar files (and has been working in my scans for specific enterprise products) but I know it does not work for repackaged or renamed distributions.

8

u/belibebond Dec 18 '21

I was doing this but found that Defender ATP already detects log4 files and tags it.

If you have defender in your organization I would go that route as it checks for hash and versions and more.

You can either quarantine it or just audit it.

5

u/belibebond Dec 18 '21

You have to go create advance threat hunting to add filter which shows affected log4 machines and it’s path.

0

u/snickersadmin Dec 19 '21

Please add me