From 33f6f510b12a413b28791a1492602d97e71edc94 Mon Sep 17 00:00:00 2001 From: mzack Date: Fri, 14 Jan 2022 12:00:59 +0100 Subject: [PATCH 1/2] Extending http variables list with dns generated variables --- v2/pkg/protocols/dns/dns.go | 5 +++-- v2/pkg/protocols/http/build_request.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/v2/pkg/protocols/dns/dns.go b/v2/pkg/protocols/dns/dns.go index 55be679a..507883fe 100644 --- a/v2/pkg/protocols/dns/dns.go +++ b/v2/pkg/protocols/dns/dns.go @@ -183,7 +183,7 @@ func (request *Request) Make(domain string) (*dns.Msg, error) { var q dns.Question - final := replacer.Replace(request.Name, generateDNSVariables(domain)) + final := replacer.Replace(request.Name, GenerateDNSVariables(domain)) q.Name = dns.Fqdn(final) q.Qclass = request.class @@ -250,7 +250,8 @@ func classToInt(class string) uint16 { return uint16(result) } -func generateDNSVariables(domain string) map[string]interface{} { +// GenerateDNSVariables from a dns name +func GenerateDNSVariables(domain string) map[string]interface{} { parsed, err := publicsuffix.Parse(strings.TrimSuffix(domain, ".")) if err != nil { return map[string]interface{}{"FQDN": domain} diff --git a/v2/pkg/protocols/http/build_request.go b/v2/pkg/protocols/http/build_request.go index 44622f10..cfe96526 100644 --- a/v2/pkg/protocols/http/build_request.go +++ b/v2/pkg/protocols/http/build_request.go @@ -20,6 +20,7 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/replacer" + "github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/race" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/raw" "github.com/projectdiscovery/nuclei/v2/pkg/types" @@ -377,7 +378,7 @@ func generateVariables(parsed *url.URL, trailingSlash bool) map[string]interface if base == "." { base = "" } - return map[string]interface{}{ + httpVariables := map[string]interface{}{ "BaseURL": parsed.String(), "RootURL": fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host), "Hostname": parsed.Host, @@ -387,4 +388,5 @@ func generateVariables(parsed *url.URL, trailingSlash bool) map[string]interface "File": base, "Scheme": parsed.Scheme, } + return generators.MergeMaps(httpVariables, dns.GenerateDNSVariables(domain)) } From d7f7d9d1fca8c9ab51b18d96713151f0432749e8 Mon Sep 17 00:00:00 2001 From: mzack Date: Fri, 14 Jan 2022 12:03:24 +0100 Subject: [PATCH 2/2] fixing function name --- v2/pkg/protocols/dns/dns_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/pkg/protocols/dns/dns_test.go b/v2/pkg/protocols/dns/dns_test.go index 0aae3ed2..d5bfbdb1 100644 --- a/v2/pkg/protocols/dns/dns_test.go +++ b/v2/pkg/protocols/dns/dns_test.go @@ -11,7 +11,7 @@ import ( ) func TestGenerateDNSVariables(t *testing.T) { - vars := generateDNSVariables("www.projectdiscovery.io") + vars := GenerateDNSVariables("www.projectdiscovery.io") require.Equal(t, map[string]interface{}{ "FQDN": "www.projectdiscovery.io", "RDN": "projectdiscovery.io",