You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains a tool to detect if a jar file is affected by the critical CVE-2021-44228. The tool does not need to execute the jar file, but will compare against a set of vulnerable hashes for classes within the jar file.
1
+
This repository contains a tool to detect 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](https://mvnrepository.com/repos/central).
2
+
3
+
# How to run this tool
4
+
5
+
1. Download the jar file under releases. TODO add link.
6
+
2. Run `java -cp <PATH_TO_DOWNLOADED_JAR> de.codeshield.log4jcheck.Log4JDetector <PATH_TO_`
7
+
8
+
9
+
If the jar is affected, the tool outputs information to the command-line:
10
+
11
+
```
12
+
CVE-2021-44228 found declared as dependency in META-INF/maven/org.apache.logging.log4j/log4j-core/pom.xml
13
+
CVE-2021-44228 found in class file org/apache/logging/log4j/core/net/JndiManager$1.class
14
+
```
2
15
3
16
# Background on CVE-2021-44228
4
-
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. [References](https://thehackernews.com/2021/12/extremely-critical-log4j-vulnerability.html).
17
+
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.
Log4j is and has been used in mostly any Java project for logging purporse. 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 if one is affected can be done using using the maven dependecy tree:
24
+
# Why is it so important?
25
+
Log4j is and has been used in mostly any Java project for logging purporse. 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 if one is affected can be done using using the maven dependecy tree:
8
26
9
27
Example: Execute command `mvn dependency:tree` on a maven project.
10
28
@@ -14,34 +32,48 @@ Example: Execute command `mvn dependency:tree` on a maven project.
This check however, is not sufficient. Java programs are frequently:
18
-
* packaged as fatjar or uberjar: All class files (including direct and transitive dependencies) are shipped as a single jar file.
19
-
* re-packaged: the originaly package names are changes as of conflicts (this can be done automatically by the compiler)
20
-
* rebundled: ...?
21
-
* re-compiled: The source code is re-compiled and packaged anew.
35
+
This check however, is only a first indication and does not suffices due to the following reasons.
36
+
37
+
Java programs are frequently:
38
+
* 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)
39
+
* re-packaged or rebundled: the originaly package names are changed to avoid naming conflicts (some compilers and package mechanism apply code transformations)
40
+
* re-compiled: The source code is compiled with a different compiler and packaged anew, this leads to modified bytecode
41
+
42
+
Consquently, _*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.
22
43
23
-
Purely using SHA hashes on the class file level, does not suffice to detect is a library ships with log4j. Therefore, an indepth bytecode inspection is necessary. This is what has been done as part of this project.
44
+
45
+
# How the script works
46
+
1. Extract pom.xml files from .jar
47
+
2. check declared dependencies against a [pre-computed list](src/main/resources/VulnerableGavs.csv) of affected groupId:artifactId:version list for artifacts hosten on Maven Central
48
+
3. Extract .class files from .jar
49
+
6. Compute SHA hashes of the class file
50
+
7. Match SHAs against a [pre-computed list](src/main/resources/VulnerableClassSHAs.csv)
51
+
52
+
# Build Instructions
53
+
54
+
To build this tool run
55
+
56
+
`mvn compile`
24
57
25
58
# Precomputed Hashes of Vulnerable Classes
26
59
27
-
The set of vulnerable hashes for classes has been pre-compute on [Maven Central](https://mvnrepository.com/repos/central) repository. The hashes of the classes do not only contain hashes of the affected files directly vulnerable jars, i.e., log4j in version range [2.0-beta9, 2.14), but also the following artifacts, but also :
60
+
The set of vulnerable hashes for classes has been pre-compute on entire [Maven Central](https://mvnrepository.com/repos/central) repository. The hashes of the classes contain all hashes that we identified as bytecode-similiar using the Fingerprinting technology.
61
+
62
+
The pre-computed information contains:
28
63
29
64
* all aritfacts that directly include log4j in any of the vulnerable version
30
65
* all artifacts that ship a class that contains a vulnerable hash of log4j in the affected version range
31
66
* all artifacts that rebundle a vulnerable class of log4j
32
-
* all artifacts that have a re-compiled class of a class of log4j w in the affected version range
33
-
34
-
Details on how this information has been computed, see section on [Fingerprinting Technology](#fingerprinting-technology).
67
+
* all artifacts that have a re-compiled class of a class of log4j in the affected version range
35
68
36
-
# How the script works
37
-
1. Extract .class files from .jar file
38
-
2. Computes SHA hashes of the class file
39
-
3. Match SHA hashes against SHA hashes in our [pre-computed database]() #TODO add link to file.
69
+
As affected version range we considered [2.0-beta9, 2.14) [Reference](https://logging.apache.org/log4j/2.x/security.html).
40
70
41
71
# Fingerprinting Technology
42
72
This tool uses a new bytecode fingerprinting technology for Java that has been invented by Andreas Dann. The basic flow is as follows.
43
73
1. Use the available fix commits [Commit1](https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=7fe72d6), [Commit2](https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=d82b47c), and [Commit3](https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=c77b3cb) to identify which classes are affected.
44
-
2. Compute bytecode hashes of the vulnerable classes.
45
-
3. Search for other classes on MavenCentral that also contain similar hashes.
74
+
2. Compute bytecode hashes using the Fingerprinting technologites of the vulnerable classes.
75
+
3. Search for other classes on MavenCentral whose fingerprint match.
46
76
47
77
Details on the technology are found in the paper [SootDiff](https://dl.acm.org/doi/10.1145/3315568.3329966).
78
+
79
+
*Note: This repository does only ship SHA hashes of the vulnerable classes and does not compute the Fingerprint on your jar*
0 commit comments