Study Notes of using dnx.exe & rcsi.exe to bypass Decvice Guard UMCI

发布于 2025-02-01 05:55:04 字数 10573 浏览 7 评论 0

0x00 前言

在 Windows 10 Enterprise 和 Server 2016 引入的新功能 Decvice Guard 是一种白名单机制,可用来阻止未授权的代码执行。

简单的理解,只要是不包含微软数字签名的程序,均无法用来执行代码。

然而,如果能够找到带有微软签名的程序,那么就能绕过 Decvice Guard 对应用程序的拦截,实现代码执行。

目前已知的方法有:

1、WinDbg/CDB

可用来执行 shell code

作者:Matt Graeber@mattifestation

地址: http://www.exploit-monday.com/2016/08/windbg-cdb-shellcode-runner.html

2、CSI.exe

可用来执行 c# 代码

作者:Casey Smith@subTee

地址: https://twitter.com/subTee/status/796737674954608641

3、dnx.exe

可用来执行 c#代码

作者:Matt Nelson@enigma0x3

地址: https://enigma0x3.net/2016/11/17/bypassing-application-whitelisting-by-using-dnx-exe/

4、rcsi.exe

可用来执行 c#代码

作者:Matt Nelson@enigma0x3

地址: https://enigma0x3.net/2016/11/21/bypassing-application-whitelisting-by-using-rcsi-exe/

0x01 简介

Matt Nelson@enigma0x3 在最近分享了他绕过 Decvice Guard 的两种方法,这是继 Matt Graeber@mattifestation 和 Casey Smith@subTee 后的第三和第四种绕过方法,本文将重现这两个过程,完成他留给读者的两个作业,优化 dnx.exe 的环境搭建步骤,分享学习心得。

链接如下:

0x02 dnx.exe

dnx.exe 内置于.NET Execution environment,包含数字签名,可用来执行 c#代码

首先搭建 dnx.exe 的使用环境

参考资料:https://blogs.msdn.microsoft.com/sujitdmello/2015/04/23/step-by-step-installation-instructions-for-getting-dnx-on-your-windows-machine/

资料显示需要 powershell v4.0 和安装 Visual C++ 2013 redistributable package,实际测试"print helloworld"并不需要这些条件,同时配置步骤也可以简化,以下为简化的配置步骤:

测试系统:Win8 x86

1、下载并安装 Microsoft .NET Framework 4.5.2:

下载地址:https://www.microsoft.com/zh-CN/download/confirmation.aspx?id=42643

2、安装 DNVM

cmd:

powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='’'dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"

如图

Alt text

3、安装 DNX

打开新的 cmd

cmd:

dnvm list

输入 y,安装 dnx

如图

Alt text

cmd:

dnvm install latest -Unstable -Persistent

cmd:

dnx

将会看到 dnx 的操作说明

如图

Alt text

4、更新 DNX 和 DNVM bits

cmd:

dnvm upgrade
dnvm update-self

如图

Alt text

5、配置 Package

新建文件夹 test

cmd:

cd c:\test
dnu restore -s https://www.myget.org/F/aspnetvnext

如图

Alt text

注:

C:\Windows\System32 直接输入 dnu restore -s https://www.myget.org/F/aspnetvnext 会报错,如图

Alt text

6、添加脚本文件

新建文件 Program.cs,内容如下:

using System;
public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World");
    }
}

注:class 名必须为 Program,否则报错

新建文件 project.json,内容如下:

{
    "dependencies":{

    },
    "commands":{
        "test":"test"
    },
    "frameworks":{
        "dnx451":{},
        "dnxcore50":{
            "dependencies":{
                "System.Console":"4.0.0-beta-*"
            }
        }
    }
}

注:project.json 中"commands"内的"test"需要同文件夹名称 test 对应

注:中文系统的浏览器复制 https://blogs.msdn.microsoft.com/sujitdmello/2015/04/23/step-by-step-installation-instructions-for-getting-dnx-on-your-windows-machine/ 中的示例代码为 unicode 格式,直接使用会报错,如图

Alt text

需要将其中的 Unicode 字符转化

7、测试脚本

cmd:

dnu restore

如图

Alt text

cmd:

dnx test

如图

Alt text

注:如果仅测试上述代码,只需完成步骤 3 即可

8、Win10 Device Guard 测试

dnx.exe 测试成功后,接下来需要找到 dnx.exe 在 Win10 上使用需要包含哪些支持文件,最直观的方法可借助于 ProcessMonitor

使用 ProcessMonitor 获取 dnx.exe 在运行时的操作,如图

Alt text

找到关键目录:

C:\Users\a\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update2\bin\

经实际测试,在 Win10 上使用,只需要该目录下的部分文件,大小为 7.44MB

注:

这是 Matt Nelson@enigma0x3 留给读者的作业

文件列表如下:

  • dnx.clr.dll
  • dnx.exe
  • dnx.onecore.dll
  • Microsoft.CodeAnalysis.CSharp.dll
  • Microsoft.CodeAnalysis.dll
  • Microsoft.Dnx.ApplicationHost.dll
  • Microsoft.Dnx.Compilation.Abstractions.dll
  • Microsoft.Dnx.Compilation.CSharp.Abstractions.dll
  • Microsoft.Dnx.Compilation.CSharp.Common.dll
  • Microsoft.Dnx.Compilation.CSharp.dll
  • Microsoft.Dnx.Compilation.dll
  • Microsoft.Dnx.Host.Clr.dll
  • Microsoft.Dnx.Host.dll
  • Microsoft.Dnx.Loader.dll
  • Microsoft.Dnx.Runtime.dll
  • Microsoft.Extensions.PlatformAbstractions.dll
  • System.Collections.Immutable.dll
  • System.Reflection.Metadata.dll
  • vcruntime140.dll(也可忽略,但会报错,不影响代码执行)

该目录下的这些文件不需要:

  • dnu.cmd
  • dnx.win32.dll
  • Microsoft.Dnx.Compilation.DesignTime.dll
  • Microsoft.Dnx.DesignTimeHost.Abstractions.dll
  • Microsoft.Dnx.dll
  • Microsoft.Dnx.Host.Mono.dll
  • Microsoft.Dnx.Runtime.Internals.dll

如图,由于 dnx.exe 包含微软的签名证书,所以在 Device Guard UMCI(user mode code integrity) 开启的环境中仍具有执行权限

Alt text

绕过成功

0x03 rcsi.exe

rcsi.exe 内置于 Microsoft Roslyn CTP 中,包含微软数字签名

Microsoft Roslyn CTP 下载地址: https://www.microsoft.com/en-us/download/details.aspx?id=34685&tduid=(24d3dfde6075d394de05e49e871fa656)(256380)(2459594)(TnL5HPStwNw-qGm27mnsJb9VbqZPmTLajQ)( )

安装前提:

  • 安装 Visual Studio 2012
  • 安装 VS2012 SDK

1、实际测试

测试系统:Win8.1 x86 安装 Visual Studio 2012、VS2012 SDK、Microsoft "Roslyn" CTP

2、执行代码

rcsi.exe 的路径为:

C:\Program Files\Microsoft Roslyn CTP\Binaries

新建文件 test.csx,内容如下:

using System;
Console.WriteLine("Hello World");
Console.ReadLine();

cmd:

"C:\Program Files\Microsoft Roslyn CTP\Binaries\rcsi.exe" test.csx

如图,成功执行 C#代码

Alt text

rcsi.exe 同 csi.exe 类似,可以用来执行 c#代码,不同点在于 csi.exe 支持交互,而 rcsi.exe 不能

如图

Alt text

3、Win10 Device Guard 测试

rcsi.exe 在 Win10 上运行同样需要支持文件 同样使用 ProcessMonitor 获取 rcsi.exe 在运行时的操作,如图

Alt text

找到 rcsi.exe 需要的支持文件如下:

  • C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Roslyn.Compilers.CSharp\v4.0_1.2.0.0__31bf3856ad364e35\Roslyn.Compilers.CSharp.dll
  • C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Roslyn.Compilers\v4.0_1.2.0.0__31bf3856ad364e35\Roslyn.Compilers.dll

注:这也是 Matt Nelson@enigma0x3 留给读者的作业

在 Win10 下测试成功,如图

Alt text

0x04 防御

参照 Matt Graeber 的方法,更新 Device Guard Bypass Mitigation Rules,可分别拦截利用 WinDbg/CDB、csi.exe、dnx.exe 和 rcsi.exe 的代码执行

参考地址如下:http://www.exploit-monday.com/2016/09/using-device-guard-to-mitigate-against.html

0x05 小结

本文对 dnx.exe 和 rcsi.exe 的利用方法做了介绍,截至目前共有四种绕过 Device Guard 的方法,相信未来会有更多的方法被发现,与此同时,防御手段也需要随之升级。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

好倦

暂无简介

文章
评论
24 人气
更多

推荐作者

alipaysp_giMRmwQ3mK

文章 0 评论 0

爱她像谁

文章 0 评论 0

清风疏影

文章 0 评论 0

mb_OO8gCSDD

文章 0 评论 0

佚名

文章 0 评论 0

汹涌人海

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文