Skip to content

Commit

Permalink
Merge pull request #174 from gerardog/Fix.NonAdminToSystem
Browse files Browse the repository at this point in the history
Fix: Elevation to System from non-admin account
  • Loading branch information
gerardog authored Sep 9, 2022
2 parents c71dac5 + d4c8612 commit afc9ccd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/gsudo/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ private static bool IsElevationRequired()
/// <returns></returns>
private static ElevationRequest.ConsoleMode GetElevationMode(bool isWindowsApp)
{
if (!ProcessHelper.IsMemberOfLocalAdmins() || // => Not local admin? Force attached mode, so the new process has admin user env vars. (See #113)
Settings.ForceAttachedConsole)
if ((!ProcessHelper.IsMemberOfLocalAdmins() || // => Not local admin? Force attached mode, so the new process has admin user env vars. (See #113)
Settings.ForceAttachedConsole) && !Settings.ForcePipedConsole && !Settings.ForceVTConsole)
{
if (Console.IsErrorRedirected
|| Console.IsInputRedirected
Expand All @@ -254,6 +254,8 @@ private static ElevationRequest.ConsoleMode GetElevationMode(bool isWindowsApp)
// Attached mode doesnt supports redirection.
return ElevationRequest.ConsoleMode.Piped;
}
if (InputArguments.TrustedInstaller)
return ElevationRequest.ConsoleMode.VT; // workaround for #173

return ElevationRequest.ConsoleMode.Attached;
}
Expand Down
5 changes: 3 additions & 2 deletions src/gsudo/Commands/ServiceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public async Task<int> Execute()

Console.Title = "gsudo Service";

if (InputArguments.TrustedInstaller && !System.Security.Principal.WindowsIdentity.GetCurrent().Claims.Any(c => c.Value == Constants.TI_SID))
if ((InputArguments.TrustedInstaller && !System.Security.Principal.WindowsIdentity.GetCurrent().Claims.Any(c => c.Value == Constants.TI_SID))
|| (InputArguments.RunAsSystem && !System.Security.Principal.WindowsIdentity.GetCurrent().IsSystem))
{
return Helpers.ServiceHelper.StartElevatedService(AllowedPid, CacheDuration, singleUse: SingleUse) ? 0: Constants.GSUDO_ERROR_EXITCODE;
return Helpers.ServiceHelper.StartElevatedService(AllowedPid, CacheDuration, singleUse: SingleUse, allowedSid: AllowedSid) ? 0: Constants.GSUDO_ERROR_EXITCODE;
}

var cacheLifetime = new CredentialsCacheLifetimeManager(AllowedPid);
Expand Down
3 changes: 1 addition & 2 deletions src/gsudo/Helpers/ServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ internal static bool StartElevatedService(int? allowedPid, TimeSpan? cacheDurati

var @params = InputArguments.Debug ? "--debug " : string.Empty;
// if (InputArguments.IntegrityLevel.HasValue) @params += $"-i {InputArguments.IntegrityLevel.Value} ";
// if (InputArguments.RunAsSystem) @params += "-s ";

if (InputArguments.RunAsSystem && allowedSid != System.Security.Principal.WindowsIdentity.GetCurrent().User.Value) @params += "-s ";
if (InputArguments.TrustedInstaller) @params += "--ti ";

verb = "gsudoservice";
Expand Down

0 comments on commit afc9ccd

Please sign in to comment.