示例#1
0
        public PingCastleReportCollection <T> ToLatestReportCollection()
        {
            var output = new PingCastleReportCollection <T>();

            foreach (var sid in data.Keys)
            {
                DateTime maxDate = DateTime.MinValue;
                foreach (var date in data[sid].Keys)
                {
                    if (maxDate < date)
                    {
                        maxDate = date;
                    }
                }
                output.Add(data[sid][maxDate]);
            }
            output.EnrichInformation();
            return(output);
        }
示例#2
0
        public PingCastleReportCollection <T> GetDataReportAtDate(DateTime dateToIssueReport)
        {
            var output = new PingCastleReportCollection <T>();

            foreach (var sid in data.Keys)
            {
                DateTime min = DateTime.MinValue;
                foreach (var date in data[sid].Keys)
                {
                    if (date > min && date <= dateToIssueReport)
                    {
                        min = date;
                    }
                }
                if (min != DateTime.MinValue)
                {
                    output.Add(data[sid][min]);
                }
            }
            output.EnrichInformation();
            return(output);
        }
示例#3
0
        public bool CartoTask(bool PerformHealthCheckGenerateDemoReports)
        {
            List <HealthcheckAnalyzer.ReachableDomainInfo> domains = null;

            StartTask("Exploration",
                      () =>
            {
                HealthcheckAnalyzer hcroot = new HealthcheckAnalyzer();
                domains = hcroot.GetAllReachableDomains(Port, Credential);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("List of domains that will be queried");
                Console.ResetColor();
                foreach (var domain in domains)
                {
                    Console.WriteLine(domain.domain);
                }
            });
            var consolidation = new PingCastleReportCollection <HealthcheckData>();

            StartTask("Examining all domains in parallele (this can take a few minutes)",
                      () =>
            {
                BlockingQueue <string> queue = new BlockingQueue <string>(30);
                int numberOfThread           = 100;
                Thread[] threads             = new Thread[numberOfThread];
                try
                {
                    ThreadStart threadFunction = () =>
                    {
                        for (; ;)
                        {
                            string domain = null;
                            if (!queue.Dequeue(out domain))
                            {
                                break;
                            }
                            try
                            {
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Starting the analysis of " + domain);
                                HealthcheckAnalyzer hc = new HealthcheckAnalyzer();
                                var data = hc.GenerateCartoReport(domain, Port, Credential, AnalyzeReachableDomains);
                                consolidation.Add(data);
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Analysis of " + domain + " completed with success");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Analysis of " + domain + " failed");
                                Trace.WriteLine("Exception while analysing domain " + domain + " : " + ex.Message);
                                Trace.WriteLine(ex.StackTrace);
                            }
                        }
                    };
                    // Consumers
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        threads[i] = new Thread(threadFunction);
                        threads[i].Start();
                    }
                    foreach (var domain in domains)
                    {
                        queue.Enqueue(domain.domain);
                    }
                    queue.Quit();
                    Trace.WriteLine("examining domains file completed. Waiting for worker thread to complete");
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        threads[i].Join();
                    }
                    Trace.WriteLine("Done examining domains");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Exception while analysing domain in carto: " + ex.Message);
                    Trace.WriteLine(ex.StackTrace);
                }
                finally
                {
                    queue.Quit();
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        if (threads[i] != null)
                        {
                            if (threads[i].ThreadState == System.Threading.ThreadState.Running)
                            {
                                threads[i].Abort();
                            }
                        }
                    }
                }
            });
            if (PerformHealthCheckGenerateDemoReports)
            {
                Console.WriteLine("Performing demo report transformation");
                Trace.WriteLine("Performing demo report transformation");
                consolidation = PingCastleReportHelper <HealthcheckData> .TransformReportsToDemo(consolidation);
            }
            if (!StartTask("Healthcheck consolidation",
                           () =>
            {
                consolidation.EnrichInformation();
                ReportHealthCheckMapBuilder nodeAnalyzer = new ReportHealthCheckMapBuilder(consolidation, License);
                nodeAnalyzer.Log = Console.WriteLine;
                nodeAnalyzer.CenterDomainForSimpliedGraph = CenterDomainForSimpliedGraph;
                nodeAnalyzer.GenerateReportFile("ad_carto_full_node_map.html");
                nodeAnalyzer.FullNodeMap = false;
                nodeAnalyzer.CenterDomainForSimpliedGraph = CenterDomainForSimpliedGraph;
                nodeAnalyzer.GenerateReportFile("ad_carto_simple_node_map.html");
            }
                           ))
            {
                return(false);
            }
            return(true);
        }
        public PingCastleReportCollection <HealthcheckData> GenerateForest(int maxDomain = 15)
        {
            int numberDomains = rnd.Next(5, maxDomain > 15 ? 15 : maxDomain);
            var children      = new PingCastleReportCollection <HealthcheckData>();
            // head of forest
            var root = GenerateSingleReport(new FakeHealthCheckDataGeneratorDomainModel()
            {
                Size = DomainSizeModel.VerySmall
            });

            for (int i = 0; i < numberDomains; i++)
            {
                var child = GenerateSingleReport(new FakeHealthCheckDataGeneratorDomainModel()
                {
                    Size = DomainSizeModel.Medium, Forest = root
                });
                children.Add(child);
            }
            foreach (var child in children)
            {
                // root trust
                var trust = new HealthCheckTrustData();
                trust.CreationDate    = child.DomainCreation;
                trust.IsActive        = true;
                trust.NetBiosName     = child.NetBIOSName;
                trust.SID             = child.DomainSid;
                trust.TrustDirection  = 3;
                trust.TrustAttributes = 32;
                trust.TrustType       = 2;
                trust.TrustPartner    = child.DomainFQDN;
                trust.SID             = child.DomainSid;
                trust.KnownDomains    = new List <HealthCheckTrustDomainInfoData>();
                root.Trusts.Add(trust);

                // child trust
                trust = new HealthCheckTrustData();
                trust.CreationDate    = child.DomainCreation;
                trust.IsActive        = true;
                trust.NetBiosName     = root.NetBIOSName;
                trust.SID             = child.DomainSid;
                trust.TrustDirection  = 3;
                trust.TrustAttributes = 32;
                trust.TrustType       = 2;
                trust.TrustPartner    = root.DomainFQDN;
                trust.SID             = root.DomainSid;
                trust.KnownDomains    = new List <HealthCheckTrustDomainInfoData>();
                child.Trusts.Add(trust);

                foreach (var child2 in children)
                {
                    if (child2.DomainSid == child.DomainSid)
                    {
                        continue;
                    }
                    var kdomain = new HealthCheckTrustDomainInfoData();
                    kdomain.CreationDate  = child2.DomainCreation;
                    kdomain.DnsName       = child2.DomainFQDN;
                    kdomain.ForestName    = child2.ForestFQDN;
                    kdomain.ForestNetbios = root.NetBIOSName;
                    kdomain.ForestSid     = root.DomainSid;
                    kdomain.NetbiosName   = child2.NetBIOSName;
                    kdomain.Sid           = child2.DomainSid;
                    trust.KnownDomains.Add(kdomain);
                }
            }
            // output all domains
            children.Add(root);
            return(children);
        }
        public PingCastleReportCollection <HealthcheckData> GenerateData(FakeHealthCheckDataGeneratorModel model)
        {
            var output = new PingCastleReportCollection <HealthcheckData>();

            var num = 0;

            while (num < model.NumberOfDomains - 1)
            {
                int value = rnd.Next(100);
                if (value < 20 && model.NumberOfDomains - num > 6)
                {
                    foreach (var d in GenerateForest(model.NumberOfDomains - num))
                    {
                        output.Add(d);
                        num++;
                    }
                }
                if (value < 60)
                {
                    output.Add(GenerateSingleReport(new FakeHealthCheckDataGeneratorDomainModel()
                    {
                        Size = DomainSizeModel.Small
                    }));
                    num++;
                }
                else if (value < 80)
                {
                    output.Add(GenerateSingleReport(new FakeHealthCheckDataGeneratorDomainModel()
                    {
                        Size = DomainSizeModel.Medium
                    }));
                    num++;
                }
                else
                {
                    output.Add(GenerateSingleReport(new FakeHealthCheckDataGeneratorDomainModel()
                    {
                        Size = DomainSizeModel.Large
                    }));
                    num++;
                }
            }
            int numberOfTrust = model.NumberOfDomains * model.TrustRatioInPercent / 100;

            for (int i = 0; i < numberOfTrust; i++)
            {
                //take 2 random domains
                int a = rnd.Next(output.Count);
                int b = rnd.Next(output.Count);
                while (a == b)
                {
                    b = rnd.Next(output.Count);
                }
                var source      = GetItem(output, a);
                var destination = GetItem(output, b);

                //bool forestTrust = false;

                bool uniDirectional = false;

                bool sidfiltering = false;

                DateTime trustCreation = DateBetween2Dates(new DateTime(Math.Max(source.DomainCreation.Ticks, destination.DomainCreation.Ticks)), DateTime.Now);

                var trust = new HealthCheckTrustData();
                trust.CreationDate    = trustCreation;
                trust.IsActive        = true;
                trust.NetBiosName     = destination.NetBIOSName;
                trust.SID             = destination.DomainSid;
                trust.TrustDirection  = (uniDirectional ? 1 : 3);
                trust.TrustAttributes = (sidfiltering ? 4 : 0);
                trust.TrustType       = 2;
                trust.TrustPartner    = destination.DomainFQDN;
                trust.SID             = destination.DomainSid;
                trust.KnownDomains    = new List <HealthCheckTrustDomainInfoData>();
                source.Trusts.Add(trust);

                trust = new HealthCheckTrustData();
                trust.CreationDate    = trustCreation;
                trust.IsActive        = true;
                trust.NetBiosName     = source.NetBIOSName;
                trust.SID             = source.DomainSid;
                trust.TrustDirection  = (uniDirectional ? 2 : 3);
                trust.TrustAttributes = (sidfiltering ? 4 : 0);
                trust.TrustType       = 2;
                trust.TrustPartner    = source.DomainFQDN;
                trust.SID             = source.DomainSid;
                trust.KnownDomains    = new List <HealthCheckTrustDomainInfoData>();
                destination.Trusts.Add(trust);
            }
            return(output);
        }