Skip to content

Commit 72ce90e

Browse files
authored
Merge pull request #467 from projectdiscovery/issue-449-custom-resolvers
Adding support for custom resolvers
2 parents 430a180 + 481716e commit 72ce90e

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ OUTPUT:
138138
-csv Output in CSV format
139139

140140
CONFIGURATIONS:
141+
-r, -resolvers string[] List of custom resolvers (file or comma separated)
141142
-allow string[] Allowed list of IP/CIDR's to process (file or comma separated)
142143
-deny string[] Denied list of IP/CIDR's to process (file or comma separated)
143144
-random-agent Enable Random User-Agent to use (default true)
@@ -323,7 +324,8 @@ https://support.hackerone.com
323324
- `vhost`, `http2`, `pipeline`, `ports`, `csp-probe`, `tls-probe` and `path` are unique flag with different probes.
324325
- Unique flags should be used for specific use cases instead of running them as default with other flags.
325326
- When using `json` flag, all the information (default probes) included in the JSON output.
326-
327+
- Custom resolver supports multiple protocol (**doh|tcp|udp**) in form of `protocol:resolver:port` (eg **udp:127.0.0.1:53**)
328+
- Invalid custom resolvers/files are ignored.
327329

328330
# Acknowledgement
329331

common/httpx/httpx.go

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func New(options *Options) (*HTTPX, error) {
4444
fastdialerOpts.Deny = options.Deny
4545
fastdialerOpts.Allow = options.Allow
4646
fastdialerOpts.WithDialerHistory = true
47+
if len(options.Resolvers) > 0 {
48+
fastdialerOpts.BaseResolvers = options.Resolvers
49+
}
4750
dialer, err := fastdialer.NewDialer(fastdialerOpts)
4851
if err != nil {
4952
return nil, fmt.Errorf("could not create resolver cache: %s", err)

common/httpx/option.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Options struct {
3636
MaxResponseBodySizeToSave int64
3737
MaxResponseBodySizeToRead int64
3838
UnsafeURI string
39+
Resolvers []string
3940
}
4041

4142
// DefaultOptions contains the default options

runner/options.go

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math"
55
"os"
66
"regexp"
7+
"strings"
78

89
"github.com/projectdiscovery/fileutil"
910
"github.com/projectdiscovery/goconfig"
@@ -197,6 +198,7 @@ type Options struct {
197198
Stream bool
198199
SkipDedupe bool
199200
ProbeAllIPS bool
201+
Resolvers goflags.NormalizedStringSlice
200202
}
201203

202204
// ParseOptions parses the command line options for application
@@ -272,6 +274,7 @@ func ParseOptions() *Options {
272274
)
273275

274276
createGroup(flagSet, "configs", "Configurations",
277+
flagSet.NormalizedStringSliceVarP(&options.Resolvers, "resolvers", "r", []string{}, "List of custom resolvers (file or comma separated)"),
275278
flagSet.Var(&options.Allow, "allow", "Allowed list of IP/CIDR's to process (file or comma separated)"),
276279
flagSet.Var(&options.Deny, "deny", "Denied list of IP/CIDR's to process (file or comma separated)"),
277280
flagSet.BoolVar(&options.RandomAgent, "random-agent", true, "Enable Random User-Agent to use"),
@@ -370,6 +373,26 @@ func (options *Options) validateOptions() {
370373
gologger.Fatal().Msgf("Invalid value for match regex option: %s\n", err)
371374
}
372375
}
376+
377+
var resolvers []string
378+
for _, resolver := range options.Resolvers {
379+
if fileutil.FileExists(resolver) {
380+
chFile, err := fileutil.ReadFile(resolver)
381+
if err != nil {
382+
gologger.Fatal().Msgf("Couldn't process resolver file \"%s\": %s\n", resolver, err)
383+
}
384+
for line := range chFile {
385+
resolvers = append(resolvers, line)
386+
}
387+
} else {
388+
resolvers = append(resolvers, resolver)
389+
}
390+
}
391+
options.Resolvers = resolvers
392+
if len(options.Resolvers) > 0 {
393+
gologger.Debug().Msgf("Using resolvers: %s\n", strings.Join(options.Resolvers, ","))
394+
395+
}
373396
}
374397

375398
// configureOutput configures the output on the screen

runner/runner.go

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func New(options *Options) (*Runner, error) {
108108
if httpxOptions.MaxResponseBodySizeToSave > httpxOptions.MaxResponseBodySizeToRead {
109109
httpxOptions.MaxResponseBodySizeToSave = httpxOptions.MaxResponseBodySizeToRead
110110
}
111+
httpxOptions.Resolvers = options.Resolvers
111112

112113
var key, value string
113114
httpxOptions.CustomHeaders = make(map[string]string)

0 commit comments

Comments
 (0)