Apache Log4j Remote Code Execution (Log4Shell)

An application uses an Apache Log4j 2 version whose message lookups let anyone who can get text logged run code on the server (Log4Shell).

SeverityCritical
CVSS 3.110 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H Open in the calculator
CVSS 4.09.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-917: Improper Neutralization of Special Elements used in an Expression Language Statement ('Expression Language Injection')
OWASP Top 10A05:2025 Injection
MITRE ATT&CKT1190 Exploit Public-Facing Application, T1210 Exploitation of Remote Services
CVECVE-2021-44228, CVE-2021-45046
CategoryOutdated Components

Description

The application uses a version of the Apache Log4j 2 logging library (log4j-core) that is vulnerable to CVE-2021-44228, known as Log4Shell. Vulnerable versions evaluate lookup expressions found in logged data, including the jndi lookup. If attacker-supplied text that the application logs, such as a username, a search term or the User-Agent header, contains an expression beginning ${jndi:ldap:// followed by the address of a server the attacker controls, Log4j connects to that server, which can return a reference that makes the application load and run attacker-supplied Java code. The first fix was incomplete in certain non-default configurations, which was tracked as CVE-2021-45046.

An unauthenticated attacker who can get a string logged by a vulnerable application can therefore typically run arbitrary code on the server with the privileges of the application, gaining full control of its data and a foothold in the hosting environment. Where the Java runtime blocks remote class loading, exploitation relies on classes already present in the application, which is often still possible, and even where code execution is blocked, a lookup can leak environment variables, such as cloud credentials, through the DNS request. Exploitation needs only a single request and was automated by attackers within hours of disclosure; Log4Shell is listed in CISA's Known Exploited Vulnerabilities (KEV) catalogue and has been used to deploy ransomware, cryptocurrency miners and backdoors.

The vulnerability can be confirmed actively by placing a JNDI expression that points at a server the tester controls into headers, parameters and other inputs and watching for the resulting DNS or LDAP callback, which also reveals vulnerable systems further along the processing chain, such as log processors that handle the data later: internal systems that log data originating from the internet are as exposed as internet-facing ones. It can be found passively by searching file systems for log4j-core JAR files, including copies nested inside WAR, EAR and fat JAR files, and through software composition analysis. Log4j is embedded in a very large number of commercial and open-source products, so vendor advisories must also be checked. The older, end-of-life Log4j 1.x branch is not affected by this flaw but has unfixed vulnerabilities of its own.

Remediation

Remove vulnerable Log4j 2 versions from every application:

  • Upgrade log4j-core to a release that the Apache Log4j security page lists as fixing both CVE-2021-44228 and CVE-2021-45046 for the Java version in use, rebuild and redeploy the application, and replace copies shaded or nested inside other archives.
  • For commercial and open-source products that embed Log4j, apply the vendor's fixed release or documented mitigation.
  • Where an upgrade cannot be made immediately, remove the JndiLookup class from the log4j-core JAR as an interim measure, as shown below. Setting log4j2.formatMsgNoLookups was found not to protect every configuration and should not be relied on.
  • Restrict outbound connections from servers to the internet, which blocks the LDAP and RMI callbacks that exploitation needs, and monitor DNS and proxy logs for jndi lookups.
  • Treat internet-facing systems that were vulnerable for any period as potentially compromised: review them for web shells, unexpected accounts and outbound connections, and rotate the credentials they held.
zip -q -d log4j-core-*.jar org/apache/logging/log4j/core/lookup/JndiLookup.class

Confirm the fix by rescanning file systems for vulnerable log4j-core versions and repeating the callback test against every input that was affected.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Patching and Outdated Software Findings

Every Patching and Outdated Software finding