Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow private tlds only #59

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/tldfinder/pkg/agent"
"github.com/projectdiscovery/tldfinder/pkg/registry"
"github.com/projectdiscovery/tldfinder/pkg/resolve"
"github.com/projectdiscovery/tldfinder/pkg/source"
fileutil "github.com/projectdiscovery/utils/file"
folderutil "github.com/projectdiscovery/utils/folder"
logutil "github.com/projectdiscovery/utils/log"
updateutils "github.com/projectdiscovery/utils/update"
"github.com/weppos/publicsuffix-go/publicsuffix"
"golang.org/x/exp/slices"
)

var (
Expand Down Expand Up @@ -180,8 +182,6 @@ func ParseOptions() *Options {
os.Exit(0)
}

options.preProcessOptions()

if !options.Silent {
showBanner()
}
Expand All @@ -202,6 +202,8 @@ func ParseOptions() *Options {
os.Exit(0)
}

options.preProcessOptions()

// Validate the options passed by the user and if any
// invalid options have been used, exit.
err = options.validateOptions()
Expand Down Expand Up @@ -258,17 +260,24 @@ func (options *Options) preProcessOptions() {
for i, query := range options.Domain {
query, _ = sanitize(query)
options.Domain[i] = options.parseQuery(query)

}
}

func (options *Options) parseQuery(query string) string {
if options.DiscoveryMode == source.DNSMode {
var tld string
if parsed, err := publicsuffix.Parse(query); err == nil {
query = parsed.TLD
tld = parsed.TLD
} else {
tld = strings.Trim(query, ".")
}
if slices.Contains(registry.PrivateTLDs, tld) {
query = tld
} else {
query = strings.Trim(query, ".")
gologger.Warning().Msgf("Skipping \"%s\": only private TLDs are allowed (e.g., .google)\n", query)
query = ""
}

} else if options.DiscoveryMode == source.TLDMode {
if parsed, err := publicsuffix.Parse(query); err == nil {
query = parsed.SLD
Expand Down
Loading
Loading