Skip to content

Commit 61f1497

Browse files
committed
Added mandatory access list and Get-NtTypeAccess function.
1 parent 6af5565 commit 61f1497

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

NtApiDotNet/NtType.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ public IEnumerable<AccessMaskEntry> AccessRights
227227
/// </summary>
228228
public IEnumerable<AccessMaskEntry> AllAccessRights => AccessRights.Where(r => GenericMapping.GenericAll.IsAccessGranted(r.Mask));
229229

230+
/// <summary>
231+
/// Get the valid mandatory access rights for this Type.
232+
/// </summary>
233+
public IEnumerable<AccessMaskEntry> MandatoryAccessRights
234+
{
235+
get
236+
{
237+
AccessMask mask = GetDefaultMandatoryAccess();
238+
return AccessRights.Where(r => mask.IsAccessGranted(r.Mask));
239+
}
240+
}
241+
230242
#endregion
231243

232244
#region Public Methods

NtObjectManager/NtObjectManager.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ FunctionsToExport = 'Get-AccessibleAlpcPort', 'Set-NtTokenPrivilege',
6868
'Suspend-NtProcess', 'Resume-NtProcess', 'Stop-NtProcess', 'Suspend-NtThread', 'Resume-NtThread', 'Stop-NtThread',
6969
'Format-NtToken', 'Remove-NtTokenPrivilege', 'Get-NtTokenPrivilege', 'Get-NtLocallyUniqueId', 'Get-NtTokenGroup',
7070
'Get-NtTokenSid', 'Set-NtTokenSid', 'Set-NtTokenGroup', 'Get-NtDesktopName', 'Get-NtWindowStationName',
71-
'Get-NtWindow', 'Out-HexDump'
71+
'Get-NtWindow', 'Out-HexDump', 'Get-NtTypeAccess'
7272

7373
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7474
CmdletsToExport = 'Add-NtKey', 'Get-NtDirectory', 'Get-NtEvent', 'Get-NtFile',

NtObjectManager/NtObjectManager.psm1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,4 +5630,50 @@ function Out-HexDump {
56305630
$builder.Complete()
56315631
$builder.ToString() | Write-Output
56325632
}
5633+
}
5634+
5635+
<#
5636+
.SYNOPSIS
5637+
Gets the access masks for a type.
5638+
.DESCRIPTION
5639+
This cmdlet gets the access masks for a type.
5640+
.PARAMETER Type
5641+
The NT type.
5642+
.PARAMETER Read
5643+
Shown only read access.
5644+
.PARAMETER Write
5645+
Shown only write access.
5646+
.PARAMETER Execute
5647+
Shown only execute access.
5648+
.PARAMETER Mandatory
5649+
Shown only default mandatory access.
5650+
.INPUTS
5651+
None
5652+
.OUTPUTS
5653+
AccessMask entries.
5654+
#>
5655+
function Get-NtTypeAccess {
5656+
[CmdletBinding(DefaultParameterSetName="All")]
5657+
Param(
5658+
[Parameter(Mandatory, Position=0)]
5659+
[NtApiDotNet.NtType]$Type,
5660+
[Parameter(ParameterSetName="Read")]
5661+
[switch]$Read,
5662+
[Parameter(ParameterSetName="Write")]
5663+
[switch]$Write,
5664+
[Parameter(ParameterSetName="Execute")]
5665+
[switch]$Execute,
5666+
[Parameter(ParameterSetName="Mandatory")]
5667+
[switch]$Mandatory
5668+
)
5669+
5670+
$access = switch($PSCmdlet.ParameterSetName) {
5671+
"All" { $Type.AccessRights }
5672+
"Read" { $Type.ReadAccessRights }
5673+
"Write" { $Type.WriteAccessRights }
5674+
"Execute" { $Type.ExecuteAccessRights }
5675+
"Mandatory" { $Type.MandatoryAccessRights }
5676+
}
5677+
5678+
$access | Write-Output
56335679
}

0 commit comments

Comments
 (0)