Local Bytecode Scanner for the Log4JShell Vulnerability (CVE-2021-44228)

Overview

πŸ” Log4JShell Bytecode Detector

Log4jShell Bytecode Detector is an open source tool that helps identify if a jar file is affected by the critical CVE-2021-44228. The tool scans the jar file and compares the classses against a set of vulnerable hashes for classes within the jar file. The hashes have been pre-computed for artifacts on Maven Central.

IMPORTANT UPDATE: We extended the list of affected artifacts on Maven Central. The list contains 18.816 artifacts. The artifacts either use log4j-core as declared dependency, or we identified .class files within the artifacts that match to the affected versions of log4j-core.

πŸ“ How to run

  1. Download the jar file under releases.
  2. Run java -cp <PATH_TO_DOWNLOADED_JAR> de.codeshield.log4jshell.Log4JDetector <ABSOLUTE_PATH_TO_JAR_TO_CHECK>

If the jar is affected, the tool outputs information to the command-line:

CVE-2021-44228 found declared as dependency in META-INF/maven/org.apache.logging.log4j/log4j-core/pom.xml
CVE-2021-44228 found in class file org/apache/logging/log4j/core/net/JndiManager$1.class

πŸ“ How to run on a live server (no need to stop your running Java instances)

  1. Download the jar file under releases.
  2. Run java -cp <PATH_TO_DOWNLOADED_JAR> de.codeshield.log4jshell.Log4JProcessDetector
  3. The jar searches the classpath of all running java processes for vulnerable log4j instances

❓ Background on CVE-2021-44228

A serious Remote Code Execution vulnerability has been discovered within log4j and version 2.0-beta9 to 2.14 are affected. The vulnerability has been classified as critical, as it affected log4j one of the most used logging libraries for Java. There are many references and article out there.

πŸ‘€ Why is it important?

Log4j is and has been used in mostly any Java project for logging purposes. Now we need to understand which projects and libraries are actually affected. As of Java's dependency mechanism, an application can also be affected if it transitively includes the vulnerable library version. A project A includes a library lib transitively, if one of the direct dependecy B of A has a dependecy to lib. A simple test to see if one is affected can be done using using the maven dependecy tree:

Example: Execute command mvn dependency:tree on a maven project.

[INFO] exampleProject:mainProject:jar:0.0.1-SNAPSHOT
[INFO] +- exampleProject:lib-using-log4j:jar:0.0.1-SNAPSHOT:compile
[INFO] |  \- org.apache.logging.log4j:log4j-core:jar:2.14.1:compile

This check, however, is only a first indication and does not suffice due to the following reasons:

Java programs are frequently:

  • packaged as fatjar or uberjar: All class files (including direct and transitive dependencies) are shipped into a single jar file. (as we do for this software artifact)
  • re-packaged or rebundled: the originaly package names are changed to avoid naming conflicts (some compilers and package mechanism apply code transformations)
  • re-compiled: The source code is compiled with a different compiler and packaged as new, which leads to modified bytecode

Consequently, any library a Java project is using can include the vulnerability into your project. An in-depth bytecode analysis helps, which is what we publish as part of this repository.

πŸ“• The script

  1. Extract pom.xml files from .jar
  2. check declared dependencies against a pre-computed list of affected groupId:artifactId:version list for artifacts hosten on Maven Central
  3. Extract .class files from .jar
  4. Compute SHA hashes of the class file
  5. Match SHAs against a pre-computed list

πŸ›  Build Instructions

To build this tool run

mvn compile

For assembling a runnable jar use

mvn clean compile assembly:single

πŸ’‘ Precomputed Hashes of Vulnerable Classes

The set of vulnerable hashes for classes has been pre-computed on entire Maven Central repository. The hashes of the classes contain all hashes that we identified as bytecode-similar using the Fingerprinting technology.

