Esempio n. 1
0
        public bool presetId_in_scan(resultClass token, List <ScanObject> CxScans, string preset_name)
        {
            if (String.IsNullOrEmpty(preset_name))
            {
                return(false);
            }
            getScans getScans = new getScans();

            List <ScanObject> pclass = new List <ScanObject>();

            foreach (ScanObject scan in CxScans)
            {
                if (CxSettings.ContainsKey(scan.Project.Id))
                {
                    ScanSettings settings = CxSettings[scan.Project.Id];
                    string       preset   = CxPresets[settings.preset.id].name;
                    if (preset.Contains(preset_name))
                    {
                        pclass.Add(scan);
                    }
                }
            }
            CxScans = pclass;
            return(true);
        }
Esempio n. 2
0
        public List <ProjectObject> projectId_in_projects(resultClass token, string project_name)
        {
            getScans             scans          = new getScans();
            List <ProjectObject> projectObjects = get_projects(token);

            if (String.IsNullOrEmpty(project_name))
            {
                foreach (ProjectObject project in projectObjects)
                {
                    if (!CxSettings.ContainsKey(Convert.ToInt64(project.id)))
                    {
                        ScanSettings scanSettings = scans.getScanSettings(token, project.id);
                        CxSettings.Add(Convert.ToInt64(project.id), scanSettings);
                    }
                }
                return(projectObjects);
            }
            else
            {
                List <ProjectObject> pclass = new List <ProjectObject>();
                foreach (ProjectObject project in projectObjects)
                {
                    if (project.name.Contains(project_name))
                    {
                        if (!CxSettings.ContainsKey(Convert.ToInt64(project.id)))
                        {
                            ScanSettings scanSettings = scans.getScanSettings(token, project.id);
                            CxSettings.Add(Convert.ToInt64(project.id), scanSettings);
                        }
                        pclass.Add(project);
                    }
                }
                return(pclass);
            }
        }
Esempio n. 3
0
        public bool get_scan_settings(resultClass token, long projectId)
        {
            getScans scans = new getScans();

            if (!CxSettings.ContainsKey(projectId))
            {
                ScanSettings scanSettings = scans.getScanSettings(token, projectId.ToString());
                CxSettings.Add(projectId, scanSettings);
            }
            return(true);
        }
Esempio n. 4
0
        /*
         *     public List<ScanObject> projectId_in_scan(List<ScanObject> scans, string project_name)
         *     {
         *         if (String.IsNullOrEmpty(project_name))
         *         {
         *             return scans;
         *         }
         *         List<ScanObject> pclass = new List<ScanObject>();
         *         foreach (ScanObject scan in scans)
         *         {
         *             if (scan.Project.Name.Contains(project_name))
         *             {
         *                 pclass.Add(scan);
         *             }
         *         }
         *         return pclass;
         *     }
         *
         */
        public bool get_result_statistics(resultClass token, long scanId)
        {
            getScans scans = new getScans();

            if (!CxSettings.ContainsKey(scanId))
            {
                ScanStatistics scanStatistics = scans.getScansStatistics(scanId, token);
                CxResultStatistics.Add(scanId, scanStatistics);
            }
            return(true);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }

            Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix = new Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > >();
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <string, ReportResultExtended> resultAll = new Dictionary <string, ReportResultExtended>();
            List <ReportResultExtended> report_output           = new List <ReportResultExtended>();
            //            Dictionary<long, ReportStaging> start = new Dictionary<long, ReportStaging>();
            //            Dictionary<long, ReportStaging> end = new Dictionary<long, ReportStaging>();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScanResults scanResults             = new getScanResults();
            getScans       scans    = new getScans();
            getProjects    projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            //List<Teams> teams = scans.getTeams(token);
            token.max_scans = (token.max_scans == 0) ? 1 : token.max_scans;
            List <ScanObject> scan = projects.filter_by_projects(token);

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, please check argumants and retry.");
                return(false);
            }
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            Dictionary <long, ScanSettings>   settings         = projects.CxSettings;
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            Dictionary <long, Presets>        presets          = projects.CxPresets;
            List <ReportLastScan>             lastScan         = reportLastScan(token, scan, teams, resultStatistics, settings, presets);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", lastScan.Count);
            }

            if (token.pipe)
            {
                foreach (ReportLastScan csv in lastScan)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}", csv.ProjectId, csv.ProjectName, csv.Comment, csv.TeamName, csv.isIncremental, csv.Owner, csv.Origin, csv.ScanType, csv.ScanStartDate, csv.ScanFinishDate, csv.High, csv.Medium, csv.Low);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(lastScan, token);
            }
            return(true);
        }
