Esempio n. 1
0
        /*public override string ToString()
         * {
         *  try
         *  {
         *
         *      StringBuilder output = new StringBuilder(1024);
         *      if (isAgentProcessRunning && isAgentServiceRunning)
         *      {
         *          output.Append(Html.Error("The agent is running both as a process and a service!")
         + AgentServiceOpenedPorts + AgentProcessOpenedPorts);
         +      }
         +      else
         +      {
         +        if (isAgentProcessRunning || isAgentServiceRunning)
         +          output.Append("Currently running." + AgentServiceOpenedPorts + AgentProcessOpenedPorts);
         +        else
         +          output.Append("Not running!");
         +      }
         +
         +      return output.ToString();
         +  }
         +  catch (Exception ex)
         +  {
         +      Logger.Error(ex.ToString());
         +      return ex.Message;
         +  }
         + }*/
        #endregion

        #region Method to display the agent status information
        internal string GetAgentStatus()
        {
            try
            {
                StringBuilder output = new StringBuilder(1024);
                if (isAgentProcessRunning && isAgentServiceRunning)
                {
                    output.Append(Html.Error("The agent is running both as a process and a service!")
                                  + AgentServiceOpenedPorts + AgentProcessOpenedPorts);
                }
                else
                {
                    if (isAgentProcessRunning || isAgentServiceRunning)
                    {
                        output.Append("Status: " + Html.Notice("Running") + AgentServiceOpenedPorts + AgentProcessOpenedPorts);
                    }
                    else
                    {
                        output.Append("Not running!");
                    }
                }

                return(output.ToString());
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                return(ex.Message);
            }
        }
