Last active
December 10, 2021 09:25
-
-
Save LXGaming/77968d304561bd52dfa31c4d9431f8fb to your computer and use it in GitHub Desktop.
ASM Patch for log4j exploit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2021 Alex Thomson | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package io.github.lxgaming.license.agent.mixin.log4j.core.pattern; | |
import io.github.lxgaming.license.agent.mixin.Mixin; | |
import org.objectweb.asm.Opcodes; | |
import org.objectweb.asm.tree.ClassNode; | |
import org.objectweb.asm.tree.FieldInsnNode; | |
import org.objectweb.asm.tree.InsnList; | |
import org.objectweb.asm.tree.LdcInsnNode; | |
import org.objectweb.asm.tree.MethodNode; | |
import org.objectweb.asm.tree.VarInsnNode; | |
public class MessagePatternConverterMixin extends Mixin { | |
@Override | |
public boolean prepare() { | |
putClass("org/apache/logging/log4j/core/pattern/MessagePatternConverter", true); | |
return true; | |
} | |
@Override | |
protected boolean handle(ClassLoader classLoader, ClassNode classNode, MethodNode methodNode) { | |
if (methodNode.name.equals("<init>")) { | |
InsnList insnList = new InsnList(); | |
insnList.add(new VarInsnNode( | |
Opcodes.ALOAD, | |
0 | |
)); | |
insnList.add(new LdcInsnNode( | |
true | |
)); | |
insnList.add(new FieldInsnNode( | |
Opcodes.PUTFIELD, | |
"org/apache/logging/log4j/core/pattern/MessagePatternConverter", | |
"noLookups", | |
"Z" | |
)); | |
methodNode.instructions.insertBefore(methodNode.instructions.getLast(), insnList); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment