
ClassLoader 및 Reflect API를 통해 원격으로 Java 바이트코드를 로드하고 실행하며, ChaCha20 암호화 및 keepalive 연결을 지원하는 클라이언트-서버 도구
이 도구는 Java 바이트코드를 클래스 파일 형태로 클라이언트(또는 잠재적 대상)에게 전송하여, Java ClassLoader와 Reflect API를 함께 사용해 로드 및 실행할 수 있게 해줍니다. 클라이언트는 서버로부터 클래스 파일을 수신하고, 각 실행 결과를 반환합니다. 페이로드는 Java로 작성되어야 하며, 서버를 시작하기 전에 컴파일되어야 합니다.
이 도구는 OpenJDK 11과 JRE Java 패키지를 사용하여 Windows와 Linux (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