Esempio n. 1
0
        private void SerchLinkApiBingEvent(string ip, BingAPISearcher bingSearcherApi, List <string> currentResults)
        {
            bingSearcherApi.SearcherLinkFoundEvent +=
                delegate(object sender, EventsThreads.ThreadListDataFoundEventArgs e)
            {
                var op = Partitioner.Create(e.Data);
                var po = new ParallelOptions();
                if (Program.cfgCurrent.ParallelDnsQueries != 0)
                {
                    po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries;
                }
                Parallel.ForEach(op, po, delegate(object item, ParallelLoopState loopState)
                {
                    if (CheckToSkip())
                    {
                        loopState.Stop();
                    }
                    try
                    {
                        var br  = (BingApiResult)item;
                        var url = new Uri(br.Url);
                        if (
                            currentResults.Any(d => string.Equals(d, url.Host, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            return;
                        }
                        currentResults.Add(url.Host);
                        var source = $"{Program.data.GetIpSource(ip)} > Bing IP Search [{url.Host}]";
                        Program.data.AddResolution(url.Host, ip, source, MaxRecursion,
                                                   Program.cfgCurrent, true);

                        Program.LogThis(new Log(Log.ModuleType.IPBingSearch,
                                                $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Found domain {url.Host} in IP {ip}",
                                                Log.LogType.medium));
                    }
                    catch
                    {
                    }
                }
                                 );
            };
            bingSearcherApi.SearcherLogEvent += IpBingSearcherLogEvent;
            bingSearcherApi.GetCustomLinks($"ip:{ip}");
            bingSearcherApi.Join();
        }
Esempio n. 2
0
        /// <summary>
        /// Perform the search through Bing API
        /// </summary>
        private void BingApiSearch()
        {
            BingAPISearcher bingSearcherApi = null;

            try
            {
                bingSearcherApi = new BingAPISearcher(Program.cfgCurrent.BingApiKey);

                var currentResults = new List <string>();
                bingSearcherApi.SearcherLinkFoundEvent +=
                    delegate(object sender, EventsThreads.ThreadListDataFoundEventArgs e)
                {
                    var searcher = (BingAPISearcher)sender;

                    foreach (var item in e.Data)
                    {
                        if (CheckToSkip())
                        {
                            searcher.Abort();
                        }

                        try
                        {
                            var br      = (BingApiResult)item;
                            var url     = new Uri(br.Url);
                            var strHost = url.Host;
                            if (
                                currentResults.All(
                                    D => !string.Equals(D, strHost, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                currentResults.Add(strHost);
                                AddAndLogSubdomainDiscover(strHost);
                            }
                            var domain = Program.data.GetDomain(url.Host);
                            domain.map.AddUrl(url.ToString());
                        }
                        catch
                        {
                        }
                    }
                };
                bingSearcherApi.SearcherLogEvent += WebSearcherLogEvent;
                var endReason = EventsThreads.ThreadEndEventArgs.EndReasonEnum.ErrorFound;
                bingSearcherApi.SearcherEndEvent +=
                    delegate(object o, EventsThreads.ThreadEndEventArgs e) { endReason = e.EndReason; };
                var strSearchString = $"site:{strDomain}";
                int nroResultados;
                do
                {
                    if (CheckToSkip())
                    {
                        return;
                    }

                    nroResultados = currentResults.Count;
                    bingSearcherApi.GetCustomLinks(strSearchString);
                    bingSearcherApi.Join();

                    CheckEndReason(endReason, currentResults, strSearchString, 49);
                } while (endReason == EventsThreads.ThreadEndEventArgs.EndReasonEnum.LimitReached &&
                         nroResultados != currentResults.Count);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                bingSearcherApi?.Abort();
            }
        }