
Script Bash e PowerShell per scansionare un filesystem locale alla ricerca di file .jar di Log4j che potrebbero essere vulnerabili a CVE-2021-44228, noto anche come Log4Shell.
Questo repository contiene script che possono aiutare a identificare i file .jar che potrebbero essere vulnerabili a CVE-2021-44228, noto anche come Log4Shell.
Questo script trova i file .jar nel filesystem a partire da un percorso specifico, calcola un hash SHA-256 per ogni file .jar trovato - indipendentemente dal nome del file - e confronta questo valore con un elenco di hash SHA-256 fornito dall'utente.
I file di hash noti calcolati sulle release ufficiali di Log4j sono disponibili su https://github.com/mubix/CVE-2021-44228-Log4Shell-Hashes, che è la fonte del file di hash incluso in questo repository.
NOTA: se il file .jar di Log4j in uso nel vostro sistema è stato modificato perché - ad esempio - è stato compilato dai sorgenti, perché un vendor ha applicato personalizzazioni di qualsiasi tipo, o perché le classi di Log4j sono state incluse all'interno di un file .jar più grande, il suo hash SHA-256 differirà dalla corrispondente release ufficiale di Log4j e lo script non sarà in grado di segnalarlo.
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
Questo script trova i file .jar nel filesystem a partire da un percorso specifico e li ispeziona per verificare se contengono la classe JndiLookup. In tal caso, lo script estrae informazioni dal manifest del file .jar che dovrebbero aiutare a determinare se il file .jar contiene una release di Log4j e se questa è vulnerabile. Infine, lo script calcola un hash SHA-256 per completezza.
Spetta all'utente decidere se usare questo script come complemento allo script "Log4Shell Hash Check" o come strumento autonomo.
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