【UWP】修改清单脱离沙盒运行
  cgGYbv7pGvep 15天前 28 0

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

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

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

同时他还提交了一个名为 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>FFFF</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>

我们调用Process.GetProcesses()获取进程列表(UAP 10.0.15138.0虽然加入了Process支持,但是并没有实现Process.GetProcesses(),所以这里是运行在 .NET 8.0 上的

using Microsoft.UI.Xaml.Controls;
using System.Diagnostics;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace FullTrustUWP.Pages
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage() => InitializeComponent();

        public void Test()
        {
            // 这里使用了 Windows App SDK,实际上 WAS 是支持 UWP 的
            Content = new ItemsView
            {
                // 必须使用 .NET Core App,因为微软没有给 .NET Core 5.0 实现这个方法
                ItemsSource = Process.GetProcesses()
            };
        }
    }
}

运行效果

如果没有设置uap10:TrustLevelmediumIL,则依然运行在沙盒中,Process.GetProcesses()只能获取到沙盒中的进程

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 15天前 0

暂无评论

推荐阅读
  mVIyUuLhKsxa   20小时前   6   0   0 .NET
  f18CFixvrKz8   20小时前   6   0   0 .NET
  f18CFixvrKz8   20小时前   5   0   0 .NET
cgGYbv7pGvep
作者其他文章 更多