The pre-computed information contains:

  • all artifacts that directly include log4j in any of the vulnerable version
  • all artifacts that ship a class that contains a vulnerable hash of log4j in the affected version range
  • all artifacts that rebundle a vulnerable class of log4j
  • all artifacts that have a re-compiled class of a class of log4j in the affected version range

As affected version range we considered [2.0-beta9, 2.15) Reference.

πŸ’» Fingerprinting Technology

This tool uses a new bytecode fingerprinting technology for Java that has been invented by Andreas Dann. The basic flow is as follows.

  1. Use the available fix commits Commit1, Commit2, and Commit3 to identify which classes are affected.
  2. Compute bytecode "Fingerprints" of vulnerable classes.
  3. Search for other classes on MavenCentral with same "Fingerprint".

Note: For a simpler roll out, this repository does ship SHA hashes of the vulnerable classes, the information has been computed using Fingerprinting

πŸ“Œ Disclaimer

The list of hashes and maven artifacts is not complete. We will regularly update the lists.

πŸ“― Contributors

This tool was co-created by the CodeShield co-founders

Feedback is welcome!

We are working on extending on the the list of affected artifacts and are always looking to improve our offering. contribution welcome

Also, ⭐️  this repository if our scanner helped you!

✍️ Contact

If you need support, or want to hear about our technology contact us at [email protected].

Your CodeShield Team πŸ’š

Comments
  • Log4j core 2.17.1 shows as vulnerable

    Log4j core 2.17.1 shows as vulnerable

    If I download the latest Log4j core jar file from maven https://repo1.maven.org/maven2/org/lucee/log4j-core/2.17.1/log4j-core-2.17.1.jar

    and scan it, I get this message:

    Analysing log4j-core-2.17.1.jar
    CVE-2021-44228 found in class file D:\Downloads\log4j-core-2.17.1\org\apache\logging\log4j\core\util\NetUtils.class
    

    Is the latest jar still vulnerable or is the scanner wrong? I'm using the latest Log4JDetector-0.7.2-jar-with-dependencies.jar to scan.

    opened by bdw429s 4
  • VulnerableGavs.csv

    VulnerableGavs.csv

    Dear Andreas, all,

    Great tool, thank you for taking this initiative!

    I just had a quick look at VulnerableGavs.csv and noticed that groupId and artifactId are confused for some of the GAVs (e.g. io.apiman:apiman-gateway-platforms-vertx3).

    Also, I wondered whether you think it is useful to add an additional column indicating whether the respective GAV declares a dependency on the original log4j-core, or whether it re-bundles the vulnerable code. The presence of a classifier may be an approximation, but does not cover all cases (e.g. org.ops4j.pax.logging:pax-logging-log4j2 re-bundles a vulnerable log4j-core version, but does not have a classifier).

    Cheers, Henrik

    opened by henrikplate 3
  • Update VulnerableClassSHAs.csv to not flag 2.17.1 as vulnerable

    Update VulnerableClassSHAs.csv to not flag 2.17.1 as vulnerable

    This MR removes flagging class NetUtils as vulnerable. There were changes in the fix commit for the class, but apparently, since version 2.17.1 those changes have been reverted.

    The MR will fix the false positives as discovered in #16 and #17

    opened by johspaeth 2
  • Are these false positives?

    Are these false positives?

    Analysing lib\lucee-5.3.9.80-SNAPSHOT.jar CVE-2021-44228 found in class file D:\ColdFusion2021\cbhome\lib\lucee-5.3.9.80-SNAPSHOT\bundles\org.lucee.log4j-core-2.17.1\org\apache\logging\log4j\core\util\NetUtils.class

    Analysing lib\runwar-4.7.1-SNAPSHOT.jar CVE-2021-44228 found in class file D:\ColdFusion2021\cbhome\lib\runwar-4.7.1-SNAPSHOT\org\apache\logging\log4j\core\util\NetUtils.class

    Analysing engine\cfml\cli\lucee-server\bundles\org.lucee.log4j-core-2.17.1.jar CVE-2021-44228 found in class file D:\ColdFusion2021\cbhome\engine\cfml\cli\lucee-server\bundles\org.lucee.log4j-core-2.17.1\org\apache\logging\log4j\core\util\NetUtils.class

    opened by murpg 2
  • The process and jar analyse processes give a different result.

    The process and jar analyse processes give a different result.

    We run and older version of exist-db, that we cannot easily update. The log4j-core.2.8.2.jar is flagged to have the vulnerability. However, when we run the processes analysis, then it finds Scanning jar file lib/log4j-1.2.14.jar which does not have the vulnerability. Does that mean the the 2.8.2 version files are not used?

    opened by WillemvdW 2
  • Log4j2 v2.17.0 is detected as affected by CVE-2021-44228

    Log4j2 v2.17.0 is detected as affected by CVE-2021-44228

    After updating log4j2 version from 2.16.0 up to 2.17.0, detector reports that CVE-2021-44228 affected jar.

    CVE-2021-44228 found declared as dependency in .../application-1.0.0/BOOT-INF/lib/log4j-core-2.17.0/org/apache/logging/log4j/core/appender/mom/JmsAppender$Builder.class
    

    On log4j2 security page it is recommended to use 2.17.0 instead of 2.16.0 cause of CVE-2021-45105.

    So the question is - is the 2.17.0 affected by CVE-2021-44228, or it is a detector defect?

    opened by benchdoos 1
  • positive test case fails

    positive test case fails

    A known bad jar is the newrelic java agent 7.4.0 using log4j 2.11.2

    https://download.newrelic.com/newrelic/java-agent/newrelic-agent/7.4.0/

    Analysing newrelic-agent-7.4.0.jar
    Jar file not affected by CVE-2021-44228!
    
    opened by johnv-git 1
