07-09-25, 09:03 PM
PoC from hawktrace - https://hawktrace.com/blog/cve-2025-53772
public static object Deserialize(string str, out Exception handledException) {
handledException = null;
BinaryFormatter binaryFormatter = new BinaryFormatter(); // [1]
byte[] array = Convert.FromBase64String(str); // [2]
object obj;
try {
obj = Base64EncodingHelper.DeserializeHelper(binaryFormatter, array);
} catch (SerializationException ex) {
handledException = ex;
binaryFormatter.Binder = new Base64EncodingHelper.HandleMissingExceptionTypesSerializationBinder();
obj = Base64EncodingHelper.DeserializeHelper(binaryFormatter, array);
}
return obj;
}
private static object DeserializeHelper(BinaryFormatter formatter, byte[] buffer) {
object obj;
using (MemoryStream memoryStream = new MemoryStream(buffer)) {
using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) { // [3]
obj = formatter.Deserialize(gzipStream); // [4]
}
}
return obj;
}
public static object Deserialize(string str, out Exception handledException) {
handledException = null;
BinaryFormatter binaryFormatter = new BinaryFormatter(); // [1]
byte[] array = Convert.FromBase64String(str); // [2]
object obj;
try {
obj = Base64EncodingHelper.DeserializeHelper(binaryFormatter, array);
} catch (SerializationException ex) {
handledException = ex;
binaryFormatter.Binder = new Base64EncodingHelper.HandleMissingExceptionTypesSerializationBinder();
obj = Base64EncodingHelper.DeserializeHelper(binaryFormatter, array);
}
return obj;
}
private static object DeserializeHelper(BinaryFormatter formatter, byte[] buffer) {
object obj;
using (MemoryStream memoryStream = new MemoryStream(buffer)) {
using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) { // [3]
obj = formatter.Deserialize(gzipStream); // [4]
}
}
return obj;
}
