Skip to content

Commit

Permalink
Fix wildcard filtering with long domains
Browse files Browse the repository at this point in the history
  • Loading branch information
d3mondev committed May 12, 2023
1 parent e1478a4 commit 9d94e50
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Wildcard filtering not working when wildcard tests put the domain over the 253 character limit.

## [2.1.1] - 2023-04-11
### Fixed
- Wrong version number in binary releases
Expand Down
2 changes: 1 addition & 1 deletion internal/app/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
AppDesc string = "Very accurate massdns resolving and bruteforcing."

// AppVersion is the program version.
AppVersion string = "v2.1.1"
AppVersion string = "v2.1.2"

// AppSponsorsURL is the text file containing sponsors information.
AppSponsorsURL string = "https://gist.githubusercontent.com/d3mondev/0bfff529a4dad627bdb684ad1ef2506d/raw/sponsors.txt"
Expand Down
4 changes: 3 additions & 1 deletion pkg/wildcarder/randomsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"time"
)

const randomSubdomainLength = 16

func newRandomSubdomains(count int) []string {
const letters = "abcdefghijklmnopqrstuvwxyz1234567890"

Expand All @@ -13,7 +15,7 @@ func newRandomSubdomains(count int) []string {
var subs []string

for i := 0; i < count; i++ {
b := make([]byte, 16)
b := make([]byte, randomSubdomainLength)

for i := range b {
b[i] = letters[rng.Intn(len(letters))]
Expand Down
5 changes: 5 additions & 0 deletions pkg/wildcarder/wildcarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (wc *Wildcarder) Filter(r io.Reader) (domains, roots []string) {
continue
}

// If the domain is too long to test for wildcards, it won't appear in the results
if len(domain)+randomSubdomainLength > 253 {
continue
}

ctx := detectionTaskContext{
results: results,

Expand Down
17 changes: 17 additions & 0 deletions pkg/wildcarder/wildcarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ func TestFilterSimpleWildcard(t *testing.T) {
assert.ElementsMatch(t, []string{"test.com"}, roots)
}

func TestFilterDomainTooLong(t *testing.T) {
domainTooLong := strings.Repeat("a", 229) + ".test.com"

resolver := newFakeResolver()
resolver.addAnswer("test.com", []DNSAnswer{{Type: resolvermt.TypeA, Answer: "192.168.0.5"}})
resolver.addAnswer(domainTooLong, []DNSAnswer{{Type: resolvermt.TypeA, Answer: "192.168.0.5"}})
resolver.addAnswer("random.test.com", []DNSAnswer{{Type: resolvermt.TypeA, Answer: "192.168.0.5"}})

wc := New(1, 1, WithResolver(resolver))
overrideWildcardTest(wc)

domains, roots := wc.Filter(strings.NewReader(domainTooLong))

assert.Empty(t, domains)
assert.Empty(t, roots)
}

func TestFilterSimpleWildcardCNAME(t *testing.T) {
resolver := newFakeResolver()
resolver.addAnswer("test.com", []DNSAnswer{{Type: resolvermt.TypeCNAME, Answer: "example.com"}})
Expand Down

0 comments on commit 9d94e50

Please sign in to comment.