Releases(v0.7.3)
Owner
CodeShield GmbH
CodeShield GmbH
Burp Active Scan extension to identify Log4j vulnerabilities CVE-2021-44228 and CVE-2021-45046

Log4j-HammerTime This Burp Suite Active Scanner extension validates exploitation of the Apache Log4j CVE-2021-44228 and CVE-2021-45046 vulnerabilities

DXC Technology - StrikeForce 8 Jan 8, 2022
Log4shell-hunter - Scanner that scans local files for log4shell vulnerability

Log4shell-hunter - Scanner that scans local files for log4shell vulnerability. Does bytecode analysis so it does not rely on metadata. Will find vulnerable log4j even it has been self-compiled/repackaged/shaded/nested (e.g. uberjar, fatjar) and even obfuscated.

Peter Fichtner 5 Feb 27, 2022
log4j2-scan is a single binary command-line tool for CVE-2021-44228 vulnerability scanning and mitigation patch

log4j2-scan is a single binary command-line tool for CVE-2021-44228 vulnerability scanning and mitigation patch. It also supports nested JAR file scan

Logpresso GitHub 839 Dec 29, 2022
A mitigation for CVE-2021-44228 (log4shell) that works by patching the vulnerability at runtime. (Works with any vulnerable java software, tested with java 6 and newer)

