如何使用Wix Installer拒绝用户对文件夹的访问权限

3
我的目标是将我的应用程序安装到一个文件夹中:
  • SYSTEM用户可读写
  • 管理员可读写
  • 其他任何人没有其他权限。
我已经尝试了各种不同的组合和排列方法,包括wix PermissionPermissionEx元素。
我最近的尝试如下:
<CreateFolder>
  <util:PermissionEx User="Users" GenericRead="no" Read="no"/>
  <util:PermissionEx User="Everyone" GenericRead="no" Read="no"/>
  <util:PermissionEx User="Administrators" GenericAll="yes"/>
</CreateFolder>

Component元素中。

我的结果总是一样:用户仍然显示对已安装文件夹的读取读取和执行以及列出文件夹内容的权限。

我的目标与限制使用wix安装程序安装的文件夹的访问权限非常相似。

我还考虑过WIX: 给一个文件夹授权Wix:如何为文件夹及其所有子文件夹设置权限


1
在下面添加了一个选项列表。也许有一些选项是可以接受的,但大多数选项可能只是理论上的。 - Stein Åsmul
2个回答

3

我想知道你的总体目标是什么(可能有几个选项适用):

  • 目标是防止普通用户运行应用程序吗?(如果是的话,您可以要求提高权限以运行 - 不太好,但应该有效。普通用户在启动应用程序时会被要求输入管理员密码。如果他们没有密码,他们就无法运行应用程序 - 据我所知 - 除非他们提升权限的管理员帐户没有密码!)。
  • 目标是防止普通用户能够列出相关文件夹的内容吗?替换ACL(禁用继承权限),并仅为您想要访问文件夹的用户/用户组添加访问权限即可。不需要拒绝权限或特定权限的普通用户。换句话说,只需替换现有的ACL,并为管理员添加通用写入权限和SYSTEM的完全权限即可?

我相信你已经非常清楚,修改访问控制列表可能会产生许多副作用,特别是拒绝权限(自我修复期间会发生什么?)。我现在没有时间测试特定的ACL,但如果你还需要,我明天会再次检查。我认为“需要管理员权限”选项可能适合你?


快速模拟

我只想添加一个 快速测试权限的方法,以便测试。只需在Windows资源管理器中按需要修改ACL权限。然后启动提升的命令提示符并导航到要捕获ACL的文件夹。然后执行以下操作:

cacls.exe foldername /s

这应该显示一个SDDL字符串,你可以直接在WiX中倾倒它以使用MSI文件中的新内置LockPermissionEx表(仅适用于MSI 5!):
<Component Feature="ProductFeature">
   <File Source="Files\Test.exe" />
   <CreateFolder>
     <PermissionEx Id="p1" Sddl="D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;0x1200a8;;;BU)" />
   </CreateFolder>
</Component>

上述操作应该会生成一个文件夹,其中SYSTEM、管理员有完全访问权限,并且对于普通用户具有“遍历文件夹/运行文件、读取属性、读取扩展属性和读取访问权限”的特殊访问权限。正如下面所述,这并不是很好的解决方案,因为管理员通常以非提升方式运行,然后模拟普通用户(不确定这究竟是如何工作的)。
如你所知,有许多与权限相关的不同WiX元素(页面中部),你也可以使用自定义操作进行权限设置(不建议这样做)。明天将进一步测试。或许可以通过提升EXE和保护数据文件夹的组合来解决问题?或者在系统尝试启动指向未提升文件的快捷方式之前,让触发快捷方式调用提升?

尝试列出一些选项

更新: 今天没有进行太多测试,但我开始思考可能的选项列表。其中一些选项只是随意记下来的,并不真正可行。它们用于排除一些方案并查看是否能激发新的更好的想法。也许可以使用 8, 1, 2, 36?也许可以组合使用?

