public void SpecialCharacters() { var c = new ExecConfig("\"C:\\Program Files (x86)\\Windows Media Player\\wmplayer.exe\" --arg1 -arg2 /arg3 arg4"); Assert.AreEqual("\"C:\\Program Files (x86)\\Windows Media Player\\wmplayer.exe\"", c.ProgramPath); Assert.AreEqual(" --arg1 -arg2 /arg3 arg4", c.Arguments); }
public void Arguments() { var c = new ExecConfig(@"C:\Windows\System32\cmd.exe --arg1 -arg2 /arg3 arg4"); Assert.AreEqual(@"C:\Windows\System32\cmd.exe", c.ProgramPath); Assert.AreEqual(@" --arg1 -arg2 /arg3 arg4", c.Arguments); }
protected override async Task ProcessRecordAsync() { var id = Id ?? Container.ID; var execConfig = new ExecConfig() { Cmd = Command, Privileged = Privileged, User = User, AttachStdin = !Detached && Input, AttachStdout = !Detached, AttachStderr = !Detached, Detach = Detached, Tty = Terminal, }; var procCreateResponse = await DkrClient.Containers.ExecCreateContainerAsync(id, new ContainerExecCreateParameters(execConfig)); if (Detached) { await DkrClient.Containers.StartContainerExecAsync(procCreateResponse.ID, CmdletCancellationToken); WriteObject(await DkrClient.Containers.InspectContainerExecAsync(procCreateResponse.ID, CmdletCancellationToken)); } else { using (var stream = await DkrClient.Containers.StartWithConfigContainerExecAsync(procCreateResponse.ID, execConfig, CmdletCancellationToken)) { await stream.CopyToConsoleAsync(Terminal, Input, CmdletCancellationToken); } } }
public void NormalCase() { var c = new ExecConfig(@"C:\Windows\System32\cmd.exe"); Assert.AreEqual(@"C:\Windows\System32\cmd.exe", c.ProgramPath); Assert.AreEqual(@"", c.Arguments); Assert.AreEqual(ExecLaunchPrivilegeLevel.Normal, c.ExecLaunchPrivilegeLevel); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); }
private void Run(ExecConfig e, string section, int seq, bool isAsync = true) { ProgramWrapper wrapper; if (Globals.Config.User == null || e.ExecLaunchPrivilegeLevel == ExecLaunchPrivilegeLevel.IgnoreUser || e.ExecLaunchPrivilegeLevel == ExecLaunchPrivilegeLevel.Full) { wrapper = new ManagedProgramWrapper(e.ProgramPath, e.Arguments); wrapper.Start(); } else { // Get the privilege for impersonation var currentProcess = new CProcess(); if (!currentProcess.SetPrivilege("SeTcbPrivilege", true)) { throw new InvalidOperationException("Required privilege SeTcbPrivilege failed"); } if (!currentProcess.SetPrivilege("SeDelegateSessionUserImpersonatePrivilege", true)) { throw new InvalidOperationException("Required privilege SeDelegateSessionUserImpersonatePrivilege failed"); } // Get the identity we needed var identity = new WindowsIdentity(Globals.Config.User); if (identity.ImpersonationLevel != TokenImpersonationLevel.Impersonation) { throw new InvalidOperationException("Insufficient permission"); } // Run the helper process as that identity using (identity.Impersonate()) { LogMuxer.Instance.Debug($"After impersonation, User={WindowsIdentity.GetCurrent().Name}, ImpersonationLevel={identity.ImpersonationLevel}");; wrapper = new NativeProgramWrapper(section, seq, identity.Token); wrapper.Start(); } } if (isAsync) { _programPool.Add(wrapper); wrapper.ProgramExited += SubprocessQuit; } else { wrapper.WaitForExit(); } }
public void Modifiers() { const string defPath = @"C:\Windows\System32\cmd.exe"; ExecConfig c; // @ only c = new ExecConfig("@" + defPath); Assert.AreEqual(true, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Normal, c.ExecLaunchPrivilegeLevel); // - only c = new ExecConfig("-" + defPath); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(true, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Normal, c.ExecLaunchPrivilegeLevel); // + only c = new ExecConfig("+" + defPath); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Full, c.ExecLaunchPrivilegeLevel); // ! only c = new ExecConfig("!" + defPath); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.IgnoreUser, c.ExecLaunchPrivilegeLevel); // !! only c = new ExecConfig("!!" + defPath); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Least, c.ExecLaunchPrivilegeLevel); // mix order c = new ExecConfig("!!@" + defPath); Assert.AreEqual(true, c.IgnoreFirstArg); Assert.AreEqual(false, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Least, c.ExecLaunchPrivilegeLevel); c = new ExecConfig("-+" + defPath); Assert.AreEqual(false, c.IgnoreFirstArg); Assert.AreEqual(true, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Full, c.ExecLaunchPrivilegeLevel); c = new ExecConfig("@-!!" + defPath); Assert.AreEqual(true, c.IgnoreFirstArg); Assert.AreEqual(true, c.IgnoreFailure); Assert.AreEqual(ExecLaunchPrivilegeLevel.Least, c.ExecLaunchPrivilegeLevel); }
public async Task <MultiplexedStream> StartWithConfigContainerExecAsync(string id, ExecConfig eConfig, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } var data = new JsonRequestContent <ContainerExecStartParameters>(new ContainerExecStartParameters(eConfig), this._client.JsonSerializer); var stream = await this._client.MakeRequestForHijackedStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, null, data, cancellationToken).ConfigureAwait(false); if (!stream.CanCloseWrite) { stream.Dispose(); throw new NotSupportedException("Cannot shutdown write on this transport"); } return(new MultiplexedStream(stream, !eConfig.Tty)); }