Esempio n. 2
0
        public static string GetServiceInfo(string serviceName, string processName = "")
        {
            try
            {
                if (processName == "")
                {
                    processName = serviceName;
                }

                int    agentProcessId     = 0;
                string agentProcessOwnder = string.Empty;
                string agentProcessPath   = string.Empty;


                ServiceController sc = new ServiceController(serviceName);

                Logger.Info("status " + serviceName + sc.Status);
                switch (sc.Status)
                {
                case ServiceControllerStatus.Running:
                case ServiceControllerStatus.StartPending:
                case ServiceControllerStatus.StopPending:
                    string processId = Helper.QueryWMI("ProcessId", "root\\CIMV2", "Win32_Service", "WHERE Name='" + serviceName + "'");
                    Logger.Info("ProcessId for  " + processName + " is " + processId);
                    if (!processId.Contains("Error") && !processId.Contains("Not detected"))
                    {
                        agentProcessId     = Convert.ToInt32(processId);
                        agentProcessOwnder = Helper.GetProcessOwner(agentProcessId);
                    }
                    agentProcessPath = Helper.QueryWMI("PathName", "root\\CIMV2", "Win32_Service", "WHERE Name='" + serviceName + "'");
                    Logger.Info("agentProcessPath for  " + processName + " is " + agentProcessPath);
                    break;

                case ServiceControllerStatus.Stopped:
                case ServiceControllerStatus.Paused:
                    break;
                }


                var status = sc.Status.ToString().Contains("Running") ? Html.Notice(sc.Status.ToString()) : sc.Status.ToString();
                status = status.Contains("Stopped") || status.Contains("Paused") ? Html.Error(status) : status;

                var openedPorts = agentProcessId != 0 ? Helper.GetOpenedPortsForProcessId(agentProcessId) : "";

                return("Status: " + status + Html.br
                       + Html.B("Details: ") + Html.br
                       + Html.U("PID: " + agentProcessId + " " + agentProcessOwnder) + Html.br
                       + "Path: " + agentProcessPath + openedPorts);
            }
            catch (InvalidOperationException)
            {
                return(Html.Warning("Service not installed on this computer!"));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                return(ex.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Method to return Service name and status
        /// </summary>
        /// <param name="AgentCaption"></param>
        /// <returns></returns>
        public static string FormatServiceNameStatus(string agentCaption, string status = null)
        {
            if (status == null || status != "Running")
            {
                status = GetServiceStatus(agentCaption);
            }
            if (status == "Running")
            {
                status = Html.Notice(status);
            }

            return(agentCaption + " status: " + status);
        }
Esempio n. 4
0
        /// <summary>
        /// Method to execute netstat command to list the ports opened for given process id.
        /// 1. Execute the netstat -ano | findstr /e process_id (matches all lines ending with process_id
        /// 2. Create an array by splitting the output by \r, \n, \t, ' ', ':'
        /// 3. Loop through the array values and if valuee==process_id get the necessary information
        /// </summary>
        /// <param name="processId"></param>
        /// <returns></returns>
        public static string GetOpenedPortsForProcessId(int processId)
        {
            try
            {
                StringBuilder portInfo = new StringBuilder(128);
                if (processId > 0)
                {
                    string netstatOutput = Helper.ExecuteCMDCommand("netstat -anop tcp | findstr /e " + processId);

                    if (netstatOutput.Contains(processId.ToString()))
                    {
                        Logger.Info("Ports for process ID " + processId + ":\r\n" + netstatOutput);
                        // split the output by \r\n
                        char[]   delimiter = new Char[] { ' ', '\t', '\r', ':' };
                        string[] parts     = netstatOutput.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);

                        for (int i = 0; i < parts.Length; i++)
                        {
                            if (parts[i] == processId.ToString())
                            {
                                string status = String.Empty;
                                switch (parts[i - 1])
                                {
                                case "LISTENING": //english
                                case "ABH™REN":   //german
                                    status = Html.Notice("LISTENING");
                                    break;

                                case "ESTABLISHED": //english
                                case "HERGESTELLT": //german
                                    status = Html.B("ESTABLISHED");
                                    break;

                                default:
                                    status = parts[i - 1];
                                    break;
                                }
                                portInfo.Append(Html.br + "Port: " + parts[i - 4] + " " + status);
                            }
                        }
                    }
                }
                return(portInfo.ToString() + Html.br);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString());
                return(null);
            }
        }
Esempio n. 5
0
        public static string GetInfoForService(string serviceName)
        {
            string message = null;

            try
            {
                ServiceController sc = new ServiceController(serviceName);
                var status           = sc.Status.ToString();
                message = status == "Running" ? Html.Notice(status) : status;
            }
            catch (System.InvalidOperationException sioex)
            {
                Logger.Error(sioex.ToString());
                message = Html.Error("Not found on this computer");
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                message = Html.ErrorMsg();
            }
            return(String.Format("{0}{1}{2} Status: {3}", Html.br, Html.tab, serviceName, message));
        }
Esempio n. 6
0
            public AgentDriver()
            {
                var wmiObject = Helper.GetWMIObject("root\\CIMV2", "Win32_SystemDriver", "WHERE DisplayName = 'paldrv'");

                Logger.Debug(String.Format("wmiObject:: DisplayName: {0} State: {1} PathName: {2}", wmiObject["DisplayName"], wmiObject["State"], wmiObject["PathName"]));

                //If HP Citrix Agent is installed, check if text trapping driver pal_drv.sys is installed
                isInstalled = wmiObject["DisplayName"].ToString().Equals(displayName);
                if (isInstalled)
                {
                    state = wmiObject["State"].ToString();
                    if (state == "Running" || state == "RUNNING")
                    {
                        state = Html.Notice(state);
                    }

                    path = wmiObject["PathName"].ToString();
                    Logger.Info("WinTrust validating file " + path);
                    SignedInfo = WinTrust.IsFileSignedInfo(path);

                    GetFileVersion();
                }
            }
Esempio n. 7
0
        internal static string FormatOutput(string commandOutput, string pid)
        {
            StringBuilder output = new StringBuilder();

            if (commandOutput.Length > 0)
            {
                string[] lines = commandOutput.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                output.Append(lines.Length - 1 + " connections found" + Html.br);
                //output.Append("TYPE CONTROLLER_IP:PORT LG_IP:PORT" + Html.br);
                foreach (var line in lines)
                {
                    output.Append(line.Replace(pid, Html.br).Replace("TCP", Html.B("TCP")).Replace("ESTABLISHED", Html.Notice("ESTABLISHED")).Replace("HERGESTELLT", Html.Notice("HERGESTELLT")));
                }
            }

            return(output.ToString());
        }