mirror of https://github.com/daffainfo/nuclei.git
Adding support for custom resolvers in DNS templates
parent
7d05446f29
commit
407e5cbfeb
|
@ -72,6 +72,8 @@ type Request struct {
|
|||
// description: |
|
||||
// Recursion determines if resolver should recurse all records to get fresh results.
|
||||
Recursion bool `yaml:"recursion,omitempty" jsonschema:"title=recurse all servers,description=Recursion determines if resolver should recurse all records to get fresh results"`
|
||||
// Resolvers to use for the dns requests
|
||||
Resolvers []string `yaml:"resolvers,omitempty" jsonschema:"title=Resolvers,description=Define resolvers to use within the template"`
|
||||
}
|
||||
|
||||
// GetID returns the unique ID of the request if any.
|
||||
|
@ -81,10 +83,14 @@ func (r *Request) GetID() string {
|
|||
|
||||
// Compile compiles the protocol request for further execution.
|
||||
func (r *Request) Compile(options *protocols.ExecuterOptions) error {
|
||||
// Create a dns client for the class
|
||||
client, err := dnsclientpool.Get(options.Options, &dnsclientpool.Configuration{
|
||||
dnsClientOptions := &dnsclientpool.Configuration{
|
||||
Retries: r.Retries,
|
||||
})
|
||||
}
|
||||
if len(r.Resolvers) > 0 {
|
||||
dnsClientOptions.Resolvers = r.Resolvers
|
||||
}
|
||||
// Create a dns client for the class
|
||||
client, err := dnsclientpool.Get(options.Options, dnsClientOptions)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get dns client")
|
||||
}
|
||||
|
|
|
@ -44,21 +44,24 @@ func Init(options *types.Options) error {
|
|||
type Configuration struct {
|
||||
// Retries contains the retries for the dns client
|
||||
Retries int
|
||||
// Resolvers contains the specific per request resolvers
|
||||
Resolvers []string
|
||||
}
|
||||
|
||||
// Hash returns the hash of the configuration to allow client pooling
|
||||
func (c *Configuration) Hash() string {
|
||||
builder := &strings.Builder{}
|
||||
builder.Grow(8)
|
||||
builder.WriteString("r")
|
||||
builder.WriteString(strconv.Itoa(c.Retries))
|
||||
builder.WriteString("l")
|
||||
builder.WriteString(strings.Join(c.Resolvers, ""))
|
||||
hash := builder.String()
|
||||
return hash
|
||||
}
|
||||
|
||||
// Get creates or gets a client for the protocol based on custom configuration
|
||||
func Get(options *types.Options, configuration *Configuration) (*retryabledns.Client, error) {
|
||||
if !(configuration.Retries > 1) {
|
||||
if !(configuration.Retries > 1) && len(configuration.Resolvers) == 0 {
|
||||
return normalClient, nil
|
||||
}
|
||||
hash := configuration.Hash()
|
||||
|
@ -72,6 +75,8 @@ func Get(options *types.Options, configuration *Configuration) (*retryabledns.Cl
|
|||
resolvers := defaultResolvers
|
||||
if options.ResolversFile != "" {
|
||||
resolvers = options.InternalResolversList
|
||||
} else if len(configuration.Resolvers) > 0 {
|
||||
resolvers = configuration.Resolvers
|
||||
}
|
||||
client := retryabledns.New(resolvers, configuration.Retries)
|
||||
|
||||
|
|
Loading…
Reference in New Issue