Skip to content

Commit 7881649

Browse files
committed
Patch CVE-2021-45105 too
1 parent 8e26058 commit 7881649

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ This program can be used as wrapper for another jar file:
1717
- (Cancel malicious `ChatEvent` on BungeeCord)
1818
- Using [SpigotLog4j2Fix](https://github.com/AzisabaNetwork/SpigotLog4j2Fix) on Spigot/Paper
1919
- Cancel outbound packet that contains malicious string
20-
- Or alternatively, you can upgrade log4j2 to `2.15.0`.
20+
- Or alternatively, you can upgrade log4j2 to `2.17.0`.

pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.azisaba</groupId>
88
<artifactId>Log4j2Fix</artifactId>
9-
<version>1.0.4</version>
9+
<version>1.0.5</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>
@@ -43,6 +43,7 @@
4343
<manifestEntries>
4444
<Main-Class>net.azisaba.log4j2Fix.Log4j2Fix</Main-Class>
4545
<Premain-Class>net.azisaba.log4j2Fix.Log4j2Fix</Premain-Class>
46+
<Agent-Class>net.azisaba.log4j2Fix.Log4j2Fix</Agent-Class>
4647
</manifestEntries>
4748
</archive>
4849
</configuration>
@@ -61,11 +62,15 @@
6162
<artifactId>native-util</artifactId>
6263
<version>1.2.6</version>
6364
</dependency>
65+
<dependency>
66+
<groupId>org.apache.logging.log4j</groupId>
67+
<artifactId>log4j-api</artifactId>
68+
<version>2.17.0</version>
69+
</dependency>
6470
<dependency>
6571
<groupId>org.apache.logging.log4j</groupId>
6672
<artifactId>log4j-core</artifactId>
67-
<version>2.14.1</version>
68-
<scope>provided</scope>
73+
<version>2.17.0</version>
6974
</dependency>
7075
</dependencies>
7176
</project>

src/main/java/net/azisaba/log4j2Fix/Log4j2Fix.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,30 @@ public static void transformClasses(boolean b) throws IOException {
101101
registered = true;
102102
NativeUtil.registerClassLoadHook((classLoader, s, aClass, protectionDomain, bytes) -> {
103103
if ("org/apache/logging/log4j/core/lookup/JndiLookup".equals(s) || s.startsWith("org/apache/logging/log4j/core/lookup/JndiLookup$")) {
104+
System.out.println("Blocked loading class " + s);
104105
sneakyThrow(new ClassNotFoundException());
105106
}
106107
return null;
107108
});
109+
110+
// log4j-api
111+
transformClass("org.apache.logging.log4j.spi.AbstractLogger", false);
112+
113+
// log4j-core
114+
transformClass("org.apache.logging.log4j.core.config.Configuration", false);
115+
transformClass("org.apache.logging.log4j.core.config.ConfigurationFactory", false);
116+
transformClass("org.apache.logging.log4j.core.config.composite.CompositeConfiguration", false);
117+
transformClass("org.apache.logging.log4j.core.config.json.JsonConfiguration", false);
118+
transformClass("org.apache.logging.log4j.core.config.plugins.util.PluginBuilder", false);
119+
transformClass("org.apache.logging.log4j.core.config.xml.XmlConfiguration", false);
120+
transformClass("org.apache.logging.log4j.core.lookup.ConfigurationStrSubstitutor", true);
121+
transformClass("org.apache.logging.log4j.core.lookup.ContextMapLookup", false);
122+
transformClass("org.apache.logging.log4j.core.lookup.DateLookup", false);
123+
transformClass("org.apache.logging.log4j.core.lookup.EventLookup", false);
124+
transformClass("org.apache.logging.log4j.core.lookup.RuntimeStrSubstitutor", true);
125+
transformClass("org.apache.logging.log4j.core.lookup.StrSubstitutor", true);
126+
127+
// Restores ReflectionUtil
108128
if (b || Boolean.getBoolean("log4j2Fix.loadReflectionUtil")) {
109129
transformClass("org.apache.logging.log4j.util.ReflectionUtil", true);
110130
transformClass("org.apache.logging.log4j.util.ReflectionUtil$PrivateSecurityManager", true);
@@ -116,7 +136,14 @@ public static void transformClass(String className, boolean loadNow) throws IOEx
116136
if (clazz == null) {
117137
String path = "/classes/" + className.replace('.', '/') + ".class";
118138
InputStream in = Log4j2Fix.class.getResourceAsStream(path);
119-
if (in == null) throw new RuntimeException("Could not find '" + path + "' in jar file");
139+
if (in == null) {
140+
path = "/" + className.replace('.', '/') + ".class";
141+
in = Log4j2Fix.class.getResourceAsStream(path);
142+
}
143+
if (in == null) {
144+
System.err.println("Could not find '" + path + "' in jar file");
145+
return;
146+
}
120147
byte[] newClassBytes = readAllBytes(in);
121148
if (loadNow) {
122149
System.out.println("Loading class " + className + " from " + path);

0 commit comments

Comments
 (0)