Log4Shell revisited: how one log line took over a server
RAIJIN Security Research · Analysis Draft, to be checked again before launch
In December 2021, a vulnerability was disclosed in Log4j 2, a Java logging library. It was assigned CVE-2021-44228 with a CVSS score of 10.0. An attacker only had to get a server to write a specific string into its log to run arbitrary code on that server.
How the vulnerability works
When writing a log entry, Log4j 2 interprets strings of the form ${…} inside the message. One such form is a JNDI lookup, where Log4j connects to the address given in the string.
The attacker places such a string in a field that gets logged, for example the User-Agent header. While writing the log, the server connects to the attacker's server, then loads and runs the code it provides.
Why the impact was so large
Log4j is one of the most widely used logging libraries in the Java ecosystem, and many products bundle it. Many teams did not even know their systems were using it.
The attack needs no login, only a single HTTP request. Soon after disclosure, large-scale scanning and attacks appeared across the internet.
What to do
The real fix is to upgrade Log4j 2 to a patched version. When an upgrade cannot happen right away, a WAF can first block requests containing JNDI lookup strings.
Attackers use nested expressions and encoding to slip past keyword matching. So a WAF has to restore the string to its original form before judging whether it is a JNDI lookup.
What it taught us
First, know which components your systems use. Second, patching takes time, so you need something like a WAF that can block attacks in the meantime.