Esempio n. 7
0
        public Dictionary <long, Presets> get_preset_list(resultClass token)
        {
            getScans scans = new getScans();
            Dictionary <long, Presets> result  = new Dictionary <long, Presets>();
            List <Presets>             presets = get_presets(token);

            foreach (Presets p in presets)
            {
                if (!result.ContainsKey(Convert.ToInt64(p.id)))
                {
                    result.Add(Convert.ToInt64(p.id), p);
                }
            }
            return(result);
        }
Esempio n. 8
0
        public Dictionary <string, Teams> get_team_list(resultClass token)
        {
            getScans scans = new getScans();
            Dictionary <string, Teams> result = new Dictionary <string, Teams>();
            List <Teams> tclass = scans.getTeams(token);

            foreach (Teams t in tclass)
            {
                if (!result.ContainsKey(t.id))
                {
                    result.Add(t.id, t);
                }
            }
            return(result);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        private List <ReportOutput> totalScansandReports(Dictionary <long, ReportStaging> start, Dictionary <long, ReportStaging> end, List <ReportResultAll> resultNew, Dictionary <long, List <ReportResultAll> > lastScan, Dictionary <long, ScanCount> scanCount)
        {
            List <ReportOutput> reports = new List <ReportOutput>();
            getScans            scans   = new getScans();

            foreach (long key in start.Keys)
            {
                ReportOutput report = new ReportOutput();

                ReportStaging          first           = start[key];
                ReportStaging          last            = end[key];
                List <ReportResultAll> lastScanResults = lastScan[key];
                foreach (ReportResultAll result in resultNew)
                {
                    if (result.projectId == first.ProjectId)
                    {
                        if (result.status == "New")
                        {
                            if (result.Severity == "High")
                            {
                                report.NewHigh++;
                            }
                            else if (result.Severity == "Medium")
                            {
                                report.NewMedium++;
                            }
                            else if (result.Severity == "Low")
                            {
                                report.NewLow++;
                            }
                        }
                    }
                }
                foreach (ReportResultAll result in lastScanResults)
                {
                    if (result.state == 0)
                    {
                        report.ToVerify++;
                    }
                    else if (result.state == 1)
                    {
                        report.NotExploitable++;
                    }
                    else if (result.state == 2)
                    {
                        report.Confirmed++;
                    }
                }
                //report.TeamName = first.TeamName;
                string[] split;
                if (first.TeamName.Contains('\\'))
                {
                    split = first.TeamName.Split('\\');
                }
                else
                {
                    split = first.TeamName.Split('/');
                }
                if (split.Length > 1)
                {
                    report.company = split[split.Length - 2];
                    report.team    = split[split.Length - 1];
                }
                report.ProjectName = first.ProjectName;
                report.StartHigh   = first.High;
                report.StartMedium = first.Medium;
                report.StartLow    = first.Low;
                report.firstScan   = first.dateTime;

                report.LastHigh   = last.High;
                report.LastMedium = last.Medium;
                report.LastLow    = last.Low;
                report.lastScan   = last.dateTime;

                report.DiffHigh   = first.High - last.High;
                report.DiffMedium = first.Medium - last.Medium;
                report.DiffLow    = first.Low - last.Low;
                report.ScanCount  = scanCount[key].count;
                reports.Add(report);
            }
            return(reports);
        }
Esempio n. 12
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }

            Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix = new Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > >();
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <string, ReportResultExtended> resultAll = new Dictionary <string, ReportResultExtended>();
            List <ReportResultExtended> report_output           = new List <ReportResultExtended>();
            //            Dictionary<long, ReportStaging> start = new Dictionary<long, ReportStaging>();
            //            Dictionary<long, ReportStaging> end = new Dictionary<long, ReportStaging>();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScanResults scanResults             = new getScanResults();
            getScans       scans    = new getScans();
            getProjects    projects = new getProjects(token);
            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check argumants and retry.");
                return(false);
            }
            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                    if (trace.Count % token.max_threads == 0)
                    {
                        fetchReports(trace, scanResults, fix, resultAll, report_output);
                        trace.Clear();
                    }
                }
            }

            fetchReports(trace, scanResults, fix, resultAll, report_output);
            trace.Clear();

            addFixed(fix, report_output);
            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", report_output.Count);
            }
            if (token.pipe)
            {
                foreach (ReportResultExtended csv in report_output)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", csv.projectName, csv.teamName, csv.presetName, csv.similarityId, csv.resultId, csv.reportId, csv.Severity, csv.status, csv.state, csv.Query, csv.Group, csv.scanDate);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(report_output, token);
            }
            return(true);
        }
