# .NET Deserialization > Insecure use of .NET formatters (`BinaryFormatter`, `LosFormatter`, `ObjectStateFormatter`, `NetDataContractSerializer`, `SoapFormatter`) and type-binding JSON/XML serializers (Json.NET with `TypeNameHandling`, `JavaScriptSerializer`, FastJSON) on attacker data, where the payload names the type to instantiate and setter/callback logic runs during reconstruction. ## How it works - **BinaryFormatter is unsafe by design.** Microsoft's own guidance states it "is insecure and can't be made secure," and calling `Deserialize` on a payload is "the equivalent of interpreting that payload as a standalone executable." A `SerializationBinder` is insufficient. From .NET 9 the in-box implementation throws on use. - **Type discriminators are the root cause for JSON/XML.** Json.NET with `TypeNameHandling` other than `None`, `JavaScriptSerializer` with a type resolver, and similar settings let the payload's `$type`/`__type` field pick a .NET class to construct; setters and type converters then run. The Black Hat "Friday the 13th JSON Attacks" research generalised this: format (binary/XML/JSON) is irrelevant as long as the library invokes methods on user-named types and a gadget space exists. - **Magic bytes.** `BinaryFormatter`/`LosFormatter` base64 commonly begins `AAEAAAD/////`; ASP.NET ViewState begins `/wE`. `ysoserial.net` and Mandiant's `heyserial` are the reference payload/detection tooling. ## ASP.NET ViewState `_VIEWSTATE` is serialized state round-tripped through a hidden field (serialized by `LosFormatter`, deserialized by `ObjectStateFormatter`, which uses `BinaryFormatter` internally plus type converters). Its integrity rests on the server's `machineKey` (validation/decryption keys). Exploitability hinges on key secrecy and MAC configuration: - A leaked or sample `machineKey` (in `web.config`, deployment guides, or disk via file-read) turns ViewState into an attacker-signable deserialization sink. - Pre-.NET-4.5, `ViewStateEncryptionMode=Always` only checked for the presence of `__VIEWSTATEENCRYPTED`; .NET ≥4.5 binds target-framework behaviour. Treat a leaked `machineKey` as equivalent to a deserialization RCE. See [[Insecure Deserialization]]. ## Notable cases | CVE / ID | Target | Note | |---|---|---| | CVE-2025-53690 | Sitecore | ViewState RCE via a **sample `machineKey`** published in 2017 deployment guides; in-the-wild, WEEPSTEEL recon (Mandiant) | | CVE-2025-53770 "ToolShell" | SharePoint on-prem | Unauth; webshell parsing ViewState payloads; mass-exploited, chained with Ivanti EPMM bugs | | CVE-2025-59287 | WSUS | Unauth `SoapUtilities.DeserializeObject` in `ReportingEvent.Validate`, port 8530/8531; in-the-wild, `w3wp.exe`→`whoami.exe` | | CVE-2026-28326 | SolarWinds ARM | Hardcoded static client-auth secret → .NET deserialization over gRPC on TCP 55555; RCE as SYSTEM | | CVE-2025-34153 | Hyland OnBase | `BinaryFormatter` over .NET Timer Service TCP 6031 | | CVE-2025-5086 | DELMIA Apriso | `NetDataContractSerializer` in a WCF service; in-the-wild (CISA KEV) | | CVE-2025-55182 "React2Shell" | React 19 / Next.js RSC | Unsafe deserialization in the RSC "Flight" protocol; CVSS 10.0, default configs | Also: Telerik UI for ASP.NET AJAX padding-oracle→deserialization (and Telerik Reporting / UI for WPF), RBH Integra32 and Quest Foglight unauth .NET Remoting, Visual Studio PDB handling (CVE-2026-114151), SharePoint DataSet/DataTable (CVE-2020-1147), and the `.NET`/`C#` type-binding JSON cases from Black Hat. ## Prevention - Stop using `BinaryFormatter`, `LosFormatter`, `ObjectStateFormatter`, `NetDataContractSerializer`, `SoapFormatter` on untrusted data; prefer `XmlSerializer`/`DataContractSerializer`/`System.Text.Json` with concrete expected types. - Json.NET: keep `TypeNameHandling = None`; if type info is required, use a strict `SerializationBinder` allowlist. - ViewState: keep `machineKey` secret and unique per deployment (never a sample key), enable MAC, and rotate keys after any suspected disclosure. Restrict management ports (gRPC 55555, Timer 6031, Remoting 2001) to their own components. ## Related - [[Insecure Deserialization]] - [[Polymorphic Deserialization]] - [[Gadget Chains]] - [[Remote Code Execution]] ## Sources - [[raw/github.com/net-deserialization-cheat-sheet-3806|.NET Deserialization Cheat Sheet]] - [[raw/learn.microsoft.com/binaryformatter-deserialization-security-guide-for-net-3807|BinaryFormatter Deserialization Security Guide for .NET]] - [[raw/github.com/payloadsallthethings-insecure-deserialization-dotnet-4512|PayloadsAllTheThings: Insecure Deserialization DotNET]] - [[raw/github.com/ysoserial-net-deserialization-payload-generator-for-net-3797|ysoserial.net: Deserialization Payload Generator for .NET]] - [[raw/invicti.com/net-json-net-deserialization-rce-3809|.NET JSON.NET Deserialization RCE]] - [[raw/swapneildash.medium.com/deep-dive-into-net-viewstate-deserialization-4354|Deep Dive into .NET ViewState Deserialization]] - [[raw/cloud.google.com/viewstate-deserialization-zero-day-in-sitecore-cve-2025-53690-4355|ViewState Deserialization Zero-Day in Sitecore (CVE-2025-53690)]] - [[raw/blog.checkpoint.com/sharepoint-zero-day-cve-2025-53770-actively-exploited-3783|SharePoint Zero-Day CVE-2025-53770 Actively Exploited]] - [[raw/research.eye.security/wsus-deserialization-exploit-in-the-wild-cve-2025-59287-4948|WSUS Deserialization Exploit in the Wild (CVE-2025-59287)]] - [[raw/bishopfox.com/master-key-included-detecting-solarwinds-arm-cve-2026-28326-12127|Master Key Included: SolarWinds ARM CVE-2026-28326]] - [[raw/sentinelone.com/cve-2025-34153-hyland-onbase-rce-via-deserialization-3048|CVE-2025-34153: Hyland OnBase RCE via Deserialization]] - [[raw/tantosec.com/from-padding-oracle-to-shell-unauthenticated-rce-in-telerik-ui-for-asp-11968|From Padding Oracle to Shell: Telerik UI for ASP.NET AJAX]]