Skip to content

Commit

Permalink
- Update NamedPipeNameFactory.cs to incorporate system run flag in pi…
Browse files Browse the repository at this point in the history
…pe naming.

- Adjust ServiceHelper.cs to support system run scenarios with target user SID.
  • Loading branch information
gerardog committed Dec 18, 2023
1 parent fd523ce commit 49738f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/gsudo/Helpers/ServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ private static ServiceLocation FindServiceByIntegrity(int? clientPid, string use
var anyIntegrity = InputArguments.UserName != null;
var tryHighIntegrity = !InputArguments.IntegrityLevel.HasValue || InputArguments.IntegrityLevel.Value >= IntegrityLevel.High;
var tryLowIntegrity = !InputArguments.IntegrityLevel.HasValue || InputArguments.IntegrityLevel.Value < IntegrityLevel.High;

var targetUserSid = InputArguments.RunAsSystem ? "S-1-5-18" : InputArguments.UserSid;

if (tryHighIntegrity)
{
var pipeName = NamedPipeClient.TryGetServicePipe(user, clientPid.Value, true);
var pipeName = NamedPipeClient.TryGetServicePipe(user, clientPid.Value, true, null);
if (pipeName != null)
{
return new ServiceLocation
Expand Down
5 changes: 3 additions & 2 deletions src/gsudo/Rpc/NamedPipeNameFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public static string GetPipeName(string allowedSid, int allowedPid, string targe
if (allowedPid < 0) allowedPid = 0;

var ti = InputArguments.TrustedInstaller ? "_TI" : string.Empty;
var admin = !isAdmin ? "_NonAdmin" : string.Empty;
var s = InputArguments.RunAsSystem ? "_S" : string.Empty;
var admin = !isAdmin ? "_NonAdmin" : string.Empty;

var data = $"{allowedSid}_{targetSid}_{allowedPid}_{ti}{admin}";
var data = $"allowedSid-{allowedSid}_targetSid-{targetSid}{allowedPid}{s}{ti}{admin}";
#if !DEBUG
data = GetHash(data);
#endif
Expand Down

0 comments on commit 49738f0

Please sign in to comment.