Log4jPatcher A Java Agent based mitigation for Log4j2 JNDI exploits. This agent employs 2 patches: Disabling all Lookup conversions (on supported Log4

null 45 Dec 16, 2022
CVE-2021-44228 (Apache Log4j Remote Code ExecutionοΌ‰

CVE-2021-44228 (Apache Log4j Remote Code ExecutionοΌ‰ all log4j-core versions >=2.0-beta9 and <=2.14.1 The version of 1.x has other vulnerabilities, it

Roxas77 10 Apr 23, 2022
Log4Shell sample vulnerable application (CVE-2021-44228)

Log4Shell sample vulnerable application (CVE-2021-44228)

StandB 5 Dec 26, 2021
CVE-2021-44228 (Log4Shell) Proof of Concept

CVE-2021-44228 (Log4Shell) Proof of Concept Apache Log4j2 <=2.14.1 JNDI features used in configuration, log messages, and parameters do not protect ag

Sunnyvale S.r.l. 5 Mar 18, 2022
An LDAP RCE exploit for CVE-2021-44228 Log4Shell

log4j-poc An LDAP RCE exploit for CVE-2021-44228 Log4Shell Description The demo Tomcat 8 server on port 8080 has a vulnerable app (log4shell) deployed

null 60 Dec 10, 2022
PCRE RegEx matching Log4Shell CVE-2021-44228 IOC in your logs

Log4Shell-Rex The following RegEx was written in an attempt to match indicators of a Log4Shell (CVE-2021-44228 and CVE-2021-45046) exploitation. If yo

back2root 286 Nov 9, 2022
Writeup and exploit for installed app to system privilege escalation on Android 12 Beta through CVE-2021-0928

Writeup and exploit for installed app to system privilege escalation on Android 12 Beta through CVE-2021-0928, a `writeToParcel`/`createFromParcel` serialization mismatch in `OutputConfiguration`

null 52 Dec 30, 2022
Contains all my research and content produced regarding the log4shell vulnerability

Objective Contains all my research and content produced regarding the log4shell vulnerability. Content Folder "analysis" Contain the information that

Dominique RIGHETTO 30 Oct 28, 2022
Java bytecode obfuscator with GUI

Bozar A Java bytecode obfuscator with GUI Usage Download the version you want in releases for your platform Run the executable. Done. Let me know if o

null 101 Dec 31, 2022
Burp Active Scan extension to identify Log4j vulnerabilities CVE-2021-44228 and CVE-2021-45046

Log4j-HammerTime This Burp Suite Active Scanner extension validates exploitation of the Apache Log4j CVE-2021-44228 and CVE-2021-45046 vulnerabilities

DXC Technology - StrikeForce 8 Jan 8, 2022
Log4shell-hunter - Scanner that scans local files for log4shell vulnerability

Log4shell-hunter - Scanner that scans local files for log4shell vulnerability. Does bytecode analysis so it does not rely on metadata. Will find vulnerable log4j even it has been self-compiled/repackaged/shaded/nested (e.g. uberjar, fatjar) and even obfuscated.

Peter Fichtner 5 Feb 27, 2022
This project will help to test the Log4j CVE-2021-44228 vulnerability.

Log4j-JNDIServer This project will help to test the Log4j CVE-2021-44228/CVE-2021-45046 vulnerabilities. Installation and Building Load the project on

Immunity, Inc 9 Jun 30, 2022
log4j2-scan is a single binary command-line tool for CVE-2021-44228 vulnerability scanning and mitigation patch

log4j2-scan is a single binary command-line tool for CVE-2021-44228 vulnerability scanning and mitigation patch. It also supports nested JAR file scan

Logpresso GitHub 839 Dec 29, 2022
Vulnerability CVE-2021-44228 checker

CVE-2021-44228 checker This is the repository for checking for vulnerability CVE-2021-44228. This is a PoC that only displays strings without any exte

Yasuhiro Yamada 36 Nov 9, 2022
A mitigation for CVE-2021-44228 (log4shell) that works by patching the vulnerability at runtime. (Works with any vulnerable java software, tested with java 6 and newer)

Log4jPatcher A Java Agent based mitigation for Log4j2 JNDI exploits. This agent employs 2 patches: Disabling all Lookup conversions (on supported Log4

null 45 Dec 16, 2022
Deploys an agent to fix CVE-2021-44228 (Log4j RCE vulnerability) in a running JVM process

-- This repository has been archived -- Further development of this tool will continue at corretto/hotpatch-for-apache-log4j2. Thanks for sharing, com

Volker Simonis 108 Dec 23, 2021