From 0b898020427f4c05f2667396fcaeee24984f8629 Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Mon, 25 Jun 2018 11:28:59 +0530 Subject: [PATCH] Fixed error handling removing ineffectual assignments --- libsubfinder/output/output.go | 9 +++++++ libsubfinder/sources/censys/censys.go | 21 +++++++++++++++ .../sources/dnsdumpster/dnsdumpster.go | 12 +++++++++ .../sources/passivetotal/passivetotal.go | 7 +++++ libsubfinder/sources/riddler/riddler.go | 26 +++++++++++++++++++ .../sources/securitytrails/securitytrails.go | 6 +++++ 6 files changed, 81 insertions(+) diff --git a/libsubfinder/output/output.go b/libsubfinder/output/output.go index 388eb0ca7..75fad032e 100644 --- a/libsubfinder/output/output.go +++ b/libsubfinder/output/output.go @@ -54,6 +54,9 @@ func WriteOutputJSON(state *helper.State, subdomains []string) error { // Write the output to file err = ioutil.WriteFile(state.Output, data, 0644) + if err != nil { + return err + } return nil } @@ -79,6 +82,9 @@ func WriteOutputAquatoneJSON(state *helper.State, subdomains []helper.Domain) er // Write the output to file err = ioutil.WriteFile(state.Output, data, 0644) + if err != nil { + return err + } return nil } @@ -118,6 +124,9 @@ func WriteOutputToDir(state *helper.State, subdomains []string, domain string) ( // Write the output to file err = ioutil.WriteFile(state.OutputDir+domain+"_hosts.json", data, 0644) + if err != nil { + return err + } return nil diff --git a/libsubfinder/sources/censys/censys.go b/libsubfinder/sources/censys/censys.go index 8fa064672..382263e02 100644 --- a/libsubfinder/sources/censys/censys.go +++ b/libsubfinder/sources/censys/censys.go @@ -65,6 +65,13 @@ func Query(args ...interface{}) interface{} { client := &http.Client{} req, err := http.NewRequest("POST", "https://www.censys.io/api/v1/search/certificates", bytes.NewBuffer(request)) + if err != nil { + if !state.Silent { + fmt.Printf("\ncensys: %v\n", err) + } + return subdomains + } + req.SetBasicAuth(username, key) // Set content type as application/json @@ -134,6 +141,13 @@ func Query(args ...interface{}) interface{} { client := &http.Client{} req, err := http.NewRequest("POST", "https://www.censys.io/api/v1/search/certificates", bytes.NewBuffer(request)) + if err != nil { + if !state.Silent { + fmt.Printf("\ncensys: %v\n", err) + } + return subdomains + } + req.SetBasicAuth(username, key) // Set content type as application/json @@ -202,6 +216,13 @@ func Query(args ...interface{}) interface{} { client := &http.Client{} req, err := http.NewRequest("POST", "https://www.censys.io/api/v1/search/certificates", bytes.NewBuffer(request)) + if err != nil { + if !state.Silent { + fmt.Printf("\ncensys: %v\n", err) + } + return subdomains + } + req.SetBasicAuth(username, key) // Set content type as application/json diff --git a/libsubfinder/sources/dnsdumpster/dnsdumpster.go b/libsubfinder/sources/dnsdumpster/dnsdumpster.go index 58812aa60..0b4f52721 100644 --- a/libsubfinder/sources/dnsdumpster/dnsdumpster.go +++ b/libsubfinder/sources/dnsdumpster/dnsdumpster.go @@ -72,6 +72,12 @@ func Query(args ...interface{}) interface{} { // Create a post request to get subdomain data req, err := http.NewRequest("POST", "https://dnsdumpster.com", strings.NewReader(form.Encode())) + if err != nil { + if !state.Silent { + fmt.Printf("\ndnsdumpster: %v\n", err) + } + return subdomains + } req.PostForm = form req.Header.Add("Content-Type", "application/x-www-form-urlencoded") @@ -79,6 +85,12 @@ func Query(args ...interface{}) interface{} { req.Header.Set("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1") resp, err = hc.Do(req) + if err != nil { + if !state.Silent { + fmt.Printf("\ndnsdumpster: %v\n", err) + } + return subdomains + } // Get the response body body, err = ioutil.ReadAll(resp.Body) diff --git a/libsubfinder/sources/passivetotal/passivetotal.go b/libsubfinder/sources/passivetotal/passivetotal.go index 7e6944785..6813caace 100644 --- a/libsubfinder/sources/passivetotal/passivetotal.go +++ b/libsubfinder/sources/passivetotal/passivetotal.go @@ -46,6 +46,13 @@ func Query(args ...interface{}) interface{} { client := &http.Client{} req, err := http.NewRequest("GET", "https://api.passivetotal.org/v2/enrichment/subdomains", bytes.NewBuffer(request)) + if err != nil { + if !state.Silent { + fmt.Printf("\npassivetotal: %v\n", err) + } + return subdomains + } + req.SetBasicAuth(username, key) // Set content type as application/json diff --git a/libsubfinder/sources/riddler/riddler.go b/libsubfinder/sources/riddler/riddler.go index 88915d5ef..694614602 100644 --- a/libsubfinder/sources/riddler/riddler.go +++ b/libsubfinder/sources/riddler/riddler.go @@ -49,9 +49,22 @@ func Query(args ...interface{}) interface{} { // Create a post request to get subdomain data req, err := http.NewRequest("POST", "https://riddler.io/auth/login", bytes.NewBuffer(data)) + if err != nil { + if !state.Silent { + fmt.Printf("\nriddler: %v\n", err) + } + return subdomains + } + req.Header.Add("Content-Type", "application/json") resp, err := hc.Do(req) + if err != nil { + if !state.Silent { + fmt.Printf("\nriddler: %v\n", err) + } + return subdomains + } // Get the response body body, err := ioutil.ReadAll(resp.Body) @@ -80,10 +93,23 @@ func Query(args ...interface{}) interface{} { data = []byte(`{"query":"pld:` + domain + `", "output":"host", "limit":500}`) req, err = http.NewRequest("POST", "https://riddler.io/api/search", bytes.NewBuffer(data)) + if err != nil { + if !state.Silent { + fmt.Printf("\nriddler: %v\n", err) + } + return subdomains + } + req.Header.Add("Content-Type", "application/json") req.Header.Add("Authentication-Token", auth.Response.User.AuthenticationToken) resp, err = hc.Do(req) + if err != nil { + if !state.Silent { + fmt.Printf("\nriddler: %v\n", err) + } + return subdomains + } // Get the response body body, err = ioutil.ReadAll(resp.Body) diff --git a/libsubfinder/sources/securitytrails/securitytrails.go b/libsubfinder/sources/securitytrails/securitytrails.go index 1882c15ff..0fee8a44d 100644 --- a/libsubfinder/sources/securitytrails/securitytrails.go +++ b/libsubfinder/sources/securitytrails/securitytrails.go @@ -40,6 +40,12 @@ func Query(args ...interface{}) interface{} { client := &http.Client{} req, err := http.NewRequest("GET", "https://api.securitytrails.com/v1/domain/"+domain+"/subdomains", nil) + if err != nil { + if !state.Silent { + fmt.Printf("\npassivetotal: %v\n", err) + } + return subdomains + } req.Header.Add("APIKEY", securitytrailsKey)