Skip to content
RCE Write-up Advanced

Bypassing .NET Serialization Binders

The blog post explains that .NET serialization binders used to validate types during deserialization can be bypassed when a custom binder returns null on failure, because the BinaryFormatter then falls back to its own type resolution. It shows two real cases, DevExpress and Microsoft Exchange, where this flaw allowed remote code execution.

Markus Wulftange Follow

Published on codewhitesec.blogspot.com

Serialization binders are often used to validate types specified in the serialized data to prevent the deserialization of dangerous types that can have malicious side effects with the runtime serializers such as the BinaryFormatter.

Markus Wulftange, on codewhitesec.blogspot.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the custom binder validated the raw type and assembly strings and returned null on failure, so the BinaryFormatter fell back to its own FastBindToType resolution, which parsed the same strings differently and still loaded the dangerous type.

Impact

Both the DevExpress framework and Microsoft Exchange could be exploited for remote code execution through this binder bypass.

What the attacker needed

Ability to send serialized data to the target; target uses BinaryFormatter with a custom binder

The fix

Custom binders should throw on unexpected types rather than return null, and should resolve and validate the type the same way the runtime does.

How it was found

  1. Set the assembly name and full type name explicitly in the serialized object's data instead of using SetType.
  2. Use the assembly-qualified name of the dangerous type as the type name so the string-based unsafe list does not match.
  3. Serialize the object and send it to the target so the binder is invoked during deserialization.
  4. Observe that the custom binder fails to resolve the type and returns null.
  5. Observe that the fallback binder resolves the type from the embedded assembly-qualified name and the object is created.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When .NET reads serialized data it can be told to create objects of a chosen type, and some of those types can run dangerous code. A serialization binder is a guard that checks the type name before the object is created. If the guard gives up quietly instead of raising an error, the underlying reader may still load the type on its own, so the check is skipped.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Markus Wulftange

View all

11 more disclosed reports, best first.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.