Esempio n. 13
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <long, List <ReportResultMaxQueries> > report = new Dictionary <long, List <ReportResultMaxQueries> >();
            Dictionary <long, List <ReportResultAll> >        last   = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token, true);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, please check arguments and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (trace.Count % token.max_threads == 0)
                {
                    waitForResult(trace, scanResults, last);
                    trace.Clear();
                }
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
            }
            waitForResult(trace, scanResults, last);
            trace.Clear();

            List <ReportResultMaxQueries> reportOutputs = totalScansandReports(last, scan, resultStatistics);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", reportOutputs.Count);
            }
            if (token.pipe)
            {
                foreach (ReportResultMaxQueries csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25}", csv.Project_Name, csv.Team_Name, csv.Preset_Name, csv.Scan_Date, csv.Project_Id, csv.Scan_Id, csv.Languages, csv.Query_1, csv.Group_1, csv.Severity_1, csv.False_Positive_1, csv.Query_2, csv.Group_2, csv.Severity_2, csv.False_Positive_2, csv.Query_3, csv.Group_3, csv.Severity_3, csv.False_Positive_3, csv.Query_4, csv.Group_4, csv.Severity_4, csv.False_Positive_4, csv.Query_5, csv.Group_5, csv.Severity_5, csv.False_Positive_5);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultAll>                     resultNew = new List <ReportResultAll>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultAll> > first     = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, List <ReportResultAll> > last      = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check arguments and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);
                findFirstandLastScan(s.Project.Id, s, resultStatistics[s.Id], start, end);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                //                        ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                //                        if (result != null)
                //                        {
                //                            trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, scans.getFullName(teams, s.OwningTeamId), s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                //                        }
                if (trace.Count % token.max_threads == 0)
                {
                    waitForResult(trace, scanResults, resultNew, start, end, first, last);
                    trace.Clear();
                }
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
            }

            waitForResult(trace, scanResults, resultNew, start, end, first, last);
            trace.Clear();

            List <ReportOutputExtended> reportOutputs = totalScansandReports(start, end, resultNew, first, last, scanCount);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", reportOutputs.Count);
            }
            if (token.pipe)
            {
                foreach (ReportOutputExtended csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21}", csv.ProjectName, csv.Team, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.StartNotExploitable, csv.StartConfirmed, csv.StartToVerify, csv.LastOthers, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.LastNotExploitable, csv.LastConfirmed, csv.LastToVerify, csv.LastOthers, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Esempio n. 16
0
        public bool fetchReportsbyDate()
        {
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultNew>                     resultNew = new List <ReportResultNew>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultNew> > last      = new Dictionary <long, List <ReportResultNew> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();
            bool              waitFlag    = false;
            getScanResults    scanResults = new getScanResults();
            getScans          scans       = new getScans();
            List <ScanObject> scan        = scans.getScan(token);

            foreach (ScanObject s in scan)
            {
                if ((s.DateAndTime != null) && (s.Status.Id == 7) && (s.DateAndTime.StartedOn > token.start_time) && (s.DateAndTime.StartedOn < token.end_time))
                {
                    setCount(s.Project.Id, scanCount);
                    findFirstorLastScan(s.Project.Id, s, start, true);
                    findFirstorLastScan(s.Project.Id, s, end, false);

                    ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Id, result.ReportId));
                    }
                }
            }
            while (!waitFlag)
            {
                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                            }
                        }
                    }
                }
            }

            List <ReportOutput> reportOutputs = totalScansandReports(start, end, resultNew, last, scanCount);

            if (token.pipe)
            {
                foreach (ReportOutput csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", csv.ProjectName, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.NotExploitable, csv.Confirmed, csv.ToVerify, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Esempio n. 17
0
        public bool fetchResultsbyDate()
        {
            List<ReportTrace> trace = new List<ReportTrace>();
            bool waitFlag = false;
          
            getScans scans = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary<string, Teams> teams = projects.CxTeams;
            List<ScanObject> scan = projects.filter_by_projects(token);
            Dictionary<long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check arguments and retry.");
                return false;
            }

            foreach (ScanObject s in scan)
            {

                if (token.save_result.Contains("XML"))
                {
                    ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                    }
                }
                if (token.save_result.Contains("PDF"))
                {
                    ReportResult result = scanResults.SetResultRequest(s.Id, "PDF", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "PDF"));
                    }
                }
            }

            while (!waitFlag)
            {
                if (token.debug && token.verbosity > 0) { Console.WriteLine("Sleeping 1 second(s)"); }
                Thread.Sleep(1000);
                waitFlag = true;
                foreach (ReportTrace rt in trace)
                {
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (token.debug && token.verbosity > 0) { Console.WriteLine("Testing report.Id {0}", rt.reportId); }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0) { Console.WriteLine("Found report.Id {0}", rt.reportId); }
                            var result = scanResults.GetGenaricResult(rt.reportId, token);
                            if (result != null)
                            {
                                rt.isRead = true;
                                writeOutputToFile(rt, token);
                                trace.Remove(rt);
                                break;
                            }
                        }
                    }
                }
            }
            return true;
        }
