From 5afb14f67e876d6ff9765f9fa1840ed529a18f7e Mon Sep 17 00:00:00 2001 From: ice3man Date: Tue, 3 Apr 2018 17:26:17 +0530 Subject: [PATCH] Added Hackertarget Data Source --- .../sources/hackertarget/hackertarget.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 libsubfinder/sources/hackertarget/hackertarget.go diff --git a/libsubfinder/sources/hackertarget/hackertarget.go b/libsubfinder/sources/hackertarget/hackertarget.go new file mode 100644 index 0000000..1249dda --- /dev/null +++ b/libsubfinder/sources/hackertarget/hackertarget.go @@ -0,0 +1,58 @@ +// +// hackertaget.go : A golang based Hackertarget subdomains search client +// Written By : @ice3man (Nizamul Rana) +// +// Distributed Under MIT License +// Copyrights (C) 2018 Ice3man +// + +package hackertarget + +import ( + "io/ioutil" + "strings" + "bufio" + "fmt" + + "subfinder/libsubfinder/helper" +) + +// +// Query : Queries awesome Hackertarget subdomain search service +// @param state : current application state, holds all information found +// +// @return subdomain : String array containing subdomains found +// @return err : nil if successfull and error if failed +// +func Query(state *helper.State) (subdomains []string, err error) { + + // Make a http request to CRT.SH server and request output in JSON + // format. + // I Think 5 minutes would be more than enough for CRT.SH :-) + resp, err := helper.GetHTTPResponse("https://api.hackertarget.com/hostsearch/?q="+state.Domain, 3000) + if err != nil { + return subdomains, err + } + + // Get the response body + resp_body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return subdomains, err + } + + scanner := bufio.NewScanner(strings.NewReader(string(resp_body))) + for scanner.Scan() { + subdomain := strings.Split(scanner.Text(), ",")[0] + subdomains = append(subdomains, subdomain) + + if state.Verbose == true { + if state.Color == true { + fmt.Printf("\n[\033[31;1;4mHACKERTARGET\033[0m] %s", subdomain) + } else { + fmt.Printf("\n[HACKERTARGET] %s", subdomain) + } + } + } + + return subdomains, nil +}