Skip to content

Commit 7839321

Browse files
committed
Added WinTcb for sessions.
1 parent 272f6c1 commit 7839321

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

NtObjectManager/Cmdlets/Object/GetNtTokenCmdlet.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public sealed class GetNtTokenCmdlet : PSCmdlet
281281
[Parameter(ParameterSetName = "Logon")]
282282
[Parameter(ParameterSetName = "Service")]
283283
[Parameter(ParameterSetName = "S4U")]
284+
[Parameter(ParameterSetName = "Session")]
284285
public SwitchParameter WithTcb { get; set; }
285286

286287
/// <summary>
@@ -312,7 +313,8 @@ public sealed class GetNtTokenCmdlet : PSCmdlet
312313
/// </summary>
313314
[Parameter(ParameterSetName = "Logon"),
314315
Parameter(ParameterSetName = "Service")]
315-
public Sid[] AdditionalGroups { get; set; }
316+
[Alias("AdditionalGroups")]
317+
public Sid[] AdditionalGroup { get; set; }
316318

317319
/// <summary>
318320
/// <para type="description">Specify domain for logon token.</para>
@@ -605,9 +607,9 @@ private NtToken GetLogonToken(TokenAccessRights desired_access, string user,
605607
string domain, SecureString password, SecurityLogonType logon_type)
606608
{
607609
IEnumerable<UserGroup> groups = null;
608-
if (AdditionalGroups != null && AdditionalGroups.Length > 0)
610+
if (AdditionalGroup != null && AdditionalGroup.Length > 0)
609611
{
610-
groups = AdditionalGroups.Select(s => new UserGroup(s,
612+
groups = AdditionalGroup.Select(s => new UserGroup(s,
611613
GetAttributes(s)));
612614
}
613615
using (NtToken token = Win32Security.LsaLogonUser(user, domain, password, logon_type, LogonProvider, groups))
@@ -762,22 +764,25 @@ private NtToken GetServiceToken(TokenAccessRights desired_access, ServiceAccount
762764

763765
private NtToken GetSessionToken(TokenAccessRights desired_access, int session_id)
764766
{
765-
if (!NtToken.EnableEffectivePrivilege(TokenPrivilegeValue.SeTcbPrivilege))
767+
using (var imp = GetTcbPrivilege())
766768
{
767-
WriteWarning("Getting session token requires SeTcbPrivilege");
768-
}
769+
if (imp == null)
770+
{
771+
WriteWarning("Getting session token requires SeTcbPrivilege");
772+
}
769773

770-
if (session_id < 0)
771-
{
772-
session_id = NtProcess.Current.SessionId;
773-
}
774-
using (var token = TokenUtils.GetSessionToken(session_id))
775-
{
776-
if (desired_access == TokenAccessRights.MaximumAllowed)
774+
if (session_id < 0)
777775
{
778-
return token.Duplicate();
776+
session_id = NtProcess.Current.SessionId;
777+
}
778+
using (var token = TokenUtils.GetSessionToken(session_id))
779+
{
780+
if (desired_access == TokenAccessRights.MaximumAllowed)
781+
{
782+
return token.Duplicate();
783+
}
784+
return token.Duplicate(desired_access);
779785
}
780-
return token.Duplicate(desired_access);
781786
}
782787
}
783788

0 commit comments

Comments
 (0)