Ejemplo n.º 1
0
        public bool Object_builder(string path_to_file)
        {
            CheckFile  chck_file  = new CheckFile(path_to_file);
            ScanObject scanObject = new ScanObject();

            if (chck_file.IsFilePE())
            {
                return(scanObject.Read(1, path_to_file));
            }
            else
            {
                if (chck_file.IsFileZip())
                {
                    return(scanObject.Read(2, path_to_file));
                }
                else
                {
                    if (chck_file.IsFileDir())
                    {
                        return(scanObject.Read(3, path_to_file));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool findFirstorLastScan(long projectId, ScanObject scan, Dictionary <string, Teams> teams, Dictionary <long, ReportStaging> keyValuePairs, bool operation)
        {
            getScans scans = new getScans();

            string fullName = teams[scan.OwningTeamId].fullName;

            if (keyValuePairs.ContainsKey(scan.Project.Id))
            {
                bool          start         = false;
                ReportStaging reportStaging = keyValuePairs[scan.Project.Id];
                long          diff          = DateTimeOffset.Compare(reportStaging.dateTime, (DateTimeOffset)scan.DateAndTime.StartedOn);
                if (operation)
                {
                    start = (diff > 0) ? true : false;
                }
                else
                {
                    start = (diff < 0) ? true : false;
                }
                if (start)
                {
                    ScanStatistics scanStatistics = scans.getScansStatistics(scan.Id, token);
                    ReportStaging  staging        = new ReportStaging()
                    {
                        ProjectId   = scan.Project.Id,
                        ProjectName = scan.Project.Name,
                        TeamName    = fullName,
                        dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                        High        = scanStatistics.HighSeverity,
                        Medium      = scanStatistics.MediumSeverity,
                        Low         = scanStatistics.LowSeverity,
                        ScanId      = scan.Id
                    };
                    keyValuePairs[scan.Project.Id] = staging;
                }
            }
            else
            {
                ScanStatistics scanStatistics = scans.getScansStatistics(scan.Id, token);
                keyValuePairs.Add(scan.Project.Id, new ReportStaging()
                {
                    ProjectId   = scan.Project.Id,
                    ProjectName = scan.Project.Name,
                    TeamName    = fullName,
                    dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                    High        = scanStatistics.HighSeverity,
                    Medium      = scanStatistics.MediumSeverity,
                    Low         = scanStatistics.LowSeverity,
                    ScanId      = scan.Id
                });
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool matchProjectandTeam(ScanObject s, List <Teams> teams)
        {
            bool     result = false;
            getScans scans  = new getScans();

            string fullName = scans.getFullName(teams, s.OwningTeamId);

            if ((String.IsNullOrEmpty(token.project_name) || ((!String.IsNullOrEmpty(token.project_name)) && (s.Project.Name.Contains(token.project_name)))))
            {
                if ((String.IsNullOrEmpty(token.team_name) || ((!String.IsNullOrEmpty(token.team_name)) && (!String.IsNullOrEmpty(fullName)) && (fullName.Contains(token.team_name)))))
                {
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public bool filter_scans(resultClass token, int max_scans, bool onlyOne = false)
        {
            getScans                      scans    = new getScans();
            List <ScanObject>             outScans = new List <ScanObject>();
            List <ScanObject>             pscans   = new List <ScanObject>();
            Dictionary <long, ScanObject> lastOne  = new Dictionary <long, ScanObject>();

            foreach (ProjectObject project in CxProjects)
            {
                List <ScanObject> temp = (max_scans > 0) ? scans.getLastScanbyId(token, project.id, max_scans) : scans.getScanbyId(token, project.id);
                if (onlyOne)
                {
                    long       topScan       = 0;
                    ScanObject topScanObject = null;
                    foreach (ScanObject so in temp)
                    {
                        if (so.Id > topScan)
                        {
                            topScan       = so.Id;
                            topScanObject = so;
                        }
                    }
                    if (topScanObject != null)
                    {
                        pscans.Add(topScanObject);
                    }
                }
                else
                {
                    pscans.AddRange(temp);
                }
            }
            foreach (ScanObject s in pscans)
            {
                if ((s.DateAndTime != null) && (s.Status.Id == 7) && (s.DateAndTime.StartedOn > token.start_time) && (s.DateAndTime.StartedOn < token.end_time))
                {
                    get_result_statistics(token, s.Id);
                    outScans.Add(s);
                }
            }

            CxScans = outScans;

            return(true);
        }
Ejemplo n.º 5
0
        public DataDisplay(Control ctrl, ScanObject obj)
        {
            this.imageScale       = 1.0F;
            this.ProbeWidth       = 1.0F;
            this.passiveColor     = Color.SlateBlue;
            this.selectedColor    = Color.RosyBrown;
            this.activeColor      = Color.Red;
            this.activePointColor = this.activeColor;
            this.forwardTransform = new Matrix();
            this.inverseTransform = new Matrix();
            this.selectedPoints   = new List <int>();
            this.activePoint      = -1;

            this.state      = DisplayState.Empty;
            this.scanObject = obj;
            if (this.scanObject.IsInitialized)
            {
                this.state = DisplayState.NoSelection;
            }
            this.control = ctrl;
        }
        /// <summary>
        /// Scan device and get the settings
        /// </summary>
        /// <returns>object populated with the device settings</returns>
        public ScanDeviceResponse ScanDevice()
        {
            String message = "Received request to ScanDevice()";

            Tracer.WriteInfo(message);
            Tracer.WriteUserLog(message);

            // Initialize Response
            ScanDeviceResponse response = new ScanDeviceResponse();

            try
            {
                // Initialize Scope
                Microsoft.GFS.WCS.ChassisManager.ScanDevice.InitializeScope();

                // Populate all services on the device
                response.Services = Microsoft.GFS.WCS.ChassisManager.ScanDevice.ListAllServices();

                // Populate all users on the device
                response.Users = Microsoft.GFS.WCS.ChassisManager.ScanDevice.ListAllUsers();

                // Populate all groups after scanning the device
                response.UserGroups = Microsoft.GFS.WCS.ChassisManager.ScanDevice.ListAllGroupsAndMembers();

                // Get windows firewall setting
                ScanObject firewallSettingObj = new ScanObject();
                firewallSettingObj.Attribute = "Windows Firewall Enable Status";
                firewallSettingObj.Value = Microsoft.GFS.WCS.ChassisManager.ScanDevice.IsWindowsFirewallEnabled().ToString();
                if (!String.IsNullOrEmpty(firewallSettingObj.Value))
                {
                    firewallSettingObj.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    firewallSettingObj.completionCode = Contracts.CompletionCode.Failure;
                    firewallSettingObj.statusDescription = "Unable to get Firewall settings";
                }
                response.ScanObjects.Add(firewallSettingObj);

                // Get windows update setting
                ScanObject windowsUpdateSettingObj = new ScanObject();
                windowsUpdateSettingObj.Attribute = "Windows Update Enable Status";
                windowsUpdateSettingObj.Value = Microsoft.GFS.WCS.ChassisManager.ScanDevice.IsWindowsUpdateEnabled().ToString();
                if (!String.IsNullOrEmpty(windowsUpdateSettingObj.Value))
                {
                    windowsUpdateSettingObj.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    windowsUpdateSettingObj.completionCode = Contracts.CompletionCode.Failure;
                    windowsUpdateSettingObj.statusDescription = "Unable to get windows update settings";
                }
                response.ScanObjects.Add(windowsUpdateSettingObj);

                // Get EMS enabled setting
                ScanObject EMSObj = new ScanObject();
                EMSObj.Attribute = "EMS Enable Status";
                EMSObj.Value = Microsoft.GFS.WCS.ChassisManager.ScanDevice.IsEMSEnabled().ToString();
                if (!String.IsNullOrEmpty(EMSObj.Value))
                {
                    EMSObj.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    EMSObj.completionCode = Contracts.CompletionCode.Failure;
                    EMSObj.statusDescription = "Unable to get EMS settings";
                }
                response.ScanObjects.Add(EMSObj);

                // Get BootStatusPolicy
                ScanObject bootStatusPolicyObj = new ScanObject();
                bootStatusPolicyObj.Attribute = "Boot Status Policy";
                bootStatusPolicyObj.Value = Microsoft.GFS.WCS.ChassisManager.ScanDevice.GetBootStatusPolicy().ToString();
                if (!String.IsNullOrEmpty(bootStatusPolicyObj.Value))
                {
                    bootStatusPolicyObj.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    bootStatusPolicyObj.completionCode = Contracts.CompletionCode.Failure;
                    bootStatusPolicyObj.statusDescription = "Unable to get Boot Status Policy settings";
                }
                response.ScanObjects.Add(bootStatusPolicyObj);

                // Check if Chassis Manager SSL certificate is installed
                ScanObject chassisManagerSSLCert = new ScanObject();
                chassisManagerSSLCert.Attribute = "Chassis Manager SSl certificate Install Status";
                chassisManagerSSLCert.Value = Microsoft.GFS.WCS.ChassisManager.ScanDevice.IsChassisManagerSSLCertInstalled().ToString();
                if (!String.IsNullOrEmpty(chassisManagerSSLCert.Value))
                {
                    chassisManagerSSLCert.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    chassisManagerSSLCert.completionCode = Contracts.CompletionCode.Failure;
                    chassisManagerSSLCert.statusDescription = "Unable to get Chassis Manager SSL certificate install status";
                }
                response.ScanObjects.Add(chassisManagerSSLCert);

                // Get Chassis FRU data
                response.ChassisFRU = GetChassisAssetInfo(DeviceType.ChassisFruEeprom);

                // Get Chassis Network settings
                response.ChassisNetworkSettings = GetChassisNetworkProperties();

                // Get Chassis Manager service properties
                response.ChassisManagerServiceProperties = new ChassisManagerServiceProperties();
                response.ChassisManagerServiceProperties.ServiceVersion = GetServiceVersion();
                response.ChassisManagerServiceProperties.ServiceAppConfigSettings = ConfigLoaded.GetAllSettings();

                // If failed to fetch service version or app config settings
                if (response.ChassisManagerServiceProperties.ServiceVersion.completionCode == Contracts.CompletionCode.Success ||
                    response.ChassisManagerServiceProperties.ServiceAppConfigSettings.Any())
                {
                    response.ChassisManagerServiceProperties.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    response.ChassisManagerServiceProperties.completionCode = Contracts.CompletionCode.Failure;
                    response.ChassisManagerServiceProperties.statusDescription = "Failed to fetch Chassis Manager service properties";
                }

                // Get Wcscli version
                response.WCSCLIVersion = Microsoft.GFS.WCS.ChassisManager.ScanDevice.GetWcsCliVersion();

                // If we reach here without exception, set completion code to success
                response.completionCode = Contracts.CompletionCode.Success;
            }
            catch (Exception ex)
            {
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = String.Format("ScanDevice failed with exception: {0}", ex.Message);
                Tracer.WriteError("ScanDevice failed with exception" + ex);
            }

            return response;
        }
Ejemplo n.º 7
0
        public ScanReport StartScanObject(ScanObject obj)
        {
            if (obj.ScanRegions == null)
            {
                ulong      i   = 0;
                ScanReport rep = new ScanReport();
                foreach (var chobj in obj.ChildObjects)
                {
                    for (i = 0; i < chobj.SizeObject(); i++)
                    {
                        byte[] prefix = new byte[8];
                        prefix = chobj.Read(i);

                        List <ThreadSignature> signatures = tree.CheckSignature(prefix);
                        if (signatures != null)
                        {
                            foreach (var sig in signatures)
                            {
                                if (sig.SignatureFirstByteMinOffset < i && sig.SignatureFirstByteMaxOffset > i)
                                {
                                    uint   dataLength = sig.Signature.DataLength;
                                    byte[] searchSign = new byte[dataLength];
                                    searchSign = chobj.Read(i);
                                    if (sig.Signature.IsMatch(searchSign))
                                    {
                                        rep.AddRecord(new ScanReport(new string(sig.ThreadName), obj.Path + chobj.Name));
                                    }
                                }
                            }
                        }
                    }
                }
                rep.scannedObjects = i;
                return(rep);
            }
            else
            {
                for (ulong i = 0; i < obj.SizeObject(); i++)
                {
                    byte[] prefix = new byte[8];
                    prefix = obj.Read(i);

                    List <ThreadSignature> signatures = tree.CheckSignature(prefix);
                    if (signatures != null)
                    {
                        foreach (var sig in signatures)
                        {
                            if (sig.SignatureFirstByteMinOffset < i && sig.SignatureFirstByteMaxOffset > i)
                            {
                                uint   dataLength = sig.Signature.DataLength;
                                byte[] searchSign = new byte[dataLength];
                                searchSign = obj.Read(i);
                                if (sig.Signature.IsMatch(searchSign))
                                {
                                    return(new ScanReport(new string(sig.ThreadName), obj.Path));
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        private bool findFirstandLastScan(long projectId, ScanObject scan, ScanStatistics scanStatistics, Dictionary <long, ReportStaging> keyStartPairs, Dictionary <long, ReportStaging> keyLastPairs)
        {
            getScans scans = new getScans();

            if (keyStartPairs.ContainsKey(scan.Project.Id))
            {
                ReportStaging reportStaging = keyStartPairs[scan.Project.Id];
                long          diff          = DateTimeOffset.Compare(reportStaging.dateTime, (DateTimeOffset)scan.DateAndTime.StartedOn);
                if (diff > 0)
                {
                    ReportStaging staging = new ReportStaging()
                    {
                        ProjectId   = scan.Project.Id,
                        ProjectName = scan.Project.Name,
                        dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                        High        = scanStatistics.HighSeverity,
                        Medium      = scanStatistics.MediumSeverity,
                        Low         = scanStatistics.LowSeverity,
                        ScanId      = scan.Id
                    };
                    keyStartPairs[scan.Project.Id] = staging;
                }
            }
            else
            {
                keyStartPairs.Add(scan.Project.Id, new ReportStaging()
                {
                    ProjectId   = scan.Project.Id,
                    ProjectName = scan.Project.Name,
                    dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                    High        = scanStatistics.HighSeverity,
                    Medium      = scanStatistics.MediumSeverity,
                    Low         = scanStatistics.LowSeverity,
                    ScanId      = scan.Id
                });
            }

            if (keyLastPairs.ContainsKey(scan.Project.Id))
            {
                ReportStaging reportStaging = keyLastPairs[scan.Project.Id];
                long          diff          = DateTimeOffset.Compare(reportStaging.dateTime, (DateTimeOffset)scan.DateAndTime.StartedOn);
                if (diff < 0)
                {
                    ReportStaging staging = new ReportStaging()
                    {
                        ProjectId   = scan.Project.Id,
                        ProjectName = scan.Project.Name,
                        dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                        High        = scanStatistics.HighSeverity,
                        Medium      = scanStatistics.MediumSeverity,
                        Low         = scanStatistics.LowSeverity,
                        ScanId      = scan.Id
                    };
                    keyLastPairs[scan.Project.Id] = staging;
                }
            }
            else
            {
                keyLastPairs.Add(scan.Project.Id, new ReportStaging()
                {
                    ProjectId   = scan.Project.Id,
                    ProjectName = scan.Project.Name,
                    dateTime    = (DateTimeOffset)scan.DateAndTime.StartedOn,
                    High        = scanStatistics.HighSeverity,
                    Medium      = scanStatistics.MediumSeverity,
                    Low         = scanStatistics.LowSeverity,
                    ScanId      = scan.Id
                });
            }

            return(true);
        }