Esempio n. 18
0
        public bool fetchReportsbyDate()
        {
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultAll>                     resultNew = new List <ReportResultAll>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultAll> > last      = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();

            /*            getScanResults scanResults = new getScanResults();
             *          getScans scans = new getScans();
             *          List<Teams> teams = scans.getTeams(token);
             *          List<ScanObject> scan = scans.getScan(token);*/
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check argumants and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);
                findFirstorLastScan(s.Project.Id, s, teams, start, true);
                findFirstorLastScan(s.Project.Id, s, teams, end, false);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
                if (trace.Count % 5 == 0)
                {
                    waitForResult(trace, scanResults, resultNew, end, last);
                    trace.Clear();
                }
            }
            waitForResult(trace, scanResults, resultNew, end, last);
            trace.Clear();

            List <ReportOutput> reportOutputs = totalScansandReports(start, end, resultNew, last, scanCount);

            if (token.pipe)
            {
                foreach (ReportOutput csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18}", csv.ProjectName, csv.company, csv.team, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.NotExploitable, csv.Confirmed, csv.ToVerify, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Esempio n. 19
0
        private List <AgingOutput> totalAllResults(Dictionary <DateTimeOffset, Dictionary <long, Dictionary <string, ReportResultExtended> > > extendedScan, Dictionary <long, ReportStaging> end)
        {
            List <AgingOutput> reports = new List <AgingOutput>();

            Dictionary <string, AgingOutput> allResults = new Dictionary <string, AgingOutput>();

            Dictionary <long, Dictionary <string, ReportResultExtended> > scanByProject = new Dictionary <long, Dictionary <string, ReportResultExtended> >();
            Dictionary <string, ReportResultExtended> scanByUnique = new Dictionary <string, ReportResultExtended>();

            getScans scans = new getScans();
            List <DateTimeOffset> dates = extendedScan.Keys.ToList();

            dates.Sort();

            foreach (DateTimeOffset key in dates)
            {
                scanByProject = extendedScan[key];
                foreach (long projectId in scanByProject.Keys)
                {
                    scanByUnique = extendedScan[key][projectId];

                    foreach (string uniqueKey in scanByUnique.Keys)
                    {
                        AgingOutput aging;
                        if (!allResults.ContainsKey(uniqueKey))
                        {
                            string   company  = String.Empty;
                            string   team     = String.Empty;
                            string   fileName = String.Empty;
                            string[] split    = scanByUnique[uniqueKey].teamName.Split('\\');
                            if (split.Length > 1)
                            {
                                company = split[split.Length - 2];
                                team    = split[split.Length - 1];
                            }
                            string[] fileSplit = scanByUnique[uniqueKey].fileName.Split('/');
                            if (fileSplit.Length > 1)
                            {
                                fileName = fileSplit[fileSplit.Length - 1];
                            }
                            aging = new AgingOutput()
                            {
                                ProjectName = scanByUnique[uniqueKey].projectName,
                                team        = team,
                                company     = company,
                                presetName  = scanByUnique[uniqueKey].presetName,
                                Query       = scanByUnique[uniqueKey].Query,
                                //similarityId = scanByUnique[uniqueKey].similarityId,
                                isFalsePositive = scanByUnique[uniqueKey].isFalsePositive,
                                //startState = scanByUnique[uniqueKey].state,
                                StateDesc = stateToString(scanByUnique[uniqueKey].state),
                                Status    = scanByUnique[uniqueKey].status,
                                Severity  = scanByUnique[uniqueKey].Severity,
                                //endState = scanByUnique[uniqueKey].state,
                                //endStateDesc = stateToString(scanByUnique[uniqueKey].state),
                                //endStatus = scanByUnique[uniqueKey].status,
                                //endSeverity = scanByUnique[uniqueKey].Severity,
                                lineNo = scanByUnique[uniqueKey].lineNo,
                                column = scanByUnique[uniqueKey].column,
                                //firstLine = scanByUnique[uniqueKey].firstLine,
                                fileName  = fileName,
                                deepLink  = scanByUnique[uniqueKey].deepLink,
                                remark    = scanByUnique[uniqueKey].remark,
                                firstScan = key,
                                lastScan  = key,
                                scanCount = 1
                            };
                            allResults.Add(uniqueKey, aging);
                            aging = allResults[uniqueKey];
                        }
                        else
                        {
                            aging = allResults[uniqueKey];
                            aging.isFalsePositive = scanByUnique[uniqueKey].isFalsePositive;
                            //aging.endState = scanByUnique[uniqueKey].state;
                            aging.StateDesc = stateToString(scanByUnique[uniqueKey].state);
                            aging.Status    = scanByUnique[uniqueKey].status;
                            aging.Severity  = scanByUnique[uniqueKey].Severity;
                            aging.lastScan  = key;
                            aging.scanCount++;
                        }
                        aging.age = (DateTimeOffset.Now - aging.firstScan.Date).Days;

                        if (!isUniqueInProject(dates, projectId, uniqueKey, extendedScan))
                        {
                            aging.Status = "Fixed";
                        }
                        if ((aging.isFalsePositive.ToUpper().Contains("TRUE")) || (aging.Status.Contains("Fixed")))
                        {
                            aging.age = 0;
                        }
                        allResults[uniqueKey] = aging;
                    }
                }
            }
            reports = allResults.Values.ToList();
            return(reports);
        }