-
Notifications
You must be signed in to change notification settings - Fork 310
Support auto wildcard detection similar to PureDNS #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Import necessary packages | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "strings" | ||
| "github.com/projectdiscovery/dnsx" // Assuming this package handles DNS queries | ||
| ) | ||
|
|
||
| // Function to check for wildcard DNS | ||
| func checkWildcard(domain string) bool { | ||
| // Common subdomains to check for wildcard | ||
| subdomains := []string{"www", "ftp", "mail", "api", "test"} | ||
|
|
||
| for _, subdomain := range subdomains { | ||
| query := subdomain + "." + domain | ||
| result := dnsx.Query(query) // Assuming dnsx.Query performs DNS queries | ||
| if strings.Contains(result, "NXDOMAIN") { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
Comment on lines
+12
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify the dnsx package API to confirm available methods
echo "=== Checking dnsx package exports ==="
ast-grep --pattern 'func ($CLIENT *DNSX) Query$_($$$) ($$$) {
$$$
}'
echo ""
echo "=== Checking existing wildcard implementation ==="
cat internal/runner/wildcard.goRepository: projectdiscovery/dnsx Length of output: 1873 🏁 Script executed: #!/bin/bash
# Search for dnsx methods and functions more broadly
echo "=== Searching for dnsx.Query usage in codebase ==="
rg "dnsx\.Query" --type go -A 2 -B 2
echo ""
echo "=== Searching for dnsx method definitions ==="
rg "func \(.*\*DNSX\) Query" --type go -A 5
echo ""
echo "=== Finding dnsx package location and structure ==="
fd -e go -path "*dnsx*" | head -20
echo ""
echo "=== Check if dnsx.Query function exists (package-level) ==="
rg "^func Query\(" --type go -B 2 -A 5Repository: projectdiscovery/dnsx Length of output: 2456 🏁 Script executed: #!/bin/bash
# Verify the exact content of the problematic function in cmd/dnsx/main.go
echo "=== Content of cmd/dnsx/main.go around the checkWildcard function ==="
head -30 cmd/dnsx/main.goRepository: projectdiscovery/dnsx Length of output: 927
Three critical issues prevent compilation and function:
Reuse the existing Corrected approach (requires further adaptation)-func checkWildcard(domain string) bool {
- subdomains := []string{"www", "ftp", "mail", "api", "test"}
-
- for _, subdomain := range subdomains {
- query := subdomain + "." + domain
- result := dnsx.Query(query)
- if strings.Contains(result, "NXDOMAIN") {
- return false
- }
- }
- return true
-}
+func checkWildcard(dnsxClient *dnsx.DNSX, domain string) bool {
+ randomSub := xid.New().String() + "." + domain
+ result, err := dnsxClient.QueryOne(randomSub)
+ if err != nil || result == nil {
+ return false
+ }
+ return len(result.A) > 0
+}🤖 Prompt for AI Agents |
||
|
|
||
| func main() { | ||
| autoWildcard := flag.Bool("auto-wildcard", false, "Enable automatic wildcard detection") | ||
| flag.Parse() | ||
|
|
||
| domains := flag.Args() | ||
| for _, domain := range domains { | ||
| if *autoWildcard && checkWildcard(domain) { | ||
| fmt.Printf("[INFO] Wildcard detected for domain: %s\n", domain) | ||
| continue // Skip the wildcard domain | ||
| } | ||
| fmt.Printf("Checking domain: %s\n", domain) | ||
| } | ||
| } | ||
|
Comment on lines
+26
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check how other commands in this repo initialize the dnsx client
ast-grep --pattern 'dnsx.New($$$)'Repository: projectdiscovery/dnsx Length of output: 47 🏁 Script executed: cat -n cmd/dnsx/main.go | head -60Repository: projectdiscovery/dnsx Length of output: 1407 🏁 Script executed: fd -t f -name "*.go" cmd/ | head -20Repository: projectdiscovery/dnsx Length of output: 295 🏁 Script executed: rg "dnsx\." --type go -A 3 -B 1 | head -100Repository: projectdiscovery/dnsx Length of output: 5154 🏁 Script executed: rg "func.*Query" libs/dnsx/ --type go -B 2 -A 5Repository: projectdiscovery/dnsx Length of output: 931 🏁 Script executed: cat -n cmd/dnsx/main.goRepository: projectdiscovery/dnsx Length of output: 1407 🏁 Script executed: rg "^func Query" libs/dnsx/ --type goRepository: projectdiscovery/dnsx Length of output: 47 🏁 Script executed: rg "dnsx\.Query\(" . --type goRepository: projectdiscovery/dnsx Length of output: 164 DNSX client must be initialized and proper query methods used. The code calls the non-existent
Additionally, add error handling for empty domain arguments (when The 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||
| package main | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||
| "github.com/projectdiscovery/dnsx" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Test file cannot access In Go, packages are determined by directory, not by Additionally:
To fix, either:
Option 1: Move test to cmd/dnsx/-// File: test/wildcard_test.go
+// File: cmd/dnsx/wildcard_test.go
package main
import (
"testing"
- "github.com/projectdiscovery/dnsx"
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Test function to check the wildcard detection | ||||||||||||||||||||||||
| func TestCheckWildcard(t *testing.T) { | ||||||||||||||||||||||||
| tests := []struct { | ||||||||||||||||||||||||
| domain string | ||||||||||||||||||||||||
| expected bool | ||||||||||||||||||||||||
| }{ | ||||||||||||||||||||||||
| {"example.com", true}, | ||||||||||||||||||||||||
| {"nonwildcard.com", false}, | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for _, tt := range tests { | ||||||||||||||||||||||||
| t.Run(tt.domain, func(t *testing.T) { | ||||||||||||||||||||||||
| got := checkWildcard(tt.domain) | ||||||||||||||||||||||||
| if got != tt.expected { | ||||||||||||||||||||||||
| t.Errorf("checkWildcard() = %v, want %v", got, tt.expected) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+9
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test design issues: non-deterministic and lacks mocking.
Consider refactoring Suggested approach with interface for testability// Define interface for DNS querying
type DNSQuerier interface {
QueryOne(hostname string) (*retryabledns.DNSData, error)
}
// Refactor checkWildcard to accept interface
func checkWildcard(client DNSQuerier, domain string) bool {
// implementation
}
// In tests, use a mock implementation
type mockDNSClient struct {
responses map[string]*retryabledns.DNSData
}
func (m *mockDNSClient) QueryOne(hostname string) (*retryabledns.DNSData, error) {
if resp, ok := m.responses[hostname]; ok {
return resp, nil
}
return nil, errors.New("NXDOMAIN")
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect import path for dnsx package.
The import
"github.com/projectdiscovery/dnsx"does not match the internal library structure. Based on the codebase, the dnsx library is located atlibs/dnsxand should be imported as"github.com/projectdiscovery/dnsx/libs/dnsx".Suggested fix
import ( "flag" "fmt" "strings" - "github.com/projectdiscovery/dnsx" // Assuming this package handles DNS queries + "github.com/projectdiscovery/dnsx/libs/dnsx" )🤖 Prompt for AI Agents