GithubHelp home page GithubHelp logo

zyanfx / safedeserializationhelpers Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 7.0 1.94 MB

:japanese_ogre: Fixes known BinaryFormatter deserialization vulnerabilities

Home Page: https://www.nuget.org/packages/Zyan.SafeDeserializationHelpers/

License: MIT License

C# 99.90% Batchfile 0.10%
serialization deserialization exploit vulnerability gadget security dotnet csharp binaryformatter

safedeserializationhelpers's Introduction

Zyan.SafeDeserializationHelpers

This tiny library tries to fix several known BinaryFormatter vulnerabilities. When a malicious payload is detected, the library throws an UnsafeDeserializationException instead of deserializing the data that is able to produce bad side effects.

GitQ appveyor tests nuget

Deserializing the untrusted data is dangerous

It's proven that deserialing arbitrary payloads under certain conditions can trigger code execution. BinaryFormatter, DataContractSerializer, XmlSerializer, as well as several widely used JSON serializers are known to be vulnerable.

See ysoserial.net project for details.

Code sample

// unsafe: deserialization can trigger arbitrary code execution
var fmt = new BinaryFormatter();
var object = fmt.Deserialize(stream);

// safe: deserialization is guarded against known vulnerabilities
var fmt = new BinaryFormatter().Safe();
var object = fmt.Deserialize(stream);

Usage

  1. Install Zyan.SafeDeserializationHelpers nuget package.
  2. Use new BinaryFormatter().Safe() instead of just new BinaryFormatter().
  3. For .NET Remoting projects, use safe versions of the binary formatter sinks:
    • Replace BinaryClientFormatterSinkProvider with SafeBinaryClientFormatterSinkProvider.
    • Replace BinaryServerFormatterSinkProvider with SafeBinaryServerFormatterSinkProvider.
  4. Make sure to test your project against payloads produced by ysoserial.net gadgets.

Known vulnerabilities supported by the library

  • ActivitySurrogateSelector gadget by James Forshaw (loads an assembly and executes arbitrary code).
  • PSObject gadget by Oleksandr Mirosh and Alvaro Munoz. Target must run a system not patched for CVE-2017-8565.
  • TypeConfuseDelegate gadget by James Forshaw (runs any process using Process.Start delegate).
  • DataSet gadget by James Forshaw (unsafe BinaryFormatter deserialization).
  • WindowsIdentity gadget by Levi Broderick (unsafe BinaryFormatter deserialization).

References

Thanks

License

MIT License.

safedeserializationhelpers's People

Contributors

yallie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

safedeserializationhelpers's Issues

Support for .NET Standard

Hi yallie,

is is possible/necessary to target the project to .NET Standard 2.0 or is the standard framework safe?

Many greetings
heikar

.NET 2.0 target

Let's try retargeting for .NET 2.0 instead of the current .NET 3.5.
.NET 2.0 is needed for the Genuine Channels project.

Replace custom exception with SecurityException

Custom exception requires Zyan.SafeDeserializationHelpers assembly to be deserialized. When the assembly is absent on the client side, the exception cannot be deserialized and is replaced with SerializationException which is kinda confusing.

Throwing a generic SecurityException instead of the custom UnsafeDeserializationException looks like a good compromise to me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.