From 3abfed25e0e03f0cc5a1637ade8832fc0c892820 Mon Sep 17 00:00:00 2001 From: ice3man Date: Fri, 6 Apr 2018 18:31:36 +0530 Subject: [PATCH] Updated Subdomain Validation Code --- libsubfinder/engines/passive/passive.go | 9 ++++++--- libsubfinder/helper/misc.go | 13 +++++++++++++ libsubfinder/helper/state.go | 7 ++++++- main.go | 10 +++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libsubfinder/engines/passive/passive.go b/libsubfinder/engines/passive/passive.go index a0cc956..29dd202 100644 --- a/libsubfinder/engines/passive/passive.go +++ b/libsubfinder/engines/passive/passive.go @@ -63,9 +63,12 @@ func PassiveDiscovery(state *helper.State) (finalPassiveSubdomains []string) { } // Now remove duplicate items from the slice - unique_passive_subdomains := helper.Unique(finalPassiveSubdomains) - fmt.Printf("\n\n[#] Total %d Unique subdomains found passively\n\n", len(unique_passive_subdomains)) - for _, subdomain := range unique_passive_subdomains { + uniquePassiveSubdomains := helper.Unique(finalPassiveSubdomains) + // Now, validate all subdomains found + validPassiveSubdomains := helper.Validate(state, uniquePassiveSubdomains) + + fmt.Printf("\n\n[#] Total %d Unique subdomains found passively\n\n", len(validPassiveSubdomains)) + for _, subdomain := range validPassiveSubdomains { fmt.Println(subdomain) } diff --git a/libsubfinder/helper/misc.go b/libsubfinder/helper/misc.go index 5f86861..06ff281 100644 --- a/libsubfinder/helper/misc.go +++ b/libsubfinder/helper/misc.go @@ -86,3 +86,16 @@ func Unique(strSlice []string) []string { } return list } + +// +// Returns unique valid subdomains found +// +func Validate(state *State, strslice []string) (subdomains []string) { + for _, entry := range strslice { + if state.Regex.MatchString(entry) == true { + subdomains = append(subdomains, entry) + } + } + + return subdomains +} \ No newline at end of file diff --git a/libsubfinder/helper/state.go b/libsubfinder/helper/state.go index 8e285ee..ebf875a 100644 --- a/libsubfinder/helper/state.go +++ b/libsubfinder/helper/state.go @@ -9,6 +9,10 @@ package helper +import ( + "regexp" +) + // Holds the State read in from the CLI type State struct { Color bool // Whether to use color or not @@ -21,6 +25,7 @@ type State struct { Bruteforce bool // Flag to decide whether to bruteforce or not WildcardIPs []string // Wildcard IP Structure IsWildcard bool // Does the host has wildcard subdomains, if yes parse them carefully + Regex *regexp.Regexp // Regex object for parsing current subdomains ConfigState Config // Current configuration file state } @@ -37,5 +42,5 @@ func InitState() (state State, err error) { return state, err } - return State{true, 10, 180, false, "", false, "", false, []string{}, true, *config}, nil + return State{true, 10, 180, false, "", false, "", false, []string{}, true, ®exp.Regexp{}, *config}, nil } diff --git a/main.go b/main.go index b1e8647..ba5983c 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,11 @@ import ( "fmt" "flag" "os" + "regexp" "subfinder/libsubfinder/helper" "subfinder/libsubfinder/engines/passive" + //"subfinder/libsubfinder/engines/bruteforce" ) @@ -40,6 +42,8 @@ func ParseCmdLine() (state *helper.State, err error) { flag.IntVar(&s.Timeout, "timeout", 180, "Timeout for passive discovery services") flag.StringVar(&s.Domain, "d", "", "Domain to find subdomains for") flag.BoolVar(&s.Recursive, "r", true, "Use recursion to find subdomains") + flag.StringVar(&s.Wordlist, "w", "", "Wordlist for doing subdomain bruteforcing") + flag.BoolVar(&s.Bruteforce, "b", false, "Use bruteforcing to find subdomains") flag.Parse() @@ -50,7 +54,7 @@ func ParseCmdLine() (state *helper.State, err error) { func main() { fmt.Println(banner) - fmt.Printf("\nSubFinder v0.1.0 Made with ❤ by @Ice3man") + fmt.Printf("\nSubFinder v0.1.0 Made with %s❤%s by @Ice3man", helper.Green, helper.Reset) fmt.Printf("\n==================================================") state, err := ParseCmdLine() @@ -65,5 +69,9 @@ func main() { os.Exit(1) } + // Create a regex for validating subdomains found + state.Regex, _ = regexp.Compile("(.*)."+state.Domain) + passive.PassiveDiscovery(state) + //bruteforce.Bruteforce(state) }