Example #1
0
        public static bool RegisterClientWithServer(string taskCode, byte[] output)
        {
            //Registration.ClientRegistrar.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return(false);
                }
                else
                {
                    if (outputMsg == "InvalidID")
                    {
                        return(false);
                    }
                }
                ConfigHandler.HostInfoes        = new HostInfo();
                ConfigHandler.HostInfoes.HostID = SplitHeader(outputMsg);
                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(string.Empty);
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //Registration.ClientRegistrar.Logger.Info("Exit");
            return(true);
        }
Example #2
0
        public static void UpdateClientInfo(object updateGetObj)
        {
            ThreadPoolCommonClass common = (ThreadPoolCommonClass)updateGetObj;
            SystemConfiguration   sysConfig;
            string tempConfig = Encoding.ASCII.GetString(common.Output);

            sysConfig = JsonConvert.DeserializeObject <SystemConfiguration>(tempConfig);

            string tempHostName;

            UpdateClient.TryGetValue(UpdateClient.Keys.ElementAt(common.ThreadIndx), out tempHostName);
            sysConfig.HostName = tempHostName;

            byte[]      configByte = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(sysConfig));
            StateObject stateObj   = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);
                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(common.TaskCode, configByte.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx));
                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, configByte);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }
                else
                {
                    if (outputMsg == "Invalid ID")
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }
Example #3
0
        public static bool UpdateClientInfo(string taskCode, byte[] output)
        {
            //SystemInfoUpdater.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);
                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return(false);
                }
                else
                {
                    if (outputMsg == "Invalid ID")
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                //SystemInfoUpdater.Logger.Error(ex);
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //SystemInfoUpdater.Logger.Info("Exit");
            return(true);
        }
Example #4
0
        public static void SearchConfigChangeInServer(string taskCode, byte[] output)
        {
            //ConfigurationDetector.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                // TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }

                if (outputMsg == "InvalidID")
                {
                    return;
                }

                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(outputMsg);
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }

            //ConfigurationDetector.Logger.Info("Exit");
        }
Example #5
0
        public static void SearchConfigChangeInServer(object obj)
        {
            StateObject           stateObj = null;
            ThreadPoolCommonClass common   = (ThreadPoolCommonClass)obj;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(common.TaskCode, common.Output.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx));

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                TcpUtil.WriteData(stateObj.ClientStream, common.Output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }

                if (outputMsg == "InvalidID")
                {
                    return;
                }
                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(outputMsg);
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }
Example #6
0
        public static bool SendLazyPacketsToServer(string taskCode, byte[] output, bool isFromLazy = true)
        {
            //Lazy.//LazyAnalyserSender.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                if (output.Length > 0)
                {
                    byte[] headerBytes = BuildHeaders(taskCode, output.Length);

                    TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                    TcpUtil.WriteData(stateObj.ClientStream, output);
                }
            }
            catch (Exception ex)
            {
                //Lazy.//LazyAnalyserSender.Logger.Info(ex);
                if (isFromLazy && output != null)
                {
                    FailHandler.LazyFailHandler.InsertInLazyFailed(output);
                }
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //Lazy.//LazyAnalyserSender.Logger.Info("Exit");
            return(true);
        }
Example #7
0
        public static bool SendAlertMessageToServer(string taskCode, byte[] output, bool isFromAlert = true)
        {
            //StoredAndForward.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();

                TCPSocket.Connect(stateObj);
                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                if (output.Length > 0)
                {
                    byte[] headerBytes = BuildHeaders(taskCode, output.Length);
                    TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                    TcpUtil.WriteData(stateObj.ClientStream, output);
                }
            }
            catch (Exception ex)
            {
                //StoredAndForward.Logger.Error(ex);
                if (isFromAlert && output != null)
                {
                    FailHandler.AlertFailHandler.InsertInAlertFailed(output);
                }
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //StoredAndForward.Logger.Info("Exit");
            return(true);
        }
Example #8
0
        public static bool GetCertificate(string taskCode)
        {
            //Registration.ClientRegistrar.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.ConnectIgnoreCertError(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);


                // byte[] bodyBytes = Encoding.ASCII.GetBytes("");
                byte[] headerBytes = BuildHeaders(taskCode, 0);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                //TcpUtil.WriteData(stateObj.ClientStream, bodyBytes);

                byte[] bytesOfCert = TcpUtil.ReadDataAsBytes(stateObj.ClientStream);
                Registration.CertHandler.InstallConsoleServerCertificate(bytesOfCert);
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //Registration.ClientRegistrar.Logger.Info("Exit");
            return(true);
        }
