【UWP】修改清单脱离沙盒运行

  • 【UWP】修改清单脱离沙盒运行已关闭评论
  • 72 次浏览
  • A+
所属分类:.NET技术
摘要

总说周知,UWP 是运行在沙盒里面的,所有权限都有严格限制,和沙盒外交互也需要特殊的通道,所以从根本杜绝了 UWP 毒瘤的存在。但是实际上 UWP 只是一个应用模型,本身是没有什么权限管理的,权限管理全靠 App Container 沙盒控制,如果我们脱离了这个沙盒,UWP 就会放飞自我了。那么有没有这种可能呢?

总说周知,UWP 是运行在沙盒里面的,所有权限都有严格限制,和沙盒外交互也需要特殊的通道,所以从根本杜绝了 UWP 毒瘤的存在。但是实际上 UWP 只是一个应用模型,本身是没有什么权限管理的,权限管理全靠 App Container 沙盒控制,如果我们脱离了这个沙盒,UWP 就会放飞自我了。那么有没有这种可能呢?

我们打开设置应用,通过任务管理器查看进程,就会发现它并没有 Runtime Broker 存在,这个进程是用来在沙盒间代理的,这说明微软给 UWP 开了一个后门。

【UWP】修改清单脱离沙盒运行

 那么我们是不是也有办法脱离沙盒运行呢?Ahmed Walid 在 2023年2月 发表了这样一个帖子

【UWP】修改清单脱离沙盒运行

同时他还提交了一个名为 Added a remark about uap10:TrustLevel 的 PR,在这个 PR 中明确提到了如何通过设置 Custom Capability 来修改 UWP 的 TrustLevel

Setting uap10:TrustLevel="mediumIL" while uap10:RuntimeBehavior="windowsApp" requires the Microsoft.coreAppActivation_8wekyb3d8bbwe Custom Capability.

This is also true if uap10:TrustLevel="mediumIL" and EntryPoint is any other value than "windows.fullTrustApplication" or "windows.partialTrustApplication".

You can read more about this custom capability here in Custom Capabilities.

如今这个 PR 已经合并,现在可以直接在微软文档《应用程序 (Windows 10)》中找到了

根据文档描述,我们需要添加一个名为 Microsoft.coreAppActivation_8wekyb3d8bbwe 的自定义权限,然后将 uap10:TrustLevel 设置为 mediumIL 即可

首先我们在清单中加入权限

<?xml version="1.0" encoding="utf-8"?> <Package   ...   xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"   xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"   IgnorableNamespaces="... uap4 rescap">   ...   <Capabilities>     ...     <!-- runFullTrust 权限是必不可少的 -->     <rescap:Capability Name="runFullTrust" />     <uap4:CustomCapability Name="Microsoft.coreAppActivation_8wekyb3d8bbwe" />   </Capabilities> </Package>

Custom Capability 不同于其他权限,这是用来给 OEM 自定义使用的,需要 SCCD 文件来证明你有使用权限的资格,所以想上架是基本没可能了,相关内容可以查看教程 [UWP] Custom Capability的使用

我们在项目根目录新建一个名为 CustomCapability.SCCD 的文件,在其中写入

<?xml version="1.0" encoding="utf-8"?> <CustomCapabilityDescriptor xmlns="http://schemas.microsoft.com/appx/2018/sccd" xmlns:s="http://schemas.microsoft.com/appx/2018/sccd">   <CustomCapabilities>     <CustomCapability Name="Microsoft.coreAppActivation_8wekyb3d8bbwe"></CustomCapability>   </CustomCapabilities>   <AuthorizedEntities AllowAny="true"/>   <Catalog>FullTrust</Catalog> </CustomCapabilityDescriptor>

 然后将该文件设置为内容,或者选择复制到输出,只要最后能出现在安装包里面就行了

最后我们将 uap10:TrustLevel 设置为 mediumIL

<?xml version="1.0" encoding="utf-8"?> <Package   ...   xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"   IgnorableNamespaces="... uap10">   ...   <Applications>     <Application       ...       uap10:TrustLevel="mediumIL">       ...     </Application>   </Applications>   ... </Package>

 部署时有概率遇到

DEP0700: 应用程序注册失败。[0x80073CF6] 错误 0x80070057: 在准备处理请求时,由于以下错误,系统无法注册 windows.capability 扩展: 参数错误。

暂时没有找到解决方法,重启几次电脑可能就好了