组合?: 超级隐藏的安装文件夹,也是 ACL 锁定的,并通过映射驱动器上运行的始终升级的 EXE 访问(访问基于访问控制的枚举服务器共享)?

  1. Lock / Hide & Elevate: hide sub folder with ACLs, then require UAC elevation on application launch by modifying the application manifest? A single launcher application EXE would be visible? (Can be super-hidden? See next bullet point).
    • Not great security-wise (once you elevate, access is pervasive), but I think it will work, and no regular user would be able to access the ACL-protected data sub-folder (they will see it though - but check out the next option with super-hidden folder status - combination possible?).
      • I will just mention that regular users will be asked for a password when trying to invoke executables that require admin rights to run. Without an admin password they can't run the application at all as far as I know. Can be forgotten in the heat of the moment, and a manager could miss that suddenly admin rights are required to run the application at all. I have seen it happen.
      • Though preventable by group policy for corporate networks, if there is a password-less, local administrator account (which could be common in small businesses), then any standard user can elevate to admin rights via that passwordless admin-account - at will - once prompted for an admin password.
        • Easy to forget.
        • Huge security hole.
        • There is the highest available elevation option that I have never tried (elevate to admin rights only for admin accounts, otherwise run with limited rights).
      • Not sure what happens if UAC is disabled. The whole approach probably fails? Or maybe it just runs elevated without asking? I don't know.
      • There are further security problems that are best not to mention along the same lines as any elevated process is problematic: access is pervasive and not specific ("all-access backstage pass" - unless you limit privileges well for the account).
      • Make no mistake about it: elevating EXE files should ideally only be used to allow system maintenance and configuration by system administrators who know what they are doing. Elevation has no place in good software engineering for regular corporate applications. In theory there should be no difference between theory and practice, but in practice there is :-).
    • You would likely need to keep the main application binary visible for it to be launchable by any users though. Otherwise MSI self-repair kicks in as the file pointed to is inaccessible. Maybe a custom shortcut flag is available to force elevation immediately? Going to have a look.
  2. Make Folder Super-Hidden: this is probably a silly option. It depends on your use case and how protected these files must be? Are they just desired out of view, or do they have to be "locked" and inaccessible? You can set a super-hidden flag for your folder with a simple attrib command:

    attrib +s +h "C:\Folder\"
    

    The folder is now super-hidden like some core OS folders. Such a folder doesn't show up in Windows Explorer or in command line unless you take special steps to make it appear (show hidden OS files - see above link). But the folder is not locked for access if the users know the folder is there. Maybe you can combine the super-hidden flag with another approach? (hide the folder and lock it too?)

  3. Access-Based Enumeration Server Share: this new server feature seems to be what you need actually. It hides folders that the user in question does not have access rights to, but I don't think the feature can be used on regular PCs (non servers). Perhaps it can? Something to check later. I don't know if storing files on a server share is an option or not?

  4. Database Connection: this is surely out of the question - for some reason - but the elephant in the room is why this data access (if it relates to data-access) isn't done via a database and an authenticated connection?
  5. Web-Application: as with 4, a good reason obviously exists preventing you from making this a web-application? Or I guess it could be a web-application for all we know. Jotting down whatever comes to mind, bear with me.
  6. Mapped Drive via Logon Script / Group Policy: I suppose you could use a mapped drive via a logon script (or better, using group policy) which is mapped only for the users who should have access to the application? Simple applications could run straight off such a mapped drive I think. No installation to do either. Or you keep a binary in the mapped drive, and the rest of the files locally?
  7. NTFS symbolic link: trying to jot down everything that comes to mind as I said. I have never used this feature, but I know a NTFS symbolic link could point to a server share. What if that server supports access based enumeration? Would this hide the files and folders for some users? Unwise to list options you haven't tried, but maybe someone else gets a better idea reading it?
  8. Custom NT Access Group: I am wondering if the simplest "fix" of all would be to create a local or AD access group which you need to be a member of to be able to access your folder at all. So you remove all built-in groups, add SYSTEM and your custom group with full access and any other groups that are technically needed (creator?). I haven't tested this (maybe it was the first thing you tried?). Combining such a local group with a super-hidden folder sounds like an option. No regular users will easily see the folder, and if they do they can't access it? There is still the issue of the launching shortcut visibility? (why should users see it, if they can't launch the application).

谢谢,斯坦。我的目标是你的第二个项目。我不希望普通用户阅读此文件夹的内容。您是否有“仅替换现有ACL并为管理员添加通用写入权限以及为SYSTEM添加完全权限”的Wix代码示例? - Eric
我已经进行了一些测试,结果并不令人满意。我可能会错过一些东西,但即使管理员现在也只能以标准权限运行 - 除非他们通过UAC提示进行提升。因此,即使管理员也似乎无法查看文件夹内容,如果您不将读取和查看文件夹列表权限授予常规用户。我还有一些事情要测试,明天再检查。隐藏子文件夹但保留主EXE对于常规用户是否足够?结合始终以提升的方式运行(UAC),这可能有效吗?然后您可以隐藏数据文件以防止被查看。 - Stein Åsmul
谢谢,斯坦。我一直在搞计算和SDDL字符串。你建议在PermissionEx元素中包含SDDL看起来很有前途。初步测试效果不错。如果综合测试发现我忽略了什么,我会再回来的。 - Eric
请这样做。ACL曾经给我带来了很多烦恼。只是说实话。祝你好运。当我使用它时,我得出结论:“只有少数ACL组合是有意义的” - 所以如果我是你,我会选择通用权限(仅限组,没有用户,没有拒绝权限,通用写入,通用读取等)。在测试期间,我确实使类似于您的情况工作,方法是拒绝文件夹列表和文件夹遍历,同时授予相同的权限(以及所有其他权限)。奇怪的组合。闻起来像麻烦:-)。删除写访问权限后,它就崩溃了。然后普通用户甚至无法阅读。 - Stein Åsmul

