Adding support for custom resolvers

This commit is contained in:
mzack 2021-12-28 07:46:42 +01:00
parent 430a180e42
commit 96a511ad48
4 changed files with 28 additions and 0 deletions

View File

@ -44,6 +44,9 @@ func New(options *Options) (*HTTPX, error) {
fastdialerOpts.Deny = options.Deny
fastdialerOpts.Allow = options.Allow
fastdialerOpts.WithDialerHistory = true
if len(options.Resolvers) > 0 {
fastdialerOpts.BaseResolvers = options.Resolvers
}
dialer, err := fastdialer.NewDialer(fastdialerOpts)
if err != nil {
return nil, fmt.Errorf("could not create resolver cache: %s", err)

View File

@ -36,6 +36,7 @@ type Options struct {
MaxResponseBodySizeToSave int64
MaxResponseBodySizeToRead int64
UnsafeURI string
Resolvers []string
}
// DefaultOptions contains the default options

View File

@ -4,6 +4,7 @@ import (
"math"
"os"
"regexp"
"strings"
"github.com/projectdiscovery/fileutil"
"github.com/projectdiscovery/goconfig"
@ -197,6 +198,7 @@ type Options struct {
Stream bool
SkipDedupe bool
ProbeAllIPS bool
Resolvers goflags.NormalizedStringSlice
}
// ParseOptions parses the command line options for application
@ -288,6 +290,7 @@ func ParseOptions() *Options {
flagSet.BoolVarP(&options.Stream, "stream", "s", false, "Stream mode - start elaborating input targets without sorting"),
flagSet.BoolVarP(&options.SkipDedupe, "skip-dedupe", "sd", false, "Disable dedupe input items (only used with stream mode)"),
flagSet.BoolVarP(&options.ProbeAllIPS, "probe-all-ips", "pa", false, "Probe all the ips associated with same host"),
flagSet.NormalizedStringSliceVarP(&options.Resolvers, "resolvers", "r", []string{}, "List of resolvers (file or comma separated) - each resolver can be in the form protocol:ip|hostname:port - invalid files/resolvers ignored"),
)
createGroup(flagSet, "debug", "Debug",
@ -370,6 +373,26 @@ func (options *Options) validateOptions() {
gologger.Fatal().Msgf("Invalid value for match regex option: %s\n", err)
}
}
var resolvers []string
for _, resolver := range options.Resolvers {
if fileutil.FileExists(resolver) {
chFile, err := fileutil.ReadFile(resolver)
if err != nil {
gologger.Fatal().Msgf("Couldn't process resolver file \"%s\": %s\n", resolver, err)
}
for line := range chFile {
resolvers = append(resolvers, line)
}
} else {
resolvers = append(resolvers, resolver)
}
}
options.Resolvers = resolvers
if len(options.Resolvers) > 0 {
gologger.Debug().Msgf("Using resolvers: %s\n", strings.Join(options.Resolvers, ","))
}
}
// configureOutput configures the output on the screen

View File

@ -108,6 +108,7 @@ func New(options *Options) (*Runner, error) {
if httpxOptions.MaxResponseBodySizeToSave > httpxOptions.MaxResponseBodySizeToRead {
httpxOptions.MaxResponseBodySizeToSave = httpxOptions.MaxResponseBodySizeToRead
}
httpxOptions.Resolvers = options.Resolvers
var key, value string
httpxOptions.CustomHeaders = make(map[string]string)