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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
func (r *Runner) EnumerateSingleDomainWithCtx(ctx context.Context, domain string, writers []io.Writer) error { gologger.Info().Msgf("Enumerating subdomains for %s\n", domain)
var resolutionPool *resolve.ResolutionPool if r.options.RemoveWildcard { resolutionPool = r.resolverClient.NewResolutionPool(r.options.Threads, r.options.RemoveWildcard) err := resolutionPool.InitWildcards(domain) if err != nil { gologger.Warning().Msgf("Could not get wildcards for domain %s: %s\n", domain, err) } }
now := time.Now() passiveResults := r.passiveAgent.EnumerateSubdomainsWithCtx(ctx, domain, r.options.Proxy, r.options.RateLimit, r.options.Timeout, time.Duration(r.options.MaxEnumerationTime)*time.Minute, passive.WithCustomRateLimit(r.rateLimit))
wg := &sync.WaitGroup{} wg.Add(1) uniqueMap := make(map[string]resolve.HostEntry) sourceMap := make(map[string]map[string]struct{}) skippedCounts := make(map[string]int) go func() { for result := range passiveResults { switch result.Type { case subscraping.Error: gologger.Warning().Msgf("Could not run source %s: %s\n", result.Source, result.Error) case subscraping.Subdomain: if !strings.HasSuffix(result.Value, "."+domain) { skippedCounts[result.Source]++ continue } subdomain := strings.ReplaceAll(strings.ToLower(result.Value), "*.", "") if matchSubdomain := r.filterAndMatchSubdomain(subdomain); matchSubdomain { if _, ok := uniqueMap[subdomain]; !ok { sourceMap[subdomain] = make(map[string]struct{}) }
if _, ok := sourceMap[subdomain][result.Source]; !ok { gologger.Verbose().Label(result.Source).Msg(subdomain) }
sourceMap[subdomain][result.Source] = struct{}{}
if _, ok := uniqueMap[subdomain]; ok { skippedCounts[result.Source]++ continue }
hostEntry := resolve.HostEntry{Domain: domain, Host: subdomain, Source: result.Source}
uniqueMap[subdomain] = hostEntry if r.options.RemoveWildcard { resolutionPool.Tasks <- hostEntry } } } } if r.options.RemoveWildcard { close(resolutionPool.Tasks) } wg.Done() }()
foundResults := make(map[string]resolve.Result) if r.options.RemoveWildcard { for result := range resolutionPool.Results { switch result.Type { case resolve.Error: gologger.Warning().Msgf("Could not resolve host: %s\n", result.Error) case resolve.Subdomain: if _, ok := foundResults[result.Host]; !ok { foundResults[result.Host] = result } } } } wg.Wait() outputWriter := NewOutputWriter(r.options.JSON) var err error for _, writer := range writers { if r.options.HostIP { err = outputWriter.WriteHostIP(domain, foundResults, writer) } else { if r.options.RemoveWildcard { err = outputWriter.WriteHostNoWildcard(domain, foundResults, writer) } else { if r.options.CaptureSources { err = outputWriter.WriteSourceHost(domain, sourceMap, writer) } else { err = outputWriter.WriteHost(domain, uniqueMap, writer) } } } if err != nil { gologger.Error().Msgf("Could not write results for %s: %s\n", domain, err) return err } }
duration := durafmt.Parse(time.Since(now)).LimitFirstN(maxNumCount).String() var numberOfSubDomains int if r.options.RemoveWildcard { numberOfSubDomains = len(foundResults) } else { numberOfSubDomains = len(uniqueMap) }
if r.options.ResultCallback != nil { if r.options.RemoveWildcard { for host, result := range foundResults { r.options.ResultCallback(&resolve.HostEntry{Domain: host, Host: result.Host, Source: result.Source}) } } else { for _, v := range uniqueMap { r.options.ResultCallback(&v) } } } gologger.Info().Msgf("Found %d subdomains for %s in %s\n", numberOfSubDomains, domain, duration)
if r.options.Statistics { gologger.Info().Msgf("Printing source statistics for %s", domain) statistics := r.passiveAgent.GetStatistics() for source, count := range skippedCounts { if stat, ok := statistics[source]; ok { stat.Results -= count statistics[source] = stat } } printStatistics(statistics) }
return nil }
|