Skip to content
RCE Write-up Advanced

Apache: Code execution in log4j2

The patch in Log4j 2.15.0 for the JNDI RCE had three bypasses: a javaClassName check that did not verify the deserialized data, a localhost restriction that could be bypassed via URI fragment canonicalisation, and a time-of-check/time-of-use flaw in LDAP attribute validation. An attacker who can inject a JNDI lookup could achieve remote code execution in some environments.

github.com

Published on github.com

sirdarckcat published GHSA-ggmf-hg75-88gg Feb 14, 2022

The author, on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the patch in 2.15.0 introduced incomplete validation: it checked the class name but not the deserialized bytes, used URI.getHost() for validation but connected to the full string, and performed a separate LDAP lookup for validation that could return different attributes than the actual lookup.

Impact

Remote code execution is possible in some environments with specific configurations, but only if the attacker can inject a JNDI lookup and, for the deserialization bypass, a suitable gadget chain is present.

What the attacker needed

Attacker can inject a JNDI lookup value; specific configurations (e.g., certain OS/resolver); for deserialization: gadget chain on classpath

The fix

Log4j 2.17.0 removed support for LDAP from the JNDI allowed protocols list, which fixed these issues.

How it was found

  1. Inject a JNDI lookup value via a Pattern Layout containing a context Lookup.
  2. Set up a malicious LDAP server that returns a response bypassing the 2.15.0 checks.
  3. Trigger the lookup; Log4j deserializes attacker-controlled data or connects to an unintended host.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Log4j is a logging library. It had a feature that could fetch data from remote servers. Attackers could abuse this to run their own code. The first fix was incomplete, and this report shows three ways around it.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.