small change to add http+dns combined requests on same target

dev
Mzack9999 2020-04-24 15:19:43 +02:00
parent f297f87cec
commit 5f1ff92d8b
2 changed files with 19 additions and 4 deletions

View File

@ -234,22 +234,28 @@ func (r *Runner) sendRequest(template *templates.Template, request interface{},
} }
} }
if isDNS(URL) { // eventually extracts dns from url
var domain string = URL
if isURL(URL) {
domain = extractDomain(URL)
}
// double check we have a valid dns and many times net/http extracts additional URL parts (credentials, port, etc...)
if isDNS(domain) {
dnsRequest, ok := request.(*requests.DNSRequest) dnsRequest, ok := request.(*requests.DNSRequest)
if !ok { if !ok {
return return
} }
// Compile each request for the template based on the URL // Compile each request for the template based on the URL
compiledRequest, err := dnsRequest.MakeDNSRequest(URL) compiledRequest, err := dnsRequest.MakeDNSRequest(domain)
if err != nil { if err != nil {
gologger.Warningf("[%s] Could not make request %s: %s\n", template.ID, URL, err) gologger.Warningf("[%s] Could not make request %s: %s\n", template.ID, domain, err)
return return
} }
// Send the request to the target servers // Send the request to the target servers
resp, err := dnsclient.Do(compiledRequest) resp, err := dnsclient.Do(compiledRequest)
if err != nil { if err != nil {
gologger.Warningf("[%s] Could not send request %s: %s\n", template.ID, URL, err) gologger.Warningf("[%s] Could not send request %s: %s\n", template.ID, domain, err)
return return
} }

View File

@ -48,6 +48,15 @@ func isURL(toTest string) bool {
return true return true
} }
func extractDomain(URL string) string {
u, err := url.Parse(URL)
if err != nil {
return ""
}
return u.Hostname()
}
// isDNS tests a string to determine if it is a well-structured dns or not // isDNS tests a string to determine if it is a well-structured dns or not
// even if it's oneliner, we leave it wrapped in a function call for // even if it's oneliner, we leave it wrapped in a function call for
// future improvements // future improvements