1
如果您能找到(或创建)一个具有所需权限的文件夹,我建议首先使用CACLS.exe以SDDL格式显示权限。一旦获得了这个,您可以在MSI中使用MsiLockPermissionsEx表。WiX似乎不直接支持MsiLockPermissionsEx表,也就是说,除非我错过了什么地方,否则似乎没有办法将SDDL字符串粘贴到某个地方应用。

嗨Phil。我相信你可以使用PermissionEx元素在WiX中完成这个任务。WiX权限控制非常令人困惑 - 也许可以看一下这个答案的中间部分,了解我所知道的WiX ACL权限控制元素列表。然而,MsiLockPermissionsEx功能仅适用于MSI 5(仅限Windows 7和Windows Server 2008 R2及以上版本)。也许还可以看一下我在这里的WiX片段 - 它展示了如何直接使用SDDL字符串(我相信 - 这是我第一次使用它)。 - Stein Åsmul
谢谢Phil和Stein。 @PhilDW,你关于calcs的建议很有帮助。而Stein的建议,在permissionex元素中包含sddl,目前看来是有效的。正如你们两个所知道的,这里有许多变化需要测试。我们完成更多测试后会报告更多信息。 - Eric
请注意,a.) cacls.exe 自 Windows 2000 引入继承后已经不再是一个好的选择,请使用 icacls.exe(当您运行 cacls.exe /? 时会有一个关于此的注释);b.) 即使是当前版本的 icacls.exe 也使用旧版本或潜在的 SDDL 方言。我所知道的 Windows 上唯一的内置工具是 PowerShell 中的 Get-Acl 命令,使用方法如下:(Get-Acl -Path .).sddl 获取 SDDL。还要注意,Get-Acl 是一个误导性的名称,因为它实际上检索的是完整的 SD,而不仅仅是 (D)ACL。 - 0xC0000022L

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接