Skip to content

Commit d059914

Browse files
committed
Specify multiple values when creating SIDs.
1 parent 6a1d403 commit d059914

1 file changed

Lines changed: 41 additions & 37 deletions

File tree

NtObjectManager/Cmdlets/Object/GetNtSidCmdlet.cs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using NtApiDotNet;
1616
using NtApiDotNet.Win32;
1717
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
1820
using System.Management.Automation;
1921

2022
namespace NtObjectManager.Cmdlets.Object
@@ -90,44 +92,44 @@ public class GetNtSidCmdlet : PSCmdlet
9092
/// <para type="description">Specify a SID using an SDDL string.</para>
9193
/// </summary>
9294
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "sddl")]
93-
public string Sddl { get; set; }
95+
public string[] Sddl { get; set; }
9496

9597
/// <summary>
9698
/// <para type="description">Specify a SID from an ACE.</para>
9799
/// </summary>
98100
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "ace")]
99101
[Alias("Ace")]
100-
public Ace AccessControlEntry { get; set; }
102+
public Ace[] AccessControlEntry { get; set; }
101103

102104
/// <summary>
103105
/// <para type="description">Lookup a SID using an NT account name.</para>
104106
/// </summary>
105107
[Parameter(Mandatory = true, ParameterSetName = "name")]
106-
public string Name { get; set; }
108+
public string[] Name { get; set; }
107109

108110
/// <summary>
109111
/// <para type="description">Create a SID based on a service name.</para>
110112
/// </summary>
111113
[Parameter(Mandatory = true, ParameterSetName = "service")]
112-
public string ServiceName { get; set; }
114+
public string[] ServiceName { get; set; }
113115

114116
/// <summary>
115117
/// <para type="description">Create a SID based on the standard set of integrity levels.</para>
116118
/// </summary>
117119
[Parameter(Mandatory = true, ParameterSetName = "il")]
118-
public TokenIntegrityLevel IntegrityLevel { get; set; }
120+
public TokenIntegrityLevel[] IntegrityLevel { get; set; }
119121

120122
/// <summary>
121123
/// <para type="description">Create a SID based on a raw integerity level.</para>
122124
/// </summary>
123125
[Parameter(Mandatory = true, ParameterSetName = "il_raw")]
124-
public int IntegrityLevelRaw { get; set; }
126+
public int[] IntegrityLevelRaw { get; set; }
125127

126128
/// <summary>
127129
/// <para type="description">Create a SID from App Container package name.</para>
128130
/// </summary>
129131
[Parameter(Mandatory = true, ParameterSetName = "package")]
130-
public string PackageName { get; set; }
132+
public string[] PackageName { get; set; }
131133

132134
/// <summary>
133135
/// <para type="description">Specify an additional restricted name for the package SID.</para>
@@ -145,7 +147,7 @@ public class GetNtSidCmdlet : PSCmdlet
145147
/// <para type="description">Get a known SID.</para>
146148
/// </summary>
147149
[Parameter(Mandatory = true, ParameterSetName = "known")]
148-
public KnownSidValue KnownSid { get; set; }
150+
public KnownSidValue[] KnownSid { get; set; }
149151

150152
/// <summary>
151153
/// <para type="description">Get the SID from the current user token. Defaults to the user SID.</para>
@@ -187,7 +189,7 @@ public class GetNtSidCmdlet : PSCmdlet
187189
/// <para type="description">Create a SID from App Container capability name.</para>
188190
/// </summary>
189191
[Parameter(Mandatory = true, ParameterSetName = "cap")]
190-
public string CapabilityName { get; set; }
192+
public string[] CapabilityName { get; set; }
191193

192194
/// <summary>
193195
/// <para type="description">Returns the group capability SID rather than normal capability SID.</para>
@@ -271,107 +273,109 @@ public class GetNtSidCmdlet : PSCmdlet
271273
/// </summary>
272274
protected override void ProcessRecord()
273275
{
274-
Sid sid;
276+
IEnumerable<Sid> sids;
275277
switch (ParameterSetName)
276278
{
277279
case "sddl":
278-
sid = new Sid(Sddl);
280+
sids = Sddl.Select(s => new Sid(s));
279281
break;
280282
case "name":
281-
sid = NtSecurity.LookupAccountName(Name);
283+
sids = Name.Select(s => NtSecurity.LookupAccountName(s));
282284
break;
283285
case "service":
284-
sid = NtSecurity.GetServiceSid(ServiceName);
286+
sids = ServiceName.Select(s => NtSecurity.GetServiceSid(s));
285287
break;
286288
case "il":
287-
sid = NtSecurity.GetIntegritySid(IntegrityLevel);
289+
sids = IntegrityLevel.Select(s => NtSecurity.GetIntegritySid(s));
288290
break;
289291
case "il_raw":
290-
sid = NtSecurity.GetIntegritySidRaw(IntegrityLevelRaw);
292+
sids = IntegrityLevelRaw.Select(s => NtSecurity.GetIntegritySidRaw(s));
291293
break;
292294
case "package":
293-
sid = TokenUtils.DerivePackageSidFromName(PackageName);
295+
sids = PackageName.Select(s => TokenUtils.DerivePackageSidFromName(s));
294296
if (RestrictedPackageName != null)
295297
{
296-
sid = TokenUtils.DeriveRestrictedPackageSidFromSid(sid, RestrictedPackageName);
298+
sids = sids.Select(s => TokenUtils.DeriveRestrictedPackageSidFromSid(s, RestrictedPackageName));
297299
}
298300
if (AsCapability)
299301
{
300-
sid = NtSecurity.PackageSidToCapability(sid);
302+
sids = sids.Select(s => NtSecurity.PackageSidToCapability(s));
301303
}
302304
break;
303305
case "known":
304-
sid = KnownSids.GetKnownSid(KnownSid);
306+
sids = KnownSid.Select(s => KnownSids.GetKnownSid(s));
305307
break;
306308
case "token":
307309
using (NtToken token = NtToken.OpenProcessToken())
308310
{
311+
Sid temp = null;
309312
if (PrimaryGroup)
310313
{
311-
sid = token.PrimaryGroup;
314+
temp = token.PrimaryGroup;
312315
}
313316
else if (Owner)
314317
{
315-
sid = token.Owner;
318+
temp = token.Owner;
316319
}
317320
else if (LogonGroup)
318321
{
319-
sid = token.LogonSid.Sid;
322+
temp = token.LogonSid.Sid;
320323
}
321324
else if (AppContainer)
322325
{
323-
sid = token.AppContainerSid;
326+
temp = token.AppContainerSid;
324327
}
325328
else if (Label)
326329
{
327-
sid = token.IntegrityLevelSid.Sid;
330+
temp = token.IntegrityLevelSid.Sid;
328331
}
329332
else
330333
{
331-
sid = token.User.Sid;
334+
temp = token.User.Sid;
332335
}
336+
sids = new[] { temp };
333337
}
334338
break;
335339
case "cap":
336-
sid = CapabilityGroup ? NtSecurity.GetCapabilityGroupSid(CapabilityName)
337-
: NtSecurity.GetCapabilitySid(CapabilityName);
340+
sids = CapabilityName.Select(s => CapabilityGroup ? NtSecurity.GetCapabilityGroupSid(s)
341+
: NtSecurity.GetCapabilitySid(s));
338342
break;
339343
case "sid":
340-
sid = new Sid(SecurityAuthority, RelativeIdentifier ?? new uint[0]);
344+
sids = new[] { new Sid(SecurityAuthority, RelativeIdentifier ?? new uint[0]) };
341345
break;
342346
case "rawsa":
343-
sid = new Sid(new SidIdentifierAuthority(SecurityAuthorityByte), RelativeIdentifier);
347+
sids = new[] { new Sid(new SidIdentifierAuthority(SecurityAuthorityByte), RelativeIdentifier) };
344348
break;
345349
case "logon":
346-
sid = NtSecurity.GetLogonSessionSid();
350+
sids = new[] { NtSecurity.GetLogonSessionSid() };
347351
break;
348352
case "trust":
349-
sid = NtSecurity.GetTrustLevelSid(TrustType, TrustLevel);
353+
sids = new[] { NtSecurity.GetTrustLevelSid(TrustType, TrustLevel) };
350354
break;
351355
case "ace":
352-
sid = AccessControlEntry.Sid;
356+
sids = AccessControlEntry.Select(a => a.Sid);
353357
break;
354358
case "relsid":
355-
sid = Sibling ? BaseSid.CreateSibling(RelativeIdentifier) : BaseSid.CreateRelative(RelativeIdentifier);
359+
sids = new[] { Sibling ? BaseSid.CreateSibling(RelativeIdentifier) : BaseSid.CreateRelative(RelativeIdentifier) };
356360
break;
357361
case "bytes":
358-
sid = new Sid(Byte);
362+
sids = new[] { new Sid(Byte) };
359363
break;
360364
default:
361365
throw new ArgumentException("No SID type specified");
362366
}
363367

364368
if (AsSddl)
365369
{
366-
WriteObject(sid.ToString());
370+
WriteObject(sids.Select(s => s.ToString()), true);
367371
}
368372
else if (AsName)
369373
{
370-
WriteObject(sid.Name);
374+
WriteObject(sids.Select(s => s.Name), true);
371375
}
372376
else
373377
{
374-
WriteObject(sid);
378+
WriteObject(sids, true);
375379
}
376380
}
377381
}

0 commit comments

Comments
 (0)