Example #9
0
        public static void SendRegistryFetchResults(string taskCode, winaudits.RegistryFetch ofileFetch)
        {
            StateObject stateObj = null;

            try
            {
                int           tryCount = 0;
                StringBuilder sb       = new StringBuilder();
                sb.AppendLine(String.Format("AuditJobid: {0}", ofileFetch.AuditJobID));
                sb.AppendLine(String.Format("AuditJobType: {0}", 3));
                string tempPath = ofileFetch.RegistryPath.Replace("\"", string.Empty).Trim("\\".ToCharArray());

                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                while (tryCount < 5)
                {
                    try
                    {
                        string exportPath32 = Util.Export(ofileFetch.RegistryHive, tempPath, false);

                        sb.AppendLine(String.Format("FileExtension: {0}", ".zip"));
                        var zipStream = new MemoryStream();
                        var zip       = new ZipOutputStream(zipStream);
                        if (exportPath32 != string.Empty && File.Exists(exportPath32))
                        {
                            zip.PutNextEntry(Path.GetFileName(exportPath32));
                            byte[] fileContent = File.ReadAllBytes(exportPath32);
                            zip.Write(fileContent, 0, fileContent.Length);
                        }
                        if (Environment.Is64BitOperatingSystem && !tempPath.Contains("Wow6432Node"))
                        {
                            string exportPath64 = Util.Export(ofileFetch.RegistryHive, tempPath, true);
                            if (exportPath64 != string.Empty && File.Exists(exportPath64))
                            {
                                zip.PutNextEntry(Path.GetFileName(exportPath64));
                                byte[] fileContent = File.ReadAllBytes(exportPath64);
                                zip.Write(fileContent, 0, fileContent.Length);
                            }
                        }

                        zip.Close();
                        byte[] buffer      = zipStream.ToArray();
                        byte[] headerBytes = BuildHeaders(taskCode, (long)buffer.Length, sb.ToString());
                        TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                        if (buffer.Length > 0)
                        {
                            stateObj.ClientStream.Write(buffer);
                            winaudits.UpdateQuery.UpdateRegistryFetchAuditStatus(2, ofileFetch.AuditJobID);
                        }
                        else
                        {
                            winaudits.UpdateQuery.UpdateRegistryFetchAuditStatus(3, ofileFetch.AuditJobID);
                            tryCount = 5;
                        }
                        break;
                    }
                    catch (Exception ex)
                    {
                        tryCount++;
                        //JobsSearcher.Logger.Error(ex);
                    }
                }

                if (tryCount == 5)
                {
                    byte[] headerBytes = BuildHeaders(taskCode, 0, sb.ToString());
                    TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                    winaudits.UpdateQuery.UpdateRegistryFetchAuditStatus(3, ofileFetch.AuditJobID);
                }
                byte[] end = Encoding.ASCII.GetBytes("<EOF>");
                stateObj.ClientStream.Write(end, 0, end.Length);
            }
            catch (Exception ex)
            {
                //JobsSearcher.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }
Example #10
0
        public static void SendFileFetchResults(string taskCode, winaudits.FileFetch ofileFetch)
        {
            StateObject stateObj = null;
            string      tempPath = ofileFetch.FilePath.Replace("\"", string.Empty);
            int         tryCount = 0;

            if (!File.Exists(tempPath))
            {
                tryCount = 5;
            }
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(String.Format("AuditJobid: {0}", ofileFetch.AuditJobID));
                sb.AppendLine(String.Format("AuditJobType: {0}", 2));

                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                while (tryCount < 5)
                {
                    try
                    {
                        using (FileStream stream = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
                        {
                            byte[] buffer = new byte[8192];
                            int    bytesRead;

                            sb.AppendLine(String.Format("FileExtension: {0}", Path.GetExtension(tempPath)));
                            byte[] headerBytes = BuildHeaders(taskCode, (long)stream.Length, sb.ToString());
                            TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                            while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                stateObj.ClientStream.Write(buffer);
                            }
                        }

                        winaudits.UpdateQuery.UpdateFileFetchAuditStatus(2, ofileFetch.AuditJobID);
                        break;
                    }
                    catch (Exception ex)
                    {
                        tryCount++;
                        //JobsSearcher.Logger.Error(ex);
                    }
                }

                if (tryCount == 5)
                {
                    byte[] headerBytes = BuildHeaders(taskCode, 0, sb.ToString());
                    TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                    winaudits.UpdateQuery.UpdateFileFetchAuditStatus(3, ofileFetch.AuditJobID);
                }
                byte[] end = Encoding.ASCII.GetBytes("<EOF>");
                stateObj.ClientStream.Write(end, 0, end.Length);
            }
            catch (Exception ex)
            {
                //JobsSearcher.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }