githubEdit

.NET Deserialization

Theory

Insecure deserialization is a vulnerability that can affect applications built using the .NET framework. They occurs when the deserialization process is not properly secured and validated, allowing attackers to exploit it and execute arbitrary code or perform other malicious activities.

Practice

JSON.NET Deserialization

In .NET application that uses JSON.net (Newtonsoft library), we can inject arbitrary code or read local files by abusing JSON deserialization objects.

To decompile a .NET application you can use dnSpyarrow-up-right on windows or AvaloniaILSpyarrow-up-right on Linux

If the application have the TypeNameHandlingarrow-up-right not being set to None and deserialize a parameter without proper validation, it is vulnerable.

json = JsonConvert.DeserializeObject<Example>(json);We can give the Json value to the “JsonConvert.DeserializeObject(json)” with a reserved key ($type).
The format is as follow. The value of $type is a string that contains the assembly-qualified name of the .NET type to be deserialized.
circle-info

In the previous code, Example is the class to what json data will be converted (deserialized)

References

Last updated