
Bash- und PowerShell-Skripte zum Durchsuchen eines lokalen Dateisystems nach Log4j-.jar-Dateien, die anfällig für CVE-2021-44228, auch bekannt als Log4Shell, sein könnten.
Dieses Repository enthält Skripte, die dabei helfen können, .jar-Dateien zu identifizieren, die möglicherweise anfällig für CVE-2021-44228, auch bekannt als Log4Shell, sind.
Dieses Skript findet .jar-Dateien im Dateisystem, beginnend ab einem bestimmten Pfad, berechnet einen SHA-256-Hash für jede gefundene .jar-Datei – unabhängig vom Dateinamen – und vergleicht diesen Wert mit einer vom Benutzer bereitgestellten Liste von SHA-256-Hashes.
Bekannte Hash-Dateien, die gegen offizielle Log4j-Versionen berechnet wurden, sind unter https://github.com/mubix/CVE-2021-44228-Log4Shell-Hashes verfügbar, was die Quelle der in diesem Repository enthaltenen Hash-Datei ist.
HINWEIS: Wenn die Log4j .jar-Datei, die in Ihrem System verwendet wird, geändert wurde – weil sie beispielsweise aus dem Quellcode kompiliert wurde, weil ein Anbieter Anpassungen jeglicher Art vorgenommen hat oder weil Log4j-Klassen in eine größere .jar-Datei eingebunden wurden – unterscheidet sich ihr SHA-256-Hash von der entsprechenden offiziellen Log4j-Version und das Skript kann sie nicht kennzeichnen.
log4shell_hash_check.sh <path> <sha256file>
E.g.: sudo ./log4shell_hash_check.sh / sha256sum.txt
sudo ./log4shell_hash_check.sh ./ sha256sum.txt
sudo ./log4shell_hash_check.sh /opt/tomcat/ sha256sum.txt
log4shell_hash_check.ps1 -path <path> -hashfile <sha256file>
E.g.: .\log4shell_hash_check.ps1 -path c:\ -hashfile sha256sum.txt
.\log4shell_hash_check.ps1 -path .\ -hashfile sha256sum.txt
.\log4shell_hash_check.ps1 -path c:\opt\tomcat\ -hashfile sha256sum.txt
OccamSec $ ./log4shell_hash_check.sh ./ log4j_2.x_sha256sum.txt
Please be patient, scanning the file system for .jar files starting at ./
.//apache-log4j-2.13.1-bin/log4j-flume-ng-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
[CUT]
.//apache-log4j-2.13.1-bin/log4j-mongodb2-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-sources.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
Checking hash 6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
>>> MATCH: 6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
Checking hash eafab7995f042e0386e08fa5e299d63465b63f1e4e5cb754612c68d52b72516d .//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
List of .jar files found under ./ (if any) saved as ./jarfiles.txt
List of .jar files matching user-provided Log4j hashes (if any) saved as ./matchinglog4j.txt
Dieses Skript findet .jar-Dateien im Dateisystem, beginnend ab einem bestimmten Pfad, und untersucht sie, um zu prüfen, ob sie die JndiLookup-Klasse enthalten. Falls dies der Fall ist, extrahiert das Skript Informationen aus dem Manifest der .jar-Datei, die dabei helfen sollen, festzustellen, ob die .jar-Datei eine Log4j-Version enthält und ob diese anfällig ist. Schließlich berechnet das Skript einen SHA-256-Hash zur Vervollständigung.
Es liegt am Benutzer zu entscheiden, ob dieses Skript als Begleitung zum Skript „Log4Shell Hash Check“ oder als eigenständiges Tool verwendet werden soll.
log4shell_jndilookup_finder.sh <path>
E.g.: sudo ./log4shell_jndilookup_finder.sh /
sudo ./log4shell_jndilookup_finder.sh ./
sudo ./log4shell_jndilookup_finder.sh /opt/tomcat/
log4shell_jndilookup_finder.ps1 -path <path>
E.g.: .\log4shell_jndilookup_finder.ps1 -path c:\
.\log4shell_jndilookup_finder.ps1 -path .\
.\log4shell_jndilookup_finder.ps1 -path c:\opt\tomcat\
OccamSec $ ./log4shell_jndilookup_finder.sh ./
Please be patient, scanning the file system for .jar files starting at ./
.//apache-log4j-2.13.1-bin/log4j-flume-ng-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
[CUT]
.//apache-log4j-2.13.1-bin/log4j-mongodb2-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-sources.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
-------------------------------------------
>>> JndiLookup.class found in: .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
PACKAGE INFORMATION:
Automatic-Module-Name: org.apache.logging.log4j.core
Bundle-Name: Apache Log4j Core
Bundle-SymbolicName: org.apache.logging.log4j.core
Implementation-Title: Apache Log4j Core
Implementation-URL: https://logging.apache.org/log4j/2.x/log4j-core/
Implementation-Vendor-Id: org.apache.logging.log4j
Specification-Title: Apache Log4j Core
VERSION INFORMATION:
Bundle-Version: 2.13.1
Implementation-Version: 2.13.1
Log4jReleaseVersion: 2.13.1
Specification-Version: 2.13.1
SHA-256 hash:
6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 *.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
List of .jar files found under ./ (if any) saved as ./jarfiles.txt
Details about .jar files containing 'JndiLookup.class' (if any) saved as ./jndilookup_jarfiles.txt