diff --git a/v2/pkg/protocols/dns/dns.go b/v2/pkg/protocols/dns/dns.go index 55be679a6..2f6697f79 100644 --- a/v2/pkg/protocols/dns/dns.go +++ b/v2/pkg/protocols/dns/dns.go @@ -1,7 +1,6 @@ package dns import ( - "net" "strings" "github.com/miekg/dns" @@ -9,6 +8,7 @@ import ( "github.com/weppos/publicsuffix-go/publicsuffix" + "github.com/projectdiscovery/iputil" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/protocols" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions" @@ -170,11 +170,21 @@ func (request *Request) Requests() int { } // Make returns the request to be sent for the protocol -func (request *Request) Make(domain string) (*dns.Msg, error) { - if request.question != dns.TypePTR && net.ParseIP(domain) != nil { - return nil, errors.New("cannot use IP address as DNS input") +func (request *Request) Make(host string) (*dns.Msg, error) { + isIP := iputil.IsIP(host) + switch { + case request.question == dns.TypePTR && isIP: + var err error + host, err = dns.ReverseAddr(host) + if err != nil { + return nil, err + } + default: + if isIP { + return nil, errors.New("cannot use IP address as DNS input") + } + host = dns.Fqdn(host) } - domain = dns.Fqdn(domain) // Build a request on the specified URL req := new(dns.Msg) @@ -183,7 +193,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(host)) q.Name = dns.Fqdn(final) q.Qclass = request.class