Beispiel #1
0
 public StdIORedir(Process2ProcessComm p2pTODO, Process2ProcessComm p2pResult, DataHRunConredir R)
 {
     this.consoleendSetResultStacked = p2pResult;
     this.consoleendGetTODOStacked   = p2pTODO;
     this.Filename = R.File;
     this.Args     = R.Args;
 }
Beispiel #2
0
        void InternalThreadAgentEnd()
        {
            Int64 W32Res;

            if (Process2ProcessComm.InvokeRunConsoleRedir(Filename, Args, out W32Res, out runningdata) == false)
            {
                TellMGMTSessionTerminated();
                MainSTDIORedir.RemoveSession(SessionID);
                return;
            }

            do
            {
                Push_Stdio_StdOut r = runningdata.p2pGetResultStacked.GetResultStacked <Push_Stdio_StdOut>();
                if (r == null)
                {
                    if (runningdata.proc.HasExited == true)
                    {
                        TellMGMTSessionTerminated();
                        MainSTDIORedir.RemoveSession(SessionID);
                        break;
                    }
                }
                else
                {
                    net.ResponsePushData1(r, "stdio", 0, "stdio-" + SessionID);
                }
            } while (true);

            runningdata.p2pGetResultStacked.ClosePipe();
            runningdata.p2pSetTODOStacked.ClosePipe();
        }
Beispiel #3
0
        public static void RunPipeConsoleEnd(Process2ProcessComm resp2p, DataHRunConredir R)
        {
            Process2ProcessComm todop2p = new Process2ProcessComm();

            if (todop2p.ConnectPipe(R.TODOPipeGUID) == false)
            {
                Debug.WriteLine("Cannot get 2nd Pipe");
                return;
            }

            StdIORedir rr = new StdIORedir(todop2p, resp2p, R);

            rr.RunConsoleEnd();
        }
Beispiel #4
0
        public static PushRunTaskResult RunTask(string ReqString, Network net)
        {
            PushRunTaskResult Res = new PushRunTaskResult();
            PushRunTask       req;

            try
            {
                req = JsonConvert.DeserializeObject <PushRunTask>(ReqString);
            }
            catch (Exception ee)
            {
                Debug.WriteLine(ee.ToString());
                Res.Result = 0x16;
                return(Res);
            }

            Res.Result = 0;
#if !DEBUG || DEBUGSERVICE
            int ProcessID;
#endif

            switch (req.Option)
            {
            case PushRunTaskOption.ActualUser:
#if !DEBUG || DEBUGSERVICE
                if (SystemInfos.SysInfo.RunningInWindowsPE == true)
                {
                    if (ProgramAgent.CPP.StartAppInWinLogon(req.Executable, req.Args, out ProcessID) == false)
                    {
                        Res.Result = ProgramAgent.CPP.WGetLastError();
                    }
                }
                else
                {
                    if (ProgramAgent.CPP.StartAppAsUser(req.Executable, req.Args, req.SessionID) == false)
                    {
                        Res.Result = ProgramAgent.CPP.WGetLastError();
                    }
                }
#else
                //Crude: since we cannot use WTSQueryUserToken function as normal user / nor admin user
                try
                {
                    Process.Start(req.Executable, req.Args);
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                }
#endif
                break;

            case PushRunTaskOption.OtherUser:
                DataHRunasUserResult ores;
                if (Process2ProcessComm.InvokeRunAsUser(req.Executable, req.Args, req.Username, req.Password, req.SessionID, out ores, out Res.Result) == true)
                {
                    Res.Result = ores.Result;
                }
                break;

            case PushRunTaskOption.SystemUserConsoleRedir:
                Res.SessionID = Redirs.MainSTDIORedir.StartRedir(req.Executable, req.Args, net);
                if (string.IsNullOrWhiteSpace(Res.SessionID) == true)
                {
                    Res.Result = 0x8000FFFF;
                }
                else
                {
                    Res.Result = 0;
                }
                break;

            case PushRunTaskOption.StealWinlogonToken:
#if !DEBUG || DEBUGSERVICE
                if (RegistryData.DangerousFunctions == true)
                {
                    if (ProgramAgent.CPP.StartAppInWinLogon(req.Executable, req.Args, out ProcessID) == false)
                    {
                        Res.Result = ProgramAgent.CPP.WGetLastError();
                    }
                }
                else
                {
                    Res.Result = 0x8000FFFF;
                }
#endif
                break;
            }


            return(Res);
        }