projectdiscovery / shuffledns

MassDNS wrapper written in go to enumerate valid subdomains using active bruteforce as well as resolve subdomains with wildcard filtering and easy input-output support.
https://projectdiscovery.io
GNU General Public License v3.0
1.29k stars 184 forks source link

wildcard filter not work when RunEnumeration multi times #315

Closed runt0 closed 3 months ago

runt0 commented 4 months ago

shuffledns version:

v1.0.9

Current Behavior:

wildcard filter not work when RunEnumeration multi times

Expected Behavior:

wildcard filter should be work when RunEnumeration multi times

Steps To Reproduce:

cmd/shuffledns/main.go:

package main

import (
    "github.com/projectdiscovery/gologger"
    "github.com/projectdiscovery/shuffledns/pkg/runner"
)

func main() {
    // RunEnumeration first time
    options := runner.ShufflednsDefaultOptions()
    options.Domain = "eastmoney.cn"
    massdnsRunner, err := runner.New(options)
    if err != nil {
        gologger.Fatal().Msgf("Could not create runner: %s\n", err)
    }
    massdnsRunner.RunEnumeration()
    massdnsRunner.Close()

    // RunEnumeration second time
    options2 := runner.ShufflednsDefaultOptions()
    options2.Domain = "eastmoney.cn"
    massdnsRunner2, err := runner.New(options)
    if err != nil {
        gologger.Fatal().Msgf("Could not create runner: %s\n", err)
    }
    massdnsRunner2.RunEnumeration()
    massdnsRunner2.Close()
}

ShufflednsDefaultOptions:

func ShufflednsDefaultOptions() *Options {
    return &Options{
        Directory: "",
        //SubdomainsList:     "",
        ResolversFile:      "resolve.txt",
        Wordlist:           "words.txt",
        MassdnsPath:        "massdns.exe",
        Json:               false,
        Silent:             false,
        Version:            false,
        Retries:            5,
        Verbose:            true,
        NoColor:            false,
        Threads:            10000,
        MassdnsRaw:         "",
        WildcardThreads:    25,
        WildcardOutputFile: "",
        MassDnsCmd:         "",
        Stdin:              false,
        DisableUpdateCheck: false,
        StrictWildcard:     true,
    }
}

resolve.txt:

119.29.29.29
182.254.116.116
1.1.1.1
114.114.115.115
114.114.114.114
8.8.8.8
223.5.5.5
119.29.29.29

words.txt:

pop
imap
smtp
act
d
mail
test1
test2
test3
test4
test5
test6

frist output: you can see the junk domains has been filtered image

second output: the filter not work image

Anything else:

runt0 commented 4 months ago

Maybe I found the reason:the pkg/wildcards/resolver.go:33,the code to genrate resolver is:

// AddServersFromList adds the resolvers from a list of servers
func (w *Resolver) AddServersFromList(list []string) {
    for i := 0; i < len(list); i++ {
        list[i] = list[i] + ":53"
    }
    w.servers, _ = transport.New(list...)
}

when the first RunEnumeration run, the excellentResolvers slice will be changed. So RunEnumeration again,the resolves will be 1.1.1.1:53:53, 1.1.1.1:53:53:53 and so on image So I change the code and it work correctly

// AddServersFromList adds the resolvers from a list of servers
func (w *Resolver) AddServersFromList(list []string) {
    var resolvers []string
    for i := 0; i < len(list); i++ {
        resolvers = append(resolvers, list[i]+":53")
    }
    w.servers, _ = transport.New(resolvers...)
}

and I notice the pkg/massdns/massdns.go:61image it use resolver.AddServersFromList(excellentResolvers) to generate resolvers, but shuffledns must be input resolvers.txt, but I didn't saw the use of ResolversFile, maybe the code shoud be this ? image