【问题标题】:Identify User with special NTFS access permission识别具有特殊 NTFS 访问权限的用户
【发布时间】:2021-07-07 22:48:13
【问题描述】:

我正在执行这个命令来获取用户和他们的权限:

Get-Acl $path | 
    select -ExpandProperty Access | 
    where { $_.IdentityReference -match "Users" } |
    select -Property * -ExcludeProperty IsInherited |
    Format-Table
           FileSystemRights AccessControlType IdentityReference                InheritanceFlags PropagationFlags
           ---------------- ----------------- -----------------                ---------------- ----------------
ReadAndExecute, Synchronize             Allow BUILTIN\Users     ContainerInherit, ObjectInherit             None
                 AppendData             Allow BUILTIN\Users                    ContainerInherit             None
                CreateFiles             Allow BUILTIN\Users                    ContainerInherit             None

在这一用户中,用户具有特殊的访问权限。我需要删除该用户。

请您帮助识别该用户。

【问题讨论】:

  • 您想要做什么并不完全清楚。 删除该用户到底是什么意思?
  • 我添加了一张图片。需要删除此用户。
  • 那不是用户,它是一个内置组,就像你用Get-Acl 向我们展示的一样:)
  • 我不太清楚这一点,但它显示 3 User right..?
  • 不,它显示了具有不同访问控制列表的相同组。

标签: powershell acl


【解决方案1】:

Special 只是指与ReadWrite 等命名预设之一不匹配的文件系统访问权限列表。

在您的情况下,BUILTIN\Users 在第一个条目中具有ReadAndExecute 预设,但也具有AppendDataCreateFiles 权限。这两个权限不是完整的Write 权限,所以它们显示为Special

如果您想为您的 BUILTIN\Users 组删除这些特定权限,您可以使用以下内容:

$path = 'C:\temp\temp'
$acl = get-acl $path

# Check the existing rights
$acl.Access | where IdentityReference -Like 'BUILTIN\Users'

# Get a list of the rules to remove
$rules = $acl.access | Where-Object { 
    !$_.IsInherited -and 
    $_.IdentityReference -like 'BUILTIN\Users' -and
    $_.FileSystemRights -in 'AppendData','CreateFiles'
}

# Remove those rules from the ACL object 
ForEach($rule in $rules) {
    $acl.RemoveAccessRule($rule)
}

# Check that the remaining rules look good:
$acl.Access

# Finally, set the ACL
# WARNING: setting file permissions can of course lock you out of files, so be careful!
Set-Acl -Path $path -AclObject $acl

请注意,您问题中的示例显示这两个权限也已通过InheritanceFlags: ContainerInherit 应用于子文件夹。因此,当您更新 ACL 时,它会尝试将更改应用到所有子文件夹。

如果您真的想像屏幕截图一样删除 C:\ 根目录上的权限条目,您可能会在您无权访问的子文件夹上遇到问题。

【讨论】:

  • 我试过代码。它正在执行没有任何错误,但访问权限没有被删除
  • @EmptyCoder 在运行.RemoveAccessRule() 方法后,$acl.Access 为您的组显示什么?如果权限与您的问题完全相同,则应该只剩下ReadAndExecute, Synchronize
【解决方案2】:

感谢@Cpt.Whale 的帮助

下面的代码解决了我的问题。

$path = 'C:\temp'
$acl = get-acl $path


##Remove Inheritance from Top Folders and Child Objects
Foreach($folder in $path) { 
 icacls $folder /inheritance:d
 Get-ChildItem -Path $folder -Recurse | ?{$_.PSisContainer} | foreach {$subfolder = $_.FullName; icacls $subfolder /inheritance:d}
}


# Check the existing rights
$acl.Access | where IdentityReference -Like 'BUILTIN\Users'

# Get a list of the rules to remove
$rules = $acl.access | Where-Object { 
    !$_.IsInherited -and 
    $_.IdentityReference -like 'BUILTIN\Users' -and
    $_.FileSystemRights -in 'CreateFiles, AppendData'
}

# Remove those rules from the ACL object 
ForEach($rule in $rules) {
    $acl.RemoveAccessRule($rule)
}

# Check that the remaining rules look good:
$acl.Access

# Finally, set the ACL

Set-Acl -Path $path -AclObject $acl

【讨论】:

    猜你喜欢
    • 2021-02-15
    • 1970-01-01
    • 2014-08-11
    • 2019-03-06
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多