Skip to content

Commit 99658d0

Browse files
committed
Add .golangci.yml for linting configuration and update tests to use context in domain resolution
- Introduced a new .golangci.yml file to configure linting with various linters for code quality checks. - Updated main.go and main_test.go to pass context as a parameter in domain resolution functions, enhancing error handling and timeout management. - Added new tests for context cancellation and output file writing functionality, ensuring robust testing coverage.
1 parent 5219400 commit 99658d0

File tree

11 files changed

+412
-40
lines changed

11 files changed

+412
-40
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
labels:
8+
- "dependencies"
9+
- "go"
10+
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"
15+
labels:
16+
- "dependencies"
17+
- "github-actions"

.github/workflows/codeql.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
# Run every Monday at 06:00 UTC
10+
- cron: '0 6 * * 1'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze (Go)
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '1.22'
29+
30+
- name: Initialize CodeQL
31+
uses: github/codeql-action/init@v3
32+
with:
33+
languages: go
34+
queries: security-extended
35+
36+
- name: Build
37+
run: go build -buildvcs=false ./...
38+
39+
- name: Perform CodeQL Analysis
40+
uses: github/codeql-action/analyze@v3
41+
with:
42+
category: "/language:go"

.github/workflows/go.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9-
permissions:
10-
contents: write
11-
129
jobs:
1310
build:
1411
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
1515
steps:
1616
- uses: actions/checkout@v4
1717

@@ -20,6 +20,16 @@ jobs:
2020
with:
2121
go-version: '1.22'
2222

23+
- name: Cache Go build artifacts
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.cache/go-build
28+
~/go/pkg/mod
29+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
30+
restore-keys: |
31+
${{ runner.os }}-go-
32+
2333
- name: Verify dependencies
2434
run: go mod verify
2535

@@ -37,6 +47,9 @@ jobs:
3747
release:
3848
needs: build
3949
if: startsWith(github.ref, 'refs/tags/v')
50+
permissions:
51+
contents: write
52+
4053
strategy:
4154
matrix:
4255
include:
@@ -71,6 +84,16 @@ jobs:
7184
with:
7285
go-version: '1.22'
7386

87+
- name: Cache Go build artifacts
88+
uses: actions/cache@v4
89+
with:
90+
path: |
91+
~/.cache/go-build
92+
~/go/pkg/mod
93+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
94+
restore-keys: |
95+
${{ runner.os }}-go-
96+
7497
- name: Build
7598
env:
7699
GOOS: ${{ matrix.goos }}

.golangci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
run:
2+
timeout: 5m
3+
go: "1.22"
4+
5+
linters:
6+
enable:
7+
- errcheck
8+
- govet
9+
- staticcheck
10+
- gofmt
11+
- unused
12+
- gosec
13+
- gocritic
14+
- misspell
15+
- unconvert
16+
17+
linters-settings:
18+
gosec:
19+
excludes:
20+
# G304: File path provided as taint input — expected for a wordlist tool
21+
- G304
22+
errcheck:
23+
# These write to stdout/files in hot paths; errors are intentionally ignored
24+
exclude-functions:
25+
- fmt.Printf
26+
- fmt.Fprintln
27+
- fmt.Fprintf
28+
- fmt.Println
29+
30+
issues:
31+
exclude-rules:
32+
# Test files are allowed to use gosec-flagged patterns
33+
- path: _test\.go
34+
linters:
35+
- gosec

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ go build
9898
- `-progress`: Show scan progress (default: true, use `-progress=false` to disable).
9999
- `-o <file>`: Write discovered subdomains to file (in addition to stdout).
100100
- `-retries <number>`: Number of DNS retry attempts per subdomain (default: 1).
101+
- `-simulate`: Run in simulation mode — no actual DNS queries are made.
102+
- `-hit-rate <number>`: In simulation mode, percentage of subdomains that "resolve" (default: 15, range: 1-100).
101103
- `-version`: Show version information and exit.
102104

103105
### Output:
@@ -110,11 +112,12 @@ Found: mail.example.com
110112

