
Scripts Bash et PowerShell pour analyser un système de fichiers local à la recherche de fichiers .jar Log4j qui pourraient être vulnérables à la CVE-2021-44228, alias Log4Shell.
Ce dépôt contient des scripts qui peuvent aider à identifier les fichiers .jar potentiellement vulnérables à la CVE-2021-44228, également connue sous le nom de Log4Shell.
Ce script recherche les fichiers .jar dans le système de fichiers à partir d'un chemin spécifique, calcule un hash SHA-256 pour chaque fichier .jar trouvé - quel que soit son nom - et compare cette valeur à une liste de hashes SHA-256 fournie par l'utilisateur.
Des fichiers de hashes connus calculés à partir des versions officielles de Log4j sont disponibles sur https://github.com/mubix/CVE-2021-44228-Log4Shell-Hashes, qui est la source du fichier de hashes inclus dans ce dépôt.
REMARQUE : si le fichier .jar de Log4j utilisé dans votre système a été modifié - par exemple parce qu'il a été compilé à partir des sources, parce qu'un éditeur a appliqué des personnalisations de quelque nature que ce soit, ou parce que les classes Log4j ont été incluses dans un fichier .jar plus volumineux - son hash SHA-256 différera de la version officielle correspondante de Log4j et le script ne pourra pas le signaler.
log4shell_hash_check.sh <path> <sha256file>
Ex. : 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>
Ex. : .\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
Ce script recherche les fichiers .jar dans le système de fichiers à partir d'un chemin spécifique et les inspecte pour vérifier s'ils contiennent la classe JndiLookup. Le cas échéant, le script extrait des informations du manifeste du fichier .jar afin de déterminer si le fichier .jar contient une version de Log4j et si celle-ci est vulnérable. Enfin, le script calcule un hash SHA-256 par souci d'exhaustivité.
Il appartient à l'utilisateur de décider si ce script doit être utilisé en complément du script « Vérification des hashes Log4Shell » ou comme outil autonome.
log4shell_jndilookup_finder.sh <path>
Ex. : sudo ./log4shell_jndilookup_finder.sh /
sudo ./log4shell_jndilookup_finder.sh ./
sudo ./log4shell_jndilookup_finder.sh /opt/tomcat/
log4shell_jndilookup_finder.ps1 -path <path>
Ex. : .\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