Skip to content

Commit b56ac50

Browse files
committed
Added Get-NtTokenPrivilege command.
1 parent ce5306a commit b56ac50

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

NtObjectManager/NtObjectManager.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ FunctionsToExport = 'Get-AccessibleAlpcPort', 'Set-NtTokenPrivilege',
6666
'Get-RpcClient', 'Format-RpcClient', 'Set-RpcServer', 'Connect-RpcClient', 'New-RpcContextHandle', 'Format-RpcComplexType',
6767
'Get-Win32File', 'Close-NtObject', 'Start-AccessibleScheduledTask', 'Get-NtEaBuffer', 'Set-NtEaBuffer',
6868
'Suspend-NtProcess', 'Resume-NtProcess', 'Stop-NtProcess', 'Suspend-NtThread', 'Resume-NtThread', 'Stop-NtThread',
69-
'Format-NtToken', 'Remove-NtTokenPrivilege'
69+
'Format-NtToken', 'Remove-NtTokenPrivilege', 'Get-NtTokenPrivilege'
7070

7171
# 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.
7272
CmdletsToExport = 'Add-NtKey', 'Get-NtDirectory', 'Get-NtEvent', 'Get-NtFile',

NtObjectManager/NtObjectManager.psm1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,53 @@ function Set-NtTokenPrivilege
128128
}
129129
}
130130

131+
<#
132+
.SYNOPSIS
133+
Get the state of a token's privileges.
134+
.DESCRIPTION
135+
This cmdlet will get the state of a token's privileges.
136+
.PARAMETER Privileges
137+
A list of privileges to get their state.
138+
.PARAMETER Token
139+
Optional token object to use to get privileges. Must be accesible for Query right.
140+
.INPUTS
141+
None
142+
.OUTPUTS
143+
List of TokenPrivilege values indicating the state of all privileges requested.
144+
.EXAMPLE
145+
Get-NtTokenPrivilege
146+
Get all privileges on the current process token
147+
.EXAMPLE
148+
Set-NtTokenPrivilege SeDebugPrivilege
149+
Get state of SeDebugPrivilege on the current process token
150+
.EXAMPLE
151+
Get-NtTokenPrivilege SeBackupPrivilege, SeRestorePrivilege -Token $token
152+
Get SeBackupPrivilege and SeRestorePrivilege status on an explicit token object.
153+
#>
154+
function Get-NtTokenPrivilege
155+
{
156+
Param(
157+
[Parameter(Position=0)]
158+
[NtApiDotNet.TokenPrivilegeValue[]]$Privileges,
159+
[NtApiDotNet.NtToken]$Token
160+
)
161+
if ($null -eq $Token) {
162+
$Token = Get-NtToken -Primary -Access Query
163+
} else {
164+
$Token = $Token.Duplicate()
165+
}
166+
167+
Use-NtObject($Token) {
168+
if ($Privileges -ne $null -and $Privileges.Count -gt 0) {
169+
foreach($priv in $Privileges) {
170+
$Token.GetPrivilege($priv) | Write-Output
171+
}
172+
} else {
173+
$Token.Privileges | Write-Output
174+
}
175+
}
176+
}
177+
131178
<#
132179
.SYNOPSIS
133180
Remove privileges from a token.

0 commit comments

Comments
 (0)