diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 66eff6e3..16c7b25b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,10 +13,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v2.5.2 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: latest + version: v1.31 args: --timeout 5m # Optional: working directory, useful for monorepos diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index dd004678..00000000 --- a/.golangci.yml +++ /dev/null @@ -1,111 +0,0 @@ -linters-settings: - dupl: - threshold: 100 - exhaustive: - default-signifies-exhaustive: false - # funlen: - # lines: 100 - # statements: 50 - goconst: - min-len: 2 - min-occurrences: 2 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - # gocyclo: - # min-complexity: 15 - goimports: - local-prefixes: github.com/golangci/golangci-lint - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: argument,case,condition,return - govet: - check-shadowing: true - settings: - printf: - funcs: - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - # lll: - # line-length: 140 - maligned: - suggest-new: true - misspell: - locale: US - nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped - -linters: - # please, do not use `enable-all`: it's deprecated and will be removed soon. - # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - disable-all: true - enable: - - bodyclose - - deadcode - - dogsled - - dupl - - errcheck - - exhaustive - - gochecknoinits - - goconst - - gocritic - - gofmt - - goimports - - gomnd - - goprintffuncname - - gosimple - - govet - - ineffassign - - misspell - - nakedret - - noctx - - nolintlint - - rowserrcheck - - exportloopref - - staticcheck - - structcheck - - stylecheck - - typecheck - - unconvert - - unparam - - unused - - varcheck - - whitespace - - revive - - # don't enable: - # - depguard - # - asciicheck - # - funlen - # - gochecknoglobals - # - gocognit - # - gocyclo - # - godot - # - godox - # - goerr113 - # - gosec - # - lll - # - nestif - # - prealloc - # - testpackage - # - wsl - -issues: - exclude-use-default: false - exclude: - # should have a package comment, unless it's in another file for this package (golint) - - 'in another file for this package' diff --git a/cmd/dnsx/dnsx.go b/cmd/dnsx/dnsx.go index 387e871a..5e943d2f 100644 --- a/cmd/dnsx/dnsx.go +++ b/cmd/dnsx/dnsx.go @@ -9,11 +9,12 @@ func main() { // Parse the command line flags and read config files options := runner.ParseOptions() - r, err := runner.New(options) + runner, err := runner.New(options) if err != nil { gologger.Fatal().Msgf("Could not create runner: %s\n", err) } - _ = r.Run() - r.Close() + // nolint:errcheck + runner.Run() + runner.Close() } diff --git a/go.mod b/go.mod index 81beec87..385b3e3f 100644 --- a/go.mod +++ b/go.mod @@ -4,22 +4,21 @@ go 1.14 require ( github.com/golang/protobuf v1.4.3 // indirect - github.com/golang/snappy v0.0.3 // indirect github.com/google/go-cmp v0.5.4 // indirect - github.com/json-iterator/go v1.1.11 // indirect - github.com/miekg/dns v1.1.43 + github.com/miekg/dns v1.1.42 github.com/nxadm/tail v1.4.8 // indirect github.com/onsi/ginkgo v1.15.0 // indirect github.com/onsi/gomega v1.10.5 // indirect github.com/projectdiscovery/clistats v0.0.8 github.com/projectdiscovery/gologger v1.1.4 github.com/projectdiscovery/hmap v0.0.1 + github.com/projectdiscovery/iputil v0.0.0-20210429152401-c18a5408ca46 + github.com/projectdiscovery/mapcidr v0.0.7 github.com/projectdiscovery/retryabledns v1.0.12-0.20210602155924-fbe3f476df22 github.com/rs/xid v1.3.0 - go.uber.org/atomic v1.8.0 // indirect go.uber.org/ratelimit v0.2.0 - golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect - golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect + golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect + golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b // indirect google.golang.org/protobuf v1.25.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index badd4716..4c4e2d64 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -47,11 +48,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= -github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= +github.com/miekg/dns v1.1.42 h1:gWGe42RGaIqXQZ+r3WUGEKBEtvPHY2SXo4dqixDNxuY= +github.com/miekg/dns v1.1.42/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -73,12 +75,22 @@ github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e h1:7bwaFH1jvtOo5ndhTQgoA349ozhX+1dc4b6tbaPnBOA= +github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= github.com/projectdiscovery/clistats v0.0.8 h1:tjmWb15mqsPf/yrQXVHLe2ThZX/5+mgKSfZBKWWLh20= github.com/projectdiscovery/clistats v0.0.8/go.mod h1:lV6jUHAv2bYWqrQstqW8iVIydKJhWlVaLl3Xo9ioVGg= +github.com/projectdiscovery/gologger v1.0.1/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTtMKunQ8O2VI= github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY= github.com/projectdiscovery/hmap v0.0.1 h1:VAONbJw5jP+syI5smhsfkrq9XPGn4aiYy5pR6KR1wog= github.com/projectdiscovery/hmap v0.0.1/go.mod h1:VDEfgzkKQdq7iGTKz8Ooul0NuYHQ8qiDs6r8bPD1Sb0= +github.com/projectdiscovery/ipranger v0.0.2/go.mod h1:kcAIk/lo5rW+IzUrFkeYyXnFJ+dKwYooEOHGVPP/RWE= +github.com/projectdiscovery/iputil v0.0.0-20210429152401-c18a5408ca46 h1:veDjJpC3q2PLyuYPS3jNeoYgbHvHPWQhwqRPoCe6YTA= +github.com/projectdiscovery/iputil v0.0.0-20210429152401-c18a5408ca46/go.mod h1:PQAqn5h5NXsQTF4ZA00ZTYLRzGCjOtcCq8llAqrsd1A= +github.com/projectdiscovery/mapcidr v0.0.4/go.mod h1:ALOIj6ptkWujNoX8RdQwB2mZ+kAmKuLJBq9T5gR5wG0= +github.com/projectdiscovery/mapcidr v0.0.6/go.mod h1:ZEBhMmBU3laUl3g9QGTrzJku1VJOzjdFwW01f/zVVzM= +github.com/projectdiscovery/mapcidr v0.0.7 h1:WK6WFimbWjUxfvcHEgofYNqIyqQh0vTDKzbmTh53aVg= +github.com/projectdiscovery/mapcidr v0.0.7/go.mod h1:7CzdUdjuLVI0s33dQ33lWgjg3vPuLFw2rQzZ0RxkT00= github.com/projectdiscovery/retryabledns v1.0.12-0.20210602155924-fbe3f476df22 h1:6JwMrS8ptw0xmHBqPgZX/jpLeeWvr5JSNePOx9SiF00= github.com/projectdiscovery/retryabledns v1.0.12-0.20210602155924-fbe3f476df22/go.mod h1:4sMC8HZyF01HXukRleSQYwz4870bwgb4+hTSXTMrkf4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -86,15 +98,17 @@ github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/yl2chen/cidranger v1.0.2/go.mod h1:9U1yz7WPYDwf0vpNWFaeRh0bjwz5RVgRy/9UEQfHl0g= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.8.0 h1:CUhrE4N1rqSE6FM9ecihEjRkLQu8cDfgDyoOs83mEY4= -go.uber.org/atomic v1.8.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -119,8 +133,8 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -143,8 +157,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= -golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b h1:qh4f65QIVFjq9eBURLEYWqaEXmOyqdUyiBSgaXWccWk= +golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -188,6 +202,7 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/internal/runner/options.go b/internal/runner/options.go index 7fac9a31..2d22c987 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -9,7 +9,6 @@ import ( "github.com/projectdiscovery/gologger/levels" ) -// Options of the runner type Options struct { Resolvers string Hosts string @@ -45,7 +44,7 @@ func ParseOptions() *Options { options := &Options{} flag.StringVar(&options.Resolvers, "r", "", "List of resolvers (file or command separated)") flag.StringVar(&options.Hosts, "l", "", "File input with list of subdomains") - flag.IntVar(&options.Threads, "t", defaultThreads, "Number of concurrent threads to make") + flag.IntVar(&options.Threads, "t", 100, "Number of concurrent threads to make") flag.IntVar(&options.Retries, "retry", 1, "Number of DNS retries") flag.IntVar(&options.RateLimit, "rl", -1, "Number of DNS request/second") flag.StringVar(&options.OutputFile, "o", "", "File to write output to (optional)") @@ -64,7 +63,7 @@ func ParseOptions() *Options { flag.BoolVar(&options.SOA, "soa", false, "Query SOA record") flag.BoolVar(&options.TXT, "txt", false, "Query TXT record") flag.BoolVar(&options.JSON, "json", false, "JSON output") - flag.IntVar(&options.WildcardThreshold, "wt", five, "Wildcard Filter Threshold") + flag.IntVar(&options.WildcardThreshold, "wt", 5, "Wildcard Filter Threshold") flag.StringVar(&options.WildcardDomain, "wd", "", "Wildcard Top level domain for wildcard filtering (other flags will be ignored)") flag.BoolVar(&options.ShowStatistics, "stats", false, "Enable statistic on keypress (terminal may become unresponsive till the end)") flag.BoolVar(&options.Trace, "trace", false, "Perform dns trace") diff --git a/internal/runner/runner.go b/internal/runner/runner.go index ec70b801..ea920c8d 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -13,6 +13,8 @@ import ( "github.com/projectdiscovery/dnsx/libs/dnsx" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/hmap/store/hybrid" + "github.com/projectdiscovery/iputil" + "github.com/projectdiscovery/mapcidr" retryabledns "github.com/projectdiscovery/retryabledns" "go.uber.org/ratelimit" ) @@ -32,7 +34,6 @@ type Runner struct { stats clistats.StatisticsClient } -// New creates new runner instance func New(options *Options) (*Runner, error) { dnsxOptions := dnsx.DefaultOptions dnsxOptions.MaxRetries = options.Retries @@ -128,7 +129,6 @@ func New(options *Options) (*Runner, error) { return &r, nil } -// InputWorker handle parsing and elaborating the input func (r *Runner) InputWorker() { r.hm.Scan(func(k, _ []byte) error { if r.options.ShowStatistics { @@ -150,7 +150,7 @@ func (r *Runner) prepareInput() error { if err != nil { return err } - defer f.Close() //nolint + defer f.Close() } else if (stat.Mode() & os.ModeCharDevice) == 0 { f = os.Stdin } else { @@ -160,13 +160,20 @@ func (r *Runner) prepareInput() error { numHosts := 0 sc := bufio.NewScanner(f) for sc.Scan() { - host := strings.TrimSpace(sc.Text()) - // Used just to get the exact number of targets - if _, ok := r.hm.Get(host); ok { - continue + item := strings.TrimSpace(sc.Text()) + hosts := []string{item} + if iputil.IsCIDR(item) { + hosts, _ = mapcidr.IPAddresses(item) + } + for _, host := range hosts { + // Used just to get the exact number of targets + if _, ok := r.hm.Get(host); ok { + continue + } + numHosts++ + // nolint:errcheck + r.hm.Set(host, nil) } - numHosts++ - _ = r.hm.Set(host, nil) } if r.options.ShowStatistics { @@ -174,12 +181,14 @@ func (r *Runner) prepareInput() error { r.stats.AddStatic("startedAt", time.Now()) r.stats.AddCounter("requests", 0) r.stats.AddCounter("total", uint64(numHosts*len(r.dnsx.Options.QuestionTypes))) - _ = r.stats.Start(makePrintCallback(), time.Duration(five)*time.Second) + // nolint:errcheck + r.stats.Start(makePrintCallback(), time.Duration(5)*time.Second) } return nil } +// nolint:deadcode func makePrintCallback() func(stats clistats.StatisticsClient) { builder := &strings.Builder{} return func(stats clistats.StatisticsClient) { @@ -216,7 +225,6 @@ func makePrintCallback() func(stats clistats.StatisticsClient) { } } -// Run the internal logic func (r *Runner) Run() error { err := r.prepareInput() if err != nil { @@ -246,7 +254,6 @@ func (r *Runner) Run() error { return nil } -// HandleOutput results func (r *Runner) HandleOutput() { defer r.wgoutputworker.Done() @@ -261,14 +268,15 @@ func (r *Runner) HandleOutput() { if err != nil { gologger.Fatal().Msgf("%s\n", err) } - defer foutput.Close() //nolint + defer foutput.Close() w = bufio.NewWriter(foutput) - defer w.Flush() //nolint + defer w.Flush() } for item := range r.outputchan { if r.options.OutputFile != "" { // uses a buffer to write to file - _, _ = w.WriteString(item + "\n") + // nolint:errcheck + w.WriteString(item + "\n") } // otherwise writes sequentially to stdout gologger.Silent().Msgf("%s\n", item) @@ -333,7 +341,8 @@ func (r *Runner) worker() { // if wildcard filtering just store the data if r.options.WildcardDomain != "" { - _ = r.storeDNSData(dnsData) + // nolint:errcheck + r.storeDNSData(dnsData) continue } if r.options.JSON { @@ -374,7 +383,7 @@ func (r *Runner) worker() { func (r *Runner) outputRecordType(domain string, items []string) { for _, item := range items { - item = strings.ToLower(item) + item := strings.ToLower(item) if r.options.ResponseOnly { r.outputchan <- item } else if r.options.Response { @@ -397,7 +406,7 @@ func (r *Runner) storeDNSData(dnsdata *retryabledns.DNSData) error { // Close running instance func (r *Runner) Close() { - _ = r.hm.Close() + r.hm.Close() } // TODO - wip - just ignore @@ -475,4 +484,5 @@ func (r *Runner) wildcardWorker() { } } } + } diff --git a/internal/runner/util.go b/internal/runner/util.go index d3f04a32..7264d6ce 100644 --- a/internal/runner/util.go +++ b/internal/runner/util.go @@ -9,11 +9,6 @@ import ( "time" ) -const ( - five = 5 - defaultThreads = 100 -) - func fileExists(fileName string) bool { info, err := os.Stat(fileName) if os.IsNotExist(err) { @@ -28,7 +23,7 @@ func linesInFile(fileName string) ([]string, error) { if err != nil { return result, err } - defer f.Close() //nolint + defer f.Close() scanner := bufio.NewScanner(f) for scanner.Scan() { line := scanner.Text() @@ -52,8 +47,8 @@ func isURL(toTest string) bool { return true } -func extractDomain(target string) string { - u, err := url.Parse(target) +func extractDomain(URL string) string { + u, err := url.Parse(URL) if err != nil { return "" } diff --git a/internal/runner/wildcard.go b/internal/runner/wildcard.go index 1791f4f4..ff1d5ec5 100644 --- a/internal/runner/wildcard.go +++ b/internal/runner/wildcard.go @@ -7,9 +7,9 @@ import ( ) // IsWildcard checks if a host is wildcard -func (r *Runner) IsWildcard(host string) (iswildcard bool, wildcards map[string]struct{}) { +func (r *Runner) IsWildcard(host string) (bool, map[string]struct{}) { orig := make(map[string]struct{}) - wildcards = make(map[string]struct{}) + wildcards := make(map[string]struct{}) subdomainPart := strings.TrimSuffix(host, "."+r.options.WildcardDomain) subdomainTokens := strings.Split(subdomainPart, ".") @@ -19,7 +19,8 @@ func (r *Runner) IsWildcard(host string) (iswildcard bool, wildcards map[string] // We use a rand prefix at the beginning like %rand%.domain.tld // A permutation is generated for each level of the subdomain. var hosts []string - hosts = append(hosts, host, xid.New().String()+"."+r.options.WildcardDomain) + hosts = append(hosts, host) + hosts = append(hosts, xid.New().String()+"."+r.options.WildcardDomain) for i := 0; i < len(subdomainTokens); i++ { newhost := xid.New().String() + "." + strings.Join(subdomainTokens[i:], ".") + "." + r.options.WildcardDomain @@ -49,10 +50,9 @@ func (r *Runner) IsWildcard(host string) (iswildcard bool, wildcards map[string] // check if original ip are among wildcards for a := range orig { if _, ok := wildcards[a]; ok { - iswildcard = true - break + return true, wildcards } } - return //nolint + return false, wildcards }