Skip to content
Write-up Intermediate

Exploiting JSON serialization in .NET core

When Newtonsoft JSON is configured with TypeNameHandling other than None and deserialises into object or a base type, the $type property lets an attacker choose which .NET type gets instantiated. The author shows payloads that can change file attributes, rename a drive and, in WPF apps only, start a process.

Jeroen Verhaeghe Follow

Published on systemweakness.com

Applications written in .net core can be vulnerable to JSON deserialization attacks. There has been some research on exploiting this in the full .net framework but not much on exploiting this in .net core.

Jeroen Verhaeghe, on systemweakness.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 deserialiser is configured to honour type names supplied in the JSON and deserialises into a generic or base type, so attacker-chosen types are instantiated.

Impact

An attacker could change file attributes, rename a drive (with admin rights) and, in WPF applications only, run a command; the command payload fails against a .NET Core web application.

What the attacker needed

TypeNameHandling set to a non-None value; JSON deserialised into object or a base type; attacker can send JSON to the endpoint

The fix

It should be fixed by leaving TypeNameHandling at None and deserialising into a specific type rather than object.

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.

JSON is a text format for data. Some .NET JSON libraries can be told to record the class name of an object in a special $type field, and to recreate that exact class when reading the JSON back. If an app trusts that field, a user can name any class they like, and some classes do things like touch files when they are created.

Similar reports

Same bug class and techniques, clearest first.