From 74c6e087043b82fa319e7c3fc6881334c3535e4b Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Wed, 29 Sep 2021 22:14:22 -0500 Subject: [PATCH 01/15] goflags support --- v2/go.mod | 4 ++ v2/go.sum | 7 +++ v2/pkg/runner/banners.go | 21 +++----- v2/pkg/runner/options.go | 108 ++++++++++++++++++++++----------------- 4 files changed, 78 insertions(+), 62 deletions(-) diff --git a/v2/go.mod b/v2/go.mod index 581d4a650..28b23e6bd 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -21,6 +21,7 @@ require ( require ( github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect + github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/miekg/dns v1.1.41 // indirect @@ -29,8 +30,11 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/projectdiscovery/goflags v0.0.7 // indirect github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e // indirect + github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe // indirect golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d // indirect golang.org/x/sys v0.0.0-20210419170143-37df388d1f33 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/v2/go.sum b/v2/go.sum index eb454ad60..a99c48040 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -7,6 +7,8 @@ github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9or github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ= +github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4= github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= github.com/corpix/uarand v0.1.1 h1:RMr1TWc9F4n5jiPDzFHtmaUXLKLNUFK0SgCLo4BhX/U= github.com/corpix/uarand v0.1.1/go.mod h1:SFKZvkcRoLqVRFZ4u25xPmp6m9ktANfbpXZ7SJ0/FNU= @@ -89,12 +91,16 @@ github.com/projectdiscovery/dnsx v1.0.3 h1:IbMlMEeki6mlllHxATVh50+eOBwyOn8OKD1Cl github.com/projectdiscovery/dnsx v1.0.3/go.mod h1:M79ADVHwnNQM6kN2J4/XvjydJ3cDhaHHoI5lxJR2Z/A= github.com/projectdiscovery/fdmax v0.0.3 h1:FM6lv9expZ/rEEBI9tkRh6tx3DV0gtpwzdc0h7bGPqg= github.com/projectdiscovery/fdmax v0.0.3/go.mod h1:NWRcaR7JTO7fC27H4jCl9n7Z+KIredwpgw1fV+4KrKI= +github.com/projectdiscovery/goflags v0.0.7 h1:aykmRkrOgDyRwcvGrK3qp+9aqcjGfAMs/+LtRmtyxwk= +github.com/projectdiscovery/goflags v0.0.7/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= github.com/projectdiscovery/gologger v1.0.0/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTtMKunQ8O2VI= github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY= github.com/projectdiscovery/hmap v0.0.1/go.mod h1:VDEfgzkKQdq7iGTKz8Ooul0NuYHQ8qiDs6r8bPD1Sb0= github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e h1:cxke2L/GKym765W0UnA9RuyaY/LI2u5z+fYqDtoQY0M= github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e/go.mod h1:4sMC8HZyF01HXukRleSQYwz4870bwgb4+hTSXTMrkf4= +github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe h1:tQTgf5XLBgZbkJDPtnV3SfdP9tzz5ZWeDBwv8WhnH9Q= +github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe/go.mod h1:oTRc18WBv9t6BpaN9XBY+QmG28PUpsyDzRht56Qf49I= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -207,6 +213,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/v2/pkg/runner/banners.go b/v2/pkg/runner/banners.go index 292d22740..421fb5296 100644 --- a/v2/pkg/runner/banners.go +++ b/v2/pkg/runner/banners.go @@ -27,13 +27,12 @@ func showBanner() { gologger.Print().Msgf("By using subfinder, you also agree to the terms of the APIs used.\n\n") } -// normalRunTasks runs the normal startup tasks -func (options *Options) normalRunTasks() { +// sourceRunTasks runs the app with source config +func (options *Options) sourceRunTasks() { configFile, err := UnmarshalRead(options.ConfigFile) if err != nil { gologger.Fatal().Msgf("Could not read configuration file %s: %s\n", options.ConfigFile, err) } - // If we have a different version of subfinder installed // previously, use the new iteration of config file. if configFile.Version != Version { @@ -46,15 +45,14 @@ func (options *Options) normalRunTasks() { if err != nil { gologger.Fatal().Msgf("Could not update configuration file to %s: %s\n", options.ConfigFile, err) } + gologger.Info().Msgf("Configuration file updated to %s\n", options.ConfigFile) } options.YAMLConfig = configFile } -// firstRunTasks runs some housekeeping tasks done -// when the program is ran for the first time -func (options *Options) firstRunTasks() { - // Create the configuration file and display information - // about it to the user. +// defaultRunTasks runs the app with default configuration +func (options *Options) defaultRunTasks() { + // Setting default configurations data config := ConfigFile{ // Use the default list of resolvers by marshaling it to the config Resolvers: resolve.DefaultResolvers, @@ -65,12 +63,5 @@ func (options *Options) firstRunTasks() { // Use the default list of recursive sources Recursive: passive.DefaultRecursiveSources, } - - err := config.MarshalWrite(options.ConfigFile) - if err != nil { - gologger.Fatal().Msgf("Could not write configuration file to %s: %s\n", options.ConfigFile, err) - } options.YAMLConfig = config - - gologger.Info().Msgf("Configuration file saved to %s\n", options.ConfigFile) } diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 36971d9bd..2567a3491 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -1,15 +1,13 @@ package runner import ( - "flag" + "github.com/projectdiscovery/goflags" + "github.com/projectdiscovery/gologger" "io" "net" "os" - "path" "reflect" "strings" - - "github.com/projectdiscovery/gologger" ) // Options contains the configuration options for tuning @@ -52,43 +50,53 @@ type Options struct { func ParseOptions() *Options { options := &Options{} - config, err := GetConfigDirectory() - if err != nil { - // This should never be reached - gologger.Fatal().Msgf("Could not get user home: %s\n", err) - } - - flag.BoolVar(&options.Verbose, "v", false, "Show Verbose output") - flag.BoolVar(&options.NoColor, "nC", false, "Don't Use colors in output") - flag.IntVar(&options.Threads, "t", 10, "Number of concurrent goroutines for resolving") - flag.IntVar(&options.Timeout, "timeout", 30, "Seconds to wait before timing out") - flag.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results") - flag.StringVar(&options.Domain, "d", "", "Domain to find subdomains for") - flag.StringVar(&options.DomainsFile, "dL", "", "File containing list of domains to enumerate") - flag.StringVar(&options.OutputFile, "o", "", "File to write output to (optional)") - flag.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)") - flag.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format") - flag.BoolVar(&options.CaptureSources, "collect-sources", false, "Output host source as array of sources instead of single (first) source") - flag.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format") - flag.BoolVar(&options.HostIP, "oI", false, "Write output in Host,IP format") - flag.BoolVar(&options.Silent, "silent", false, "Show only subdomains in output") - flag.BoolVar(&options.Recursive, "recursive", false, "Use only recursive subdomain enumeration sources") - flag.BoolVar(&options.All, "all", false, "Use all sources (slow) for enumeration") - flag.StringVar(&options.Sources, "sources", "", "Comma separated list of sources to use") - flag.BoolVar(&options.ListSources, "ls", false, "List all available sources") - flag.StringVar(&options.ExcludeSources, "exclude-sources", "", "List of sources to exclude from enumeration") - flag.StringVar(&options.Resolvers, "r", "", "Comma-separated list of resolvers to use") - flag.StringVar(&options.ResolverList, "rL", "", "Text file containing list of resolvers to use") - flag.BoolVar(&options.RemoveWildcard, "nW", false, "Remove Wildcard & Dead Subdomains from output") - flag.StringVar(&options.LocalIPString, "b", "", "IP address to be used as local bind") - flag.StringVar(&options.ConfigFile, "config", path.Join(config, "config.yaml"), "Configuration file for API Keys, etc") - flag.StringVar(&options.Proxy, "proxy", "", "HTTP proxy to use with subfinder") - flag.IntVar(&options.RateLimit, "rate-limit", 0, "Maximum number of HTTP requests to send per second") - flag.BoolVar(&options.Version, "version", false, "Show version of subfinder") - flag.Parse() + flagSet := goflags.NewFlagSet() + flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources. It has a simple modular architecture and is optimized for speed. subfinder is built for doing one thing only - passive subdomain enumeration, and it does that very well.`) + createGroup(flagSet, "input", "Target", + flagSet.StringVar(&options.Domain, "d", "", "Domain to find subdomains for"), + flagSet.StringVar(&options.DomainsFile, "dL", "", "File containing list of domains to enumerate"), + flagSet.StringVar(&options.Sources, "sources", "", "Comma separated list of sources to use"), + ) + createGroup(flagSet, "template", "Template", + flagSet.IntVar(&options.Threads, "t", 10, "Number of concurrent goroutines for resolving"), + flagSet.IntVar(&options.Timeout, "timeout", 30, "Seconds to wait before timing out"), + flagSet.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results"), + flagSet.BoolVar(&options.ListSources, "ls", false, "List all available sources"), + flagSet.BoolVar(&options.Recursive, "recursive", false, "Use only recursive subdomain enumeration sources"), + flagSet.BoolVar(&options.All, "all", false, "Use all sources (slow) for enumeration"), + flagSet.StringVar(&options.ExcludeSources, "exclude-sources", "", "List of sources to exclude from enumeration"), + ) + createGroup(flagSet, "filters", "FILTERING", + flagSet.StringVar(&options.Resolvers, "r", "", "Comma-separated list of resolvers to use"), + flagSet.StringVar(&options.ResolverList, "rL", "", "Text file containing list of resolvers to use"), + flagSet.BoolVar(&options.RemoveWildcard, "nW", false, "Remove Wildcard & Dead Subdomains from output"), + flagSet.StringVar(&options.LocalIPString, "b", "", "IP address to be used as local bind"), + flagSet.StringVar(&options.Proxy, "proxy", "", "HTTP proxy to use with subfinder"), + ) + createGroup(flagSet, "config", "Configurations", + flagSet.StringVar(&options.ConfigFile, "config", "", "Configuration file for API Keys, etc"), + //flagSet.StringVar(&options.ConfigFile, "config", path.Join(config, "config.yaml"), "Configuration file for API Keys, etc"), + //flagSet.StringVar(&options.SourceConfigFile, "source-config", path.Join(config, "config.yaml"), "Source Configuration file for API Keys, etc"), + ) + createGroup(flagSet, "rate-limit", "RATE-LIMIT", + flagSet.IntVar(&options.RateLimit, "rate-limit", 0, "Maximum number of HTTP requests to send per second"), + ) + createGroup(flagSet, "output", "Output", + flagSet.BoolVar(&options.Verbose, "v", false, "Show Verbose output"), + flagSet.BoolVar(&options.NoColor, "nC", false, "Don't Use colors in output"), + flagSet.StringVar(&options.OutputFile, "o", "", "File to write output to (optional)"), + flagSet.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)"), + flagSet.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format"), + flagSet.BoolVar(&options.CaptureSources, "collect-sources", false, "Output host source as array of sources instead of single (first) source"), + flagSet.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format"), + flagSet.BoolVar(&options.HostIP, "oI", false, "Write output in Host,IP format"), + flagSet.BoolVar(&options.Silent, "silent", false, "Show only subdomains in output"), + flagSet.BoolVar(&options.Version, "version", false, "Show version of subfinder"), + ) + flagSet.Parse() // Default output is stdout - options.Output = os.Stdout + // options.Output = os.Stdout // Check if stdin pipe was given options.Stdin = hasStdin() @@ -104,15 +112,15 @@ func ParseOptions() *Options { os.Exit(0) } - // Check if the config file exists. If not, it means this is the - // first run of the program. Show the first run notices and initialize the config file. - // Else show the normal banners and read the yaml fiile to the config - if !CheckConfigExists(options.ConfigFile) { - options.firstRunTasks() + // Check if the application loading with any configuration, then take it + // Otherwise load the default config data from the code + if options.ConfigFile != "" { + gologger.Info().Msgf("loading from file %s", options.ConfigFile) + options.sourceRunTasks() } else { - options.normalRunTasks() + gologger.Info().Msg("loading the default") + options.defaultRunTasks() } - if options.ListSources { listSources(options) os.Exit(0) @@ -120,7 +128,7 @@ func ParseOptions() *Options { // Validate the options passed by the user and if any // invalid options have been used, exit. - err = options.validateOptions() + err := options.validateOptions() if err != nil { gologger.Fatal().Msgf("Program exiting: %s\n", err) } @@ -160,3 +168,9 @@ func listSources(options *Options) { gologger.Silent().Msgf(message, source) } } +func createGroup(flagSet *goflags.FlagSet, groupName, description string, flags ...*goflags.FlagData) { + flagSet.SetGroup(groupName, description) + for _, currentFlag := range flags { + currentFlag.Group(groupName) + } +} From a64853a5162dff527f912a8f7db8f30da332a6f5 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Wed, 29 Sep 2021 22:30:08 -0500 Subject: [PATCH 02/15] lint error fix --- v2/pkg/runner/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 2567a3491..a729e3fd2 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -93,7 +93,7 @@ func ParseOptions() *Options { flagSet.BoolVar(&options.Silent, "silent", false, "Show only subdomains in output"), flagSet.BoolVar(&options.Version, "version", false, "Show version of subfinder"), ) - flagSet.Parse() + _ = flagSet.Parse() // Default output is stdout // options.Output = os.Stdout From a52484598c773fd69349ed6537afd39c8a961232 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 3 Oct 2021 02:54:54 +0530 Subject: [PATCH 03/15] misc update --- v2/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/go.mod b/v2/go.mod index 28b23e6bd..4669c3279 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -30,7 +30,7 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/projectdiscovery/goflags v0.0.7 // indirect + github.com/projectdiscovery/goflags v0.0.7 github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e // indirect github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe // indirect golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d // indirect From bb6dcac02c4b73b1bb29a0720aed0c13a6d402ff Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 3 Oct 2021 04:02:44 +0530 Subject: [PATCH 04/15] misc update --- v2/pkg/runner/options.go | 71 ++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index a729e3fd2..7843088f1 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -51,48 +51,57 @@ func ParseOptions() *Options { options := &Options{} flagSet := goflags.NewFlagSet() - flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources. It has a simple modular architecture and is optimized for speed. subfinder is built for doing one thing only - passive subdomain enumeration, and it does that very well.`) - createGroup(flagSet, "input", "Target", - flagSet.StringVar(&options.Domain, "d", "", "Domain to find subdomains for"), - flagSet.StringVar(&options.DomainsFile, "dL", "", "File containing list of domains to enumerate"), - flagSet.StringVar(&options.Sources, "sources", "", "Comma separated list of sources to use"), + flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers subdomains for websites by using passive online sources.`) + + createGroup(flagSet, "input", "Input", + flagSet.StringVarP(&options.Domain,"domain", "d", "", "Domain to find subdomains for"), + flagSet.StringVarP(&options.DomainsFile,"list", "dL", "", "File containing list of domains to enumerate"), + ) + + createGroup(flagSet, "source", "Source", + flagSet.StringVarP(&options.Sources,"sources","s", "", "Sources to use for enumeration (-s crtsh,bufferover"), + flagSet.BoolVar(&options.Recursive, "recursive", false, "Sources to use supports recursive enumeration"), + flagSet.BoolVar(&options.All, "all", false, "Use all sources (slow) for enumeration"), + flagSet.StringVarP(&options.ExcludeSources, "exclude-sources","es", "", "Sources to exclude from enumeration (-es archiveis,zoomeye)"), + ) + + createGroup(flagSet, "rate-limit", "Rate-limit", + flagSet.IntVar(&options.RateLimit, "rate-limit", 0, "Maximum number of HTTP requests to send per second"), + flagSet.IntVar(&options.Threads, "t", 10, "Number of concurrent goroutines for resolving (-active only)"), ) - createGroup(flagSet, "template", "Template", - flagSet.IntVar(&options.Threads, "t", 10, "Number of concurrent goroutines for resolving"), + + createGroup(flagSet, "optimization", "Optimization", flagSet.IntVar(&options.Timeout, "timeout", 30, "Seconds to wait before timing out"), flagSet.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results"), - flagSet.BoolVar(&options.ListSources, "ls", false, "List all available sources"), - flagSet.BoolVar(&options.Recursive, "recursive", false, "Use only recursive subdomain enumeration sources"), - flagSet.BoolVar(&options.All, "all", false, "Use all sources (slow) for enumeration"), - flagSet.StringVar(&options.ExcludeSources, "exclude-sources", "", "List of sources to exclude from enumeration"), ) - createGroup(flagSet, "filters", "FILTERING", - flagSet.StringVar(&options.Resolvers, "r", "", "Comma-separated list of resolvers to use"), - flagSet.StringVar(&options.ResolverList, "rL", "", "Text file containing list of resolvers to use"), - flagSet.BoolVar(&options.RemoveWildcard, "nW", false, "Remove Wildcard & Dead Subdomains from output"), - flagSet.StringVar(&options.LocalIPString, "b", "", "IP address to be used as local bind"), - flagSet.StringVar(&options.Proxy, "proxy", "", "HTTP proxy to use with subfinder"), + + createGroup(flagSet, "output", "Output", + flagSet.StringVarP(&options.OutputFile,"output", "o", "", "File to write output to (optional)"), + flagSet.BoolVarP(&options.JSON, "json","oJ", false, "Write output in JSONL(ines) format"), + flagSet.StringVarP(&options.OutputDirectory,"output-dir", "oD", "", "Directory to write output (-dL only)"), + flagSet.BoolVarP(&options.CaptureSources, "collect-sources","cs", false, "Include all sources in the output (-json only)"), + flagSet.BoolVarP(&options.HostIP,"ip", "oI", false, "Include host IP in output (-active only)"), ) - createGroup(flagSet, "config", "Configurations", - flagSet.StringVar(&options.ConfigFile, "config", "", "Configuration file for API Keys, etc"), + + createGroup(flagSet, "configuration", "Configuration", //flagSet.StringVar(&options.ConfigFile, "config", path.Join(config, "config.yaml"), "Configuration file for API Keys, etc"), //flagSet.StringVar(&options.SourceConfigFile, "source-config", path.Join(config, "config.yaml"), "Source Configuration file for API Keys, etc"), + flagSet.StringVar(&options.ConfigFile, "config", "", "Configuration file for API Keys, etc"), + flagSet.StringVar(&options.Resolvers, "r", "", "Comma separated list of resolvers to use"), + flagSet.StringVarP(&options.ResolverList,"rlist", "rL", "", "File containing list of resolvers to use"), + flagSet.BoolVarP(&options.RemoveWildcard,"active", "nW", false, "Display active subdomains only"), + flagSet.StringVarP(&options.LocalIPString,"bind-ip", "b", "", "IP address to be used as local bind"), + flagSet.StringVar(&options.Proxy, "proxy", "", "HTTP proxy to use with subfinder"), ) - createGroup(flagSet, "rate-limit", "RATE-LIMIT", - flagSet.IntVar(&options.RateLimit, "rate-limit", 0, "Maximum number of HTTP requests to send per second"), - ) - createGroup(flagSet, "output", "Output", - flagSet.BoolVar(&options.Verbose, "v", false, "Show Verbose output"), - flagSet.BoolVar(&options.NoColor, "nC", false, "Don't Use colors in output"), - flagSet.StringVar(&options.OutputFile, "o", "", "File to write output to (optional)"), - flagSet.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)"), - flagSet.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format"), - flagSet.BoolVar(&options.CaptureSources, "collect-sources", false, "Output host source as array of sources instead of single (first) source"), - flagSet.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format"), - flagSet.BoolVar(&options.HostIP, "oI", false, "Write output in Host,IP format"), + + createGroup(flagSet, "debug", "Debug", flagSet.BoolVar(&options.Silent, "silent", false, "Show only subdomains in output"), flagSet.BoolVar(&options.Version, "version", false, "Show version of subfinder"), + flagSet.BoolVar(&options.Verbose, "v", false, "Show Verbose output"), + flagSet.BoolVarP(&options.NoColor,"nc", "nC", false, "Disable color in output"), + flagSet.BoolVar(&options.ListSources, "ls", false, "List all available sources"), ) + _ = flagSet.Parse() // Default output is stdout From 327b9f1e225c40bf401cea5676e8f85255543eac Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Tue, 5 Oct 2021 11:18:05 -0500 Subject: [PATCH 05/15] default output changes --- v2/pkg/runner/options.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index a729e3fd2..1a3e70796 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -1,13 +1,14 @@ package runner import ( - "github.com/projectdiscovery/goflags" - "github.com/projectdiscovery/gologger" "io" "net" "os" "reflect" "strings" + + "github.com/projectdiscovery/goflags" + "github.com/projectdiscovery/gologger" ) // Options contains the configuration options for tuning @@ -96,7 +97,7 @@ func ParseOptions() *Options { _ = flagSet.Parse() // Default output is stdout - // options.Output = os.Stdout + options.Output = os.Stdout // Check if stdin pipe was given options.Stdin = hasStdin() From b120e4740546aec51e7c9bedabc344956ca35fb2 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Fri, 3 Dec 2021 11:06:11 -0600 Subject: [PATCH 06/15] readme updates for flags --- README.md | 68 +++++++++++++++++++++++----------------- v2/pkg/runner/options.go | 12 +++---- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 5d15d9741..8d4185ab8 100644 --- a/README.md +++ b/README.md @@ -53,34 +53,46 @@ subfinder -h ``` This will display help for the tool. Here are all the switches it supports. -| Flag | Description | Example | -| ---------------- | ---------------------------------------------------------- | --------------------------------------------| -| -all | Use all sources (slow) for enumeration | subfinder -d uber.com -all | -| -b | IP address to be used as local bind | subfinder -b 172.16.0.1 | -| -config | Configuration file for API Keys, etc | subfinder -config config.yaml | -| -d | Domain to find subdomains for | subfinder -d uber.com | -| -dL | File containing list of domains to enumerate | subfinder -dL hackerone-hosts.txt | -| -exclude-sources | List of sources to exclude from enumeration | subfinder -exclude-sources archiveis | -| -max-time | Minutes to wait for enumeration results (default 10) | subfinder -max-time 1 | -| -nC | Don't Use colors in output | subfinder -nC | -| -nW | Remove Wildcard & Dead Subdomains from output | subfinder -nW | -| -ls | List all available sources | subfinder -ls | -| -o | File to write output to (optional) | subfinder -o output.txt | -| -oD | Directory to write enumeration results to (optional) | subfinder -oD ~/outputs | -| -oI | Write output in Host,IP format | subfinder -oI | -| -oJ | Write output in JSON lines Format | subfinder -oJ | -| -r | Comma-separated list of resolvers to use | subfinder -r 1.1.1.1,1.0.0.1 | -| -rL | Text file containing list of resolvers to use | subfinder -rL resolvers.txt | -| -recursive | Enumeration recursive subdomains | subfinder -d news.yahoo.com -recursive | -| -silent | Show only subdomains in output | subfinder -silent | -| -sources | Comma separated list of sources to use | subfinder -sources shodan,censys | -| -t | Number of concurrent goroutines for resolving (default 10) | subfinder -t 100 | -| -timeout | Seconds to wait before timing out (default 30) | subfinder -timeout 30 | -| -proxy | HTTP proxy to use with subfinder | subfinder -proxy http://localhost:3128 | -| -rate-limit | Maximum number of HTTP requests to send per second | subfinder -rate-limit 10 | -| -v | Show Verbose output | subfinder -v | -| -version | Show current program version | subfinder -version | - +Flags: +INPUT: + -d, -domain string Domain to find subdomains for + -dL, -list string File containing list of domains to enumerate + +SOURCE: + -s, -sources string Sources to use for enumeration (-s crtsh,bufferover + -recursive Sources to use supports recursive enumeration + -all Use all sources (slow) for enumeration + -es, -exclude-sources string Sources to exclude from enumeration (-es archiveis,zoomeye) + +RATE-LIMIT: + -rate-limit int Maximum number of HTTP requests to send per second + -t int Number of concurrent goroutines for resolving (-active only) (default 10) + +OUTPUT: + -o, -output string File to write output to (optional) + -oJ, -json Write output in JSONL(ines) format + -oD, -output-dir string Directory to write output (-dL only) + -cs, -collect-sources Include all sources in the output (-json only) + -oI, -ip Include host IP in output (-active only) + +CONFIGURATION: + -config string Configuration file for API Keys, etc + -r string Comma separated list of resolvers to use + -rL, -rlist string File containing list of resolvers to use + -nW, -active Display active subdomains only + -b, -bind-ip string IP address to be used as local bind + -proxy string HTTP proxy to use with subfinder + +DEBUG: + -silent Show only subdomains in output + -version Show version of subfinder + -v Show Verbose output + -nC, -nc Disable color in output + -ls List all available sources + +OPTIMIZATION: + -timeout int Seconds to wait before timing out (default 30) + -max-time int Minutes to wait for enumeration results (default 10) # Installation diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 6fd5f7ed5..dcb6a5c48 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -71,11 +71,6 @@ func ParseOptions() *Options { flagSet.IntVar(&options.Threads, "t", 10, "Number of concurrent goroutines for resolving (-active only)"), ) - createGroup(flagSet, "optimization", "Optimization", - flagSet.IntVar(&options.Timeout, "timeout", 30, "Seconds to wait before timing out"), - flagSet.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results"), - ) - createGroup(flagSet, "output", "Output", flagSet.StringVarP(&options.OutputFile,"output", "o", "", "File to write output to (optional)"), flagSet.BoolVarP(&options.JSON, "json","oJ", false, "Write output in JSONL(ines) format"), @@ -85,8 +80,6 @@ func ParseOptions() *Options { ) createGroup(flagSet, "configuration", "Configuration", - //flagSet.StringVar(&options.ConfigFile, "config", path.Join(config, "config.yaml"), "Configuration file for API Keys, etc"), - //flagSet.StringVar(&options.SourceConfigFile, "source-config", path.Join(config, "config.yaml"), "Source Configuration file for API Keys, etc"), flagSet.StringVar(&options.ConfigFile, "config", "", "Configuration file for API Keys, etc"), flagSet.StringVar(&options.Resolvers, "r", "", "Comma separated list of resolvers to use"), flagSet.StringVarP(&options.ResolverList,"rlist", "rL", "", "File containing list of resolvers to use"), @@ -103,6 +96,11 @@ func ParseOptions() *Options { flagSet.BoolVar(&options.ListSources, "ls", false, "List all available sources"), ) + createGroup(flagSet, "optimization", "Optimization", + flagSet.IntVar(&options.Timeout, "timeout", 30, "Seconds to wait before timing out"), + flagSet.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results"), + ) + _ = flagSet.Parse() // Default output is stdout From 18dca54b14f54b2d796acbe544ec7ef64f51fe33 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Tue, 14 Dec 2021 13:19:13 -0600 Subject: [PATCH 07/15] return error and exit --- v2/pkg/runner/options.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index dcb6a5c48..e0df89dce 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -1,6 +1,7 @@ package runner import ( + "fmt" "io" "net" "os" @@ -55,15 +56,15 @@ func ParseOptions() *Options { flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers subdomains for websites by using passive online sources.`) createGroup(flagSet, "input", "Input", - flagSet.StringVarP(&options.Domain,"domain", "d", "", "Domain to find subdomains for"), - flagSet.StringVarP(&options.DomainsFile,"list", "dL", "", "File containing list of domains to enumerate"), + flagSet.StringVarP(&options.Domain, "domain", "d", "", "Domain to find subdomains for"), + flagSet.StringVarP(&options.DomainsFile, "list", "dL", "", "File containing list of domains to enumerate"), ) createGroup(flagSet, "source", "Source", - flagSet.StringVarP(&options.Sources,"sources","s", "", "Sources to use for enumeration (-s crtsh,bufferover"), + flagSet.StringVarP(&options.Sources, "sources", "s", "", "Sources to use for enumeration (-s crtsh,bufferover"), flagSet.BoolVar(&options.Recursive, "recursive", false, "Sources to use supports recursive enumeration"), flagSet.BoolVar(&options.All, "all", false, "Use all sources (slow) for enumeration"), - flagSet.StringVarP(&options.ExcludeSources, "exclude-sources","es", "", "Sources to exclude from enumeration (-es archiveis,zoomeye)"), + flagSet.StringVarP(&options.ExcludeSources, "exclude-sources", "es", "", "Sources to exclude from enumeration (-es archiveis,zoomeye)"), ) createGroup(flagSet, "rate-limit", "Rate-limit", @@ -72,19 +73,19 @@ func ParseOptions() *Options { ) createGroup(flagSet, "output", "Output", - flagSet.StringVarP(&options.OutputFile,"output", "o", "", "File to write output to (optional)"), - flagSet.BoolVarP(&options.JSON, "json","oJ", false, "Write output in JSONL(ines) format"), - flagSet.StringVarP(&options.OutputDirectory,"output-dir", "oD", "", "Directory to write output (-dL only)"), - flagSet.BoolVarP(&options.CaptureSources, "collect-sources","cs", false, "Include all sources in the output (-json only)"), - flagSet.BoolVarP(&options.HostIP,"ip", "oI", false, "Include host IP in output (-active only)"), + flagSet.StringVarP(&options.OutputFile, "output", "o", "", "File to write output to (optional)"), + flagSet.BoolVarP(&options.JSON, "json", "oJ", false, "Write output in JSONL(ines) format"), + flagSet.StringVarP(&options.OutputDirectory, "output-dir", "oD", "", "Directory to write output (-dL only)"), + flagSet.BoolVarP(&options.CaptureSources, "collect-sources", "cs", false, "Include all sources in the output (-json only)"), + flagSet.BoolVarP(&options.HostIP, "ip", "oI", false, "Include host IP in output (-active only)"), ) createGroup(flagSet, "configuration", "Configuration", flagSet.StringVar(&options.ConfigFile, "config", "", "Configuration file for API Keys, etc"), flagSet.StringVar(&options.Resolvers, "r", "", "Comma separated list of resolvers to use"), - flagSet.StringVarP(&options.ResolverList,"rlist", "rL", "", "File containing list of resolvers to use"), - flagSet.BoolVarP(&options.RemoveWildcard,"active", "nW", false, "Display active subdomains only"), - flagSet.StringVarP(&options.LocalIPString,"bind-ip", "b", "", "IP address to be used as local bind"), + flagSet.StringVarP(&options.ResolverList, "rlist", "rL", "", "File containing list of resolvers to use"), + flagSet.BoolVarP(&options.RemoveWildcard, "active", "nW", false, "Display active subdomains only"), + flagSet.StringVarP(&options.LocalIPString, "bind-ip", "b", "", "IP address to be used as local bind"), flagSet.StringVar(&options.Proxy, "proxy", "", "HTTP proxy to use with subfinder"), ) @@ -92,7 +93,7 @@ func ParseOptions() *Options { flagSet.BoolVar(&options.Silent, "silent", false, "Show only subdomains in output"), flagSet.BoolVar(&options.Version, "version", false, "Show version of subfinder"), flagSet.BoolVar(&options.Verbose, "v", false, "Show Verbose output"), - flagSet.BoolVarP(&options.NoColor,"nc", "nC", false, "Disable color in output"), + flagSet.BoolVarP(&options.NoColor, "nc", "nC", false, "Disable color in output"), flagSet.BoolVar(&options.ListSources, "ls", false, "List all available sources"), ) @@ -101,7 +102,10 @@ func ParseOptions() *Options { flagSet.IntVar(&options.MaxEnumerationTime, "max-time", 10, "Minutes to wait for enumeration results"), ) - _ = flagSet.Parse() + if err := flagSet.Parse(); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } // Default output is stdout options.Output = os.Stdout From dd8798da224be2910b7454ddbd0d36357c0adae4 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Wed, 15 Dec 2021 13:18:50 -0600 Subject: [PATCH 08/15] add missing parentheses in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d4185ab8..af9118d35 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ INPUT: -dL, -list string File containing list of domains to enumerate SOURCE: - -s, -sources string Sources to use for enumeration (-s crtsh,bufferover + -s, -sources string Sources to use for enumeration (-s crtsh,bufferover) -recursive Sources to use supports recursive enumeration -all Use all sources (slow) for enumeration -es, -exclude-sources string Sources to exclude from enumeration (-es archiveis,zoomeye) From 64c0f36f43f031f1e52f2a1f1be2e8268dbd2f4c Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Wed, 26 Jan 2022 22:38:42 -0600 Subject: [PATCH 09/15] safely deleted sources, resolvers control and added support for provider config file --- v2/pkg/runner/banners.go | 19 ++++++++----------- v2/pkg/runner/options.go | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/v2/pkg/runner/banners.go b/v2/pkg/runner/banners.go index 421fb5296..4ed8667b2 100644 --- a/v2/pkg/runner/banners.go +++ b/v2/pkg/runner/banners.go @@ -52,16 +52,13 @@ func (options *Options) sourceRunTasks() { // defaultRunTasks runs the app with default configuration func (options *Options) defaultRunTasks() { - // Setting default configurations data - config := ConfigFile{ - // Use the default list of resolvers by marshaling it to the config - Resolvers: resolve.DefaultResolvers, - // Use the default list of passive sources - Sources: passive.DefaultSources, - // Use the default list of all passive sources - AllSources: passive.DefaultAllSources, - // Use the default list of recursive sources - Recursive: passive.DefaultRecursiveSources, + configFile, err := UnmarshalRead(options.ConfigFile) + if err != nil { + gologger.Fatal().Msgf("Could not read configuration file %s: %s\n", options.ConfigFile, err) } - options.YAMLConfig = config + configFile.Sources = passive.DefaultSources + configFile.AllSources = passive.DefaultAllSources + configFile.Recursive = passive.DefaultRecursiveSources + configFile.Resolvers = resolve.DefaultResolvers + options.YAMLConfig = configFile } diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index e0df89dce..44e19ec82 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -5,6 +5,7 @@ import ( "io" "net" "os" + "path" "reflect" "strings" @@ -51,7 +52,11 @@ type Options struct { // ParseOptions parses the command line flags provided by a user func ParseOptions() *Options { options := &Options{} - + config, err := GetConfigDirectory() + if err != nil { + // This should never be reached + gologger.Fatal().Msgf("Could not get user home: %s\n", err) + } flagSet := goflags.NewFlagSet() flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers subdomains for websites by using passive online sources.`) @@ -103,6 +108,15 @@ func ParseOptions() *Options { ) if err := flagSet.Parse(); err != nil { + if strings.Contains(err.Error(), "-providerfile") { + if c, cErr := flagSet.GetProviderConfig(); cErr == nil { + delete(c, "resolvers") + delete(c, "sources") + delete(c, "all-sources") + delete(c, "recursive") + flagSet.GenerateProviderConfig(c) + } + } fmt.Println(err.Error()) os.Exit(1) } @@ -131,6 +145,11 @@ func ParseOptions() *Options { options.sourceRunTasks() } else { gologger.Info().Msg("loading the default") + if flagSet.ProviderConfigFile { + options.ConfigFile = path.Join(config, "provider.yaml") + } else { + options.ConfigFile = path.Join(config, "config.yaml") + } options.defaultRunTasks() } if options.ListSources { @@ -140,7 +159,7 @@ func ParseOptions() *Options { // Validate the options passed by the user and if any // invalid options have been used, exit. - err := options.validateOptions() + err = options.validateOptions() if err != nil { gologger.Fatal().Msgf("Program exiting: %s\n", err) } From cc44050adf0fe81cc3333f28ad7c0073a9237d2a Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Thu, 27 Jan 2022 13:34:12 -0600 Subject: [PATCH 10/15] go mod and file path changes --- v2/go.mod | 2 +- v2/pkg/runner/options.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/v2/go.mod b/v2/go.mod index 4669c3279..ceed17c84 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -30,7 +30,7 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/projectdiscovery/goflags v0.0.7 + github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e // indirect github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe // indirect golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d // indirect diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 44e19ec82..8394c9de2 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -5,7 +5,7 @@ import ( "io" "net" "os" - "path" + "path/filepath" "reflect" "strings" @@ -146,9 +146,9 @@ func ParseOptions() *Options { } else { gologger.Info().Msg("loading the default") if flagSet.ProviderConfigFile { - options.ConfigFile = path.Join(config, "provider.yaml") + options.ConfigFile = filepath.Join(config, "provider.yaml") } else { - options.ConfigFile = path.Join(config, "config.yaml") + options.ConfigFile = filepath.Join(config, "config.yaml") } options.defaultRunTasks() } From 521f825481030a1aa8c233e2855f52a8659c09d6 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Thu, 27 Jan 2022 13:35:14 -0600 Subject: [PATCH 11/15] go sum changes --- v2/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v2/go.sum b/v2/go.sum index a99c48040..3c4c126db 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -91,6 +91,8 @@ github.com/projectdiscovery/dnsx v1.0.3 h1:IbMlMEeki6mlllHxATVh50+eOBwyOn8OKD1Cl github.com/projectdiscovery/dnsx v1.0.3/go.mod h1:M79ADVHwnNQM6kN2J4/XvjydJ3cDhaHHoI5lxJR2Z/A= github.com/projectdiscovery/fdmax v0.0.3 h1:FM6lv9expZ/rEEBI9tkRh6tx3DV0gtpwzdc0h7bGPqg= github.com/projectdiscovery/fdmax v0.0.3/go.mod h1:NWRcaR7JTO7fC27H4jCl9n7Z+KIredwpgw1fV+4KrKI= +github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c h1:TZ+p5LdrgkbsYHchUPezjYCUXPQ1bhBcF/mUJdr9TDo= +github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= github.com/projectdiscovery/goflags v0.0.7 h1:aykmRkrOgDyRwcvGrK3qp+9aqcjGfAMs/+LtRmtyxwk= github.com/projectdiscovery/goflags v0.0.7/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= github.com/projectdiscovery/gologger v1.0.0/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= From 816f4be5ea980ec7256ba4e4a856056839b2d864 Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Thu, 3 Feb 2022 11:24:13 -0600 Subject: [PATCH 12/15] use default file --- v2/pkg/runner/options.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 8394c9de2..0db9ca5f7 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -5,7 +5,6 @@ import ( "io" "net" "os" - "path/filepath" "reflect" "strings" @@ -52,11 +51,7 @@ type Options struct { // ParseOptions parses the command line flags provided by a user func ParseOptions() *Options { options := &Options{} - config, err := GetConfigDirectory() - if err != nil { - // This should never be reached - gologger.Fatal().Msgf("Could not get user home: %s\n", err) - } + var err error flagSet := goflags.NewFlagSet() flagSet.SetDescription(`Subfinder is a subdomain discovery tool that discovers subdomains for websites by using passive online sources.`) @@ -108,7 +103,7 @@ func ParseOptions() *Options { ) if err := flagSet.Parse(); err != nil { - if strings.Contains(err.Error(), "-providerfile") { + if strings.Contains(err.Error(), goflags.ProviderFlagName) { if c, cErr := flagSet.GetProviderConfig(); cErr == nil { delete(c, "resolvers") delete(c, "sources") @@ -145,11 +140,7 @@ func ParseOptions() *Options { options.sourceRunTasks() } else { gologger.Info().Msg("loading the default") - if flagSet.ProviderConfigFile { - options.ConfigFile = filepath.Join(config, "provider.yaml") - } else { - options.ConfigFile = filepath.Join(config, "config.yaml") - } + options.ConfigFile = flagSet.GetProviderConfigPath() options.defaultRunTasks() } if options.ListSources { From ee2f32129ddd889b18f702e348170140e5209ebd Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Thu, 3 Feb 2022 11:35:19 -0600 Subject: [PATCH 13/15] adding missing parentheses --- v2/pkg/runner/options.go | 1 + 1 file changed, 1 insertion(+) diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 3f624fbb9..f80264206 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -198,6 +198,7 @@ func createGroup(flagSet *goflags.FlagSet, groupName, description string, flags for _, currentFlag := range flags { currentFlag.Group(groupName) } +} func (options *Options) preProcessOptions() { options.Domain, _ = sanitize(options.Domain) From 6039a5cd44fcdf37bd5063549b8b6f61bdc35bdf Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Thu, 3 Feb 2022 11:38:13 -0600 Subject: [PATCH 14/15] go mod update --- v2/go.mod | 2 +- v2/go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/v2/go.mod b/v2/go.mod index ceed17c84..26912855f 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -30,7 +30,7 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c + github.com/projectdiscovery/goflags v0.0.7-0.20220203040211-bbdcd4c06ed5 github.com/projectdiscovery/retryabledns v1.0.12-0.20210419174848-eec3ac17d61e // indirect github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe // indirect golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d // indirect diff --git a/v2/go.sum b/v2/go.sum index 3c4c126db..327ce9dda 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -93,6 +93,8 @@ github.com/projectdiscovery/fdmax v0.0.3 h1:FM6lv9expZ/rEEBI9tkRh6tx3DV0gtpwzdc0 github.com/projectdiscovery/fdmax v0.0.3/go.mod h1:NWRcaR7JTO7fC27H4jCl9n7Z+KIredwpgw1fV+4KrKI= github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c h1:TZ+p5LdrgkbsYHchUPezjYCUXPQ1bhBcF/mUJdr9TDo= github.com/projectdiscovery/goflags v0.0.7-0.20220127045615-f8749b99fe7c/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= +github.com/projectdiscovery/goflags v0.0.7-0.20220203040211-bbdcd4c06ed5 h1:QXXMALyjxKNTvCneAxxzSjtiOl2lAspbjP0B4TnetrQ= +github.com/projectdiscovery/goflags v0.0.7-0.20220203040211-bbdcd4c06ed5/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= github.com/projectdiscovery/goflags v0.0.7 h1:aykmRkrOgDyRwcvGrK3qp+9aqcjGfAMs/+LtRmtyxwk= github.com/projectdiscovery/goflags v0.0.7/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY= github.com/projectdiscovery/gologger v1.0.0/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= From 3a4adb787aa28d21abb28bf3e3e352d8c3471aef Mon Sep 17 00:00:00 2001 From: LuitelSamikshya Date: Mon, 7 Feb 2022 10:22:20 -0600 Subject: [PATCH 15/15] validations --- v2/pkg/runner/banners.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v2/pkg/runner/banners.go b/v2/pkg/runner/banners.go index 4ed8667b2..a9ebf1030 100644 --- a/v2/pkg/runner/banners.go +++ b/v2/pkg/runner/banners.go @@ -1,6 +1,9 @@ package runner import ( + "strings" + + "github.com/projectdiscovery/goflags" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/subfinder/v2/pkg/passive" "github.com/projectdiscovery/subfinder/v2/pkg/resolve" @@ -53,7 +56,7 @@ func (options *Options) sourceRunTasks() { // defaultRunTasks runs the app with default configuration func (options *Options) defaultRunTasks() { configFile, err := UnmarshalRead(options.ConfigFile) - if err != nil { + if err != nil && !strings.Contains(err.Error(), goflags.ErrEofYaml.Error()) { gologger.Fatal().Msgf("Could not read configuration file %s: %s\n", options.ConfigFile, err) } configFile.Sources = passive.DefaultSources