Log4Shell: when writing down a message was enough to give orders
Log4j, a widely used library for writing logs, interpreted certain text instead of just storing it. A well-chosen message could make the server run someone else’s code.
New here? Try the first lesson without an accountCompany or project
Apache Log4j
When
Published: 10 Dec 2021
Reference
CVE-2021-44228
Severity and scale
Critical (CVSS 10)
The story
Almost every program keeps a log: a diary where it writes down what happens, like “Sol logged in at 10:02”. In the Java world, a widely used component for writing that diary is Log4j, from the Apache foundation. In December 2021 it became known that it had an extremely serious flaw, discovered by Chen Zhaojun of the Alibaba Cloud security team. Because Log4j came inside a huge number of products, companies all over the world had to check their systems to find out where it was.
The term, explained simply
Imagine a secretary who writes down everything she is told. One day it turns out that if someone dictates a sentence in a certain special format, she does not write it down: she takes it as an order and goes to fetch instructions wherever she is told. Log4j did something like that with certain text. And Log4j was a dependency: a piece made by others that ships inside your program. That is why the flaw was also in programs that had not chosen it directly: it came inside another component.
The root cause
Log4j interpreted parts of the text it logged. If that text came from outside, like a username or a header, whoever wrote it could make the library load and run code from an external server. A piece of data turned into an instruction.
What could happen
Remote code execution: the attacker could run their own programs on the server, with the application’s permissions. NVD gave it the maximum score, 10 out of 10, and CISA added it to its catalog of exploited vulnerabilities on the same day it was published.
How it was fixed and how to prevent it
Apache disabled that behavior by default in version 2.15.0 and removed it completely in 2.16.0; more fixes followed, so the recommendation is to use the latest version. To prevent it: keep an inventory of dependencies, that is, a list of every component inside each program; update quickly; always treat logged text as data; and limit which network destinations a server can connect to.
Sources
Official documents and the researcher’s own write-up. We tell the story, the concept and the defense; there are no steps to repeat the attack.