111113
With verbose mode (`-v`), you'll see additional information:
112114
```
113-
Starting subenum v0.2.0
115+
Starting subenum v0.3.0
114116
Target domain: example.com
115117
Wordlist: wordlist.txt
116118
Concurrency: 100 workers
117119
Timeout: 1000 ms
120+
Retries: 1
118121
DNS Server: 8.8.8.8:53
119122
---
120123
Total wordlist entries: 50

docs/CONTRIBUTING.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,46 @@ Please ensure that any contributions adhere to the ethical usage principles of t
9595
- Consider potential misuse and implement appropriate safeguards
9696
- Document proper usage scenarios and any necessary warnings
9797

98-
## *(Details on reporting bugs, suggesting features, pull requests.)*
98+
## Reporting Bugs
99+
100+
1. Search [existing issues](https://github.com/TMHSDigital/subenum/issues) first to avoid duplicates.
101+
2. Open a new issue using the **Bug Report** template.
102+
3. Include:
103+
- The exact command you ran
104+
- Your OS, Go version, and `subenum` version (`./subenum -version`)
105+
- Full terminal output (redact any sensitive domain names)
106+
- Expected vs. actual behaviour
107+
108+
Do NOT include sensitive information, unauthorized scan results, or private domain details.
109+
110+
## Suggesting Features
111+
112+
1. Search [existing issues](https://github.com/TMHSDigital/subenum/issues) to avoid duplicates.
113+
2. Open a new issue using the **Feature Request** template.
114+
3. Describe:
115+
- The problem the feature solves
116+
- Your proposed solution
117+
- Legitimate security testing use cases it enables
118+
119+
Features that could primarily enable malicious use will be declined.
120+
121+
## Simulation Mode for Development
122+
123+
Use `-simulate` to develop and test without making real DNS queries:
124+
125+
```bash
126+
./subenum -simulate -hit-rate 30 -w examples/sample_wordlist.txt example.com
127+
```
128+
129+
This lets you iterate on output formatting, flag handling, and new features safely.
130+
131+
## Testing Requirements
132+
133+
All pull requests must pass the full test suite, including the race detector:
134+
135+
```bash
136+
go test -v -race ./...
137+
```
138+
139+
New features should include tests. New flags must be covered by at least one test case.
140+
Add network-dependent tests under `if testing.Short() { t.Skip(...) }` so they can be skipped in offline environments.

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ show_downloads: true
55
google_analytics:
66
github:
77
is_project_page: true
8-
repository_url: https://github.com/yourusername/subenum
8+
repository_url: https://github.com/TMHSDigital/subenum

docs/docker.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This guide explains how to use `subenum` with Docker for a containerized subdoma
1818

1919
```bash
2020
# Clone the repository (if you haven't already)
21-
git clone https://github.com/yourusername/subenum.git
21+
git clone https://github.com/TMHSDigital/subenum.git
2222
cd subenum
2323

2424
# Build the Docker image
@@ -73,6 +73,47 @@ docker run --rm -v /path/to/your/files:/data subenum -w /data/your-wordlist.txt
7373
- `/root/examples/`: Contains example files and wordlists from the repository
7474
- `/data/`: Mount point for your custom files
7575

76+
### Saving Results to a File
77+
78+
Use `-o` to write discovered subdomains to a file on the host via the `/data` volume:
79+
80+
```bash
81+
docker run --rm -v $(pwd)/data:/data subenum \
82+
-w /data/wordlist.txt \
83+
-o /data/results.txt \
84+
example.com
85+
```
86+
87+
### Using Retries for Unreliable Networks
88+
89+
The `-retries` flag re-attempts failed DNS lookups before marking a subdomain as unresolved:
90+
91+
```bash
92+
docker run --rm -v $(pwd)/data:/data subenum \
93+
-w /data/wordlist.txt \
94+
-retries 3 \
95+
-timeout 2000 \
96+
example.com
97+
```
98+
99+
### Safe Simulation Mode
100+
101+
Test the tool without making any real DNS queries:
102+
103+
```bash
104+
docker run --rm subenum \
105+
-simulate \
106+
-hit-rate 20 \
107+
-w /root/examples/sample_wordlist.txt \
108+
example.com
109+
```
110+
111+
Or via Make:
112+
113+
```bash
114+
make docker-simulate
115+
```
116+
76117
## Troubleshooting
77118

78119
### DNS Resolution Issues

examples/advanced_usage.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,65 @@ cd examples
101101
./multi_domain_scan.sh sample_domains.txt
102102
```
103103

104+
## Saving Results to a File
105+
106+
Use `-o` to write discovered subdomains to a file while still printing them to stdout:
107+
108+
```bash
109+
./subenum -w wordlist.txt -o results.txt example.com
110+
```
111+
112+
Combine with other flags for a full scan that saves output:
113+
114+
```bash
115+
./subenum -w wordlist.txt -v -t 150 -o scan_results.txt example.com
116+
```
117+
118+
## Retries for Unreliable Networks
119+
120+
Use `-retries` to re-attempt failed DNS lookups before giving up. Useful on flaky connections or rate-limited resolvers:
121+
122+
```bash
123+
./subenum -w wordlist.txt -retries 3 example.com
124+
```
125+
126+
Combine with a longer timeout for maximum resilience:
127+
128+
```bash
129+
./subenum -w wordlist.txt -retries 3 -timeout 2000 -dns-server 1.1.1.1:53 example.com
130+
```
131+
132+
## Simulation Mode
133+
134+
Use `-simulate` to run without making any real DNS queries. Ideal for demonstrations, CI testing, or exploring the tool's output format:
135+
136+
```bash
137+
./subenum -simulate -w examples/sample_wordlist.txt example.com
138+
```
139+
140+
Adjust the simulated hit rate (percentage of subdomains that appear to resolve):
141+
142+
```bash
143+
./subenum -simulate -hit-rate 30 -w examples/sample_wordlist.txt example.com
144+
```
145+
146+
Simulation mode with verbose output shows fake IPs and timings:
147+
148+
```bash
149+
./subenum -simulate -hit-rate 25 -v -w examples/sample_wordlist.txt example.com
150+
```
151+
104152
## Continuous Integration / Automated Testing
105153

106154
For CI/CD environments, you can use the version flag to ensure the correct version is installed:
107155

108156
```bash
109157
./subenum -version
110-
# Output: subenum v0.2.0
158+
# Output: subenum v0.3.0
159+
```
160+
161+
Use simulation mode in CI pipelines to test the tool's behaviour without network access:
162+
163+
```bash
164+
./subenum -simulate -hit-rate 20 -w examples/sample_wordlist.txt -o /tmp/results.txt example.com
111165
```

0 commit comments

Comments
 (0)