diff --git a/helpers/file.go b/helpers/file.go
@@ -15,7 +15,8 @@ type FileScanner struct {
func LoadTargetFile(targetPath string) *FileScanner {
file, err := os.Open(targetPath)
if err != nil {
- fmt.Printf("%v, %+v", err, targetPath)
+ fmt.Printf("[!] Could not open target file %q: %v\n", targetPath, err)
+ os.Exit(1)
}
scanner := bufio.NewScanner(file)
diff --git a/helpers/net.go b/helpers/net.go
@@ -14,19 +14,6 @@ import (
const HttpTimeout = 15 * time.Second
-func ParseDomain(website string) string {
- if strings.HasPrefix(website, "http") {
- parsedUrl, err := url.Parse(website)
- if err != nil {
- fmt.Printf("%s", err)
- }
-
- website = parsedUrl.Host
- }
-
- return website
-}
-
func GetHttpTransport() *http.Transport {
var proxy = os.Getenv("HTTP_PROXY")
url, err := url.Parse(proxy)
@@ -74,6 +61,7 @@ func GetCurrentIP() string {
fmt.Printf("[!] Could not query public IP address: %s\n", err.Error())
return ""
}
+ defer resp.Body.Close()
result, err := io.ReadAll(resp.Body)
if err != nil {
@@ -118,12 +106,10 @@ func HasUnavailableWebInterface(url string) bool {
}
req.Header.Add("User-Agent", GetUserAgent())
resp, err := client.Do(req)
- if err != nil {
+ if err != nil || resp == nil {
return true
}
+ defer resp.Body.Close()
- if resp == nil || resp.StatusCode >= http.StatusBadGateway {
- return true
- }
- return false
+ return resp.StatusCode >= http.StatusBadGateway
}
diff --git a/osint/dnsx.go b/osint/dnsx.go
@@ -83,16 +83,14 @@ func (d *Dnsx) Run(domain string) {
fo, err := os.Create(d.outfile)
if err != nil {
- panic(err)
+ fmt.Printf("[!] Dnsx: failed to create %s: %v\n", d.outfile, err)
+ return
}
- defer func() {
- if err := fo.Close(); err != nil {
- panic(err)
- }
- }()
+ defer fo.Close()
if _, err := fo.Write(prettyJSON.Bytes()); err != nil {
- panic(err)
+ fmt.Printf("[!] Dnsx: failed to write %s: %v\n", d.outfile, err)
+ return
}
fmt.Printf("[OSINT %s] Dnsx results are stored in %s\n", domain, d.outfile)
diff --git a/osint/subfinder.go b/osint/subfinder.go
@@ -37,27 +37,27 @@ func (s *Subfinder) Run(domain string) {
subfinder, err := runner.NewRunner(subfinderOpts)
if err != nil {
- log.Fatalf("failed to create subfinder runner: %v", err)
+ fmt.Printf("[!] Subfinder: failed to create runner: %v\n", err)
+ return
}
output := &bytes.Buffer{}
_, err = subfinder.EnumerateSingleDomainWithCtx(context.Background(), domain, []io.Writer{output})
if err != nil {
- log.Fatalf("failed to enumerate single domain: %v", err)
+ fmt.Printf("[!] Subfinder: failed to enumerate %s: %v\n", domain, err)
+ return
}
fo, err := os.Create(s.outfile)
if err != nil {
- panic(err)
+ fmt.Printf("[!] Subfinder: failed to create %s: %v\n", s.outfile, err)
+ return
}
- defer func() {
- if err := fo.Close(); err != nil {
- panic(err)
- }
- }()
+ defer fo.Close()
if _, err := fo.Write(output.Bytes()); err != nil {
- panic(err)
+ fmt.Printf("[!] Subfinder: failed to write %s: %v\n", s.outfile, err)
+ return
}
fmt.Printf("[OSINT %s] Subfinder are stored in %s\n\n", domain, s.outfile)
diff --git a/scan/robotstxt.go b/scan/robotstxt.go
@@ -35,12 +35,12 @@ func (d *RobotsTxt) Run(domain string) {
req.Header.Add("User-Agent", helper.GetUserAgent())
resp, err := client.Do(req)
-
if err != nil {
fmt.Printf("%v", err)
+ continue
}
- if resp != nil && resp.StatusCode != http.StatusNotFound {
+ if resp.StatusCode != http.StatusNotFound {
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("%v", err)
@@ -51,6 +51,7 @@ func (d *RobotsTxt) Run(domain string) {
} else {
fmt.Println("----- Sorry, got 404 status code for robots.txt ----- ")
}
+ resp.Body.Close()
}
fmt.Printf("[SCAN %s] RobotsTxt scan for %s completed\n\n", domain, domain)
diff --git a/scan/sitemap.go b/scan/sitemap.go
@@ -38,12 +38,12 @@ func (d *Sitemap) Run(domain string) {
req.Header.Add("User-Agent", helper.GetUserAgent())
resp, err := client.Do(req)
-
if err != nil {
fmt.Printf("%v", err)
+ continue
}
- if resp != nil && resp.StatusCode != http.StatusNotFound {
+ if resp.StatusCode != http.StatusNotFound {
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("%v", err)
@@ -60,6 +60,7 @@ func (d *Sitemap) Run(domain string) {
} else {
fmt.Println("----- Sorry, got 404 status code for sitemap.xml -----")
}
+ resp.Body.Close()
}
fmt.Printf("[SCAN %s] Sitemap scan for %s completed\n\n", domain, domain)
| | | | | |