Repository navigation
feat: add shodanct passive source - #1796
Conversation
WalkthroughA new Shodan CT passive scraping source is added that queries ChangesShodanct Passive Source
File Utility Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/subscraping/sources/shodanct/shodanct.go (1)
36-36: 💤 Low valueConsider URL-escaping the domain parameter.
The domain is interpolated directly into the URL without escaping. While domain names typically contain only safe characters, using
url.PathEscapeor constructing the URL withurl.URLwould be more robust.🔒 Proposed fix using url.PathEscape
+ "net/url" + searchURL := fmt.Sprintf("https://ctl.shodan.io/api/v1/domain/%s/hostnames", domain) + searchURL := fmt.Sprintf("https://ctl.shodan.io/api/v1/domain/%s/hostnames", url.PathEscape(domain))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/subscraping/sources/shodanct/shodanct.go` at line 36, The domain parameter in the searchURL construction is interpolated directly into the URL without escaping, which could cause issues if the domain contains special characters. Modify the searchURL assignment to use url.PathEscape on the domain parameter before embedding it in the fmt.Sprintf call. This ensures the domain is properly URL-encoded for safe inclusion in the URL path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/subscraping/sources/shodanct/shodanct.go`:
- Around line 16-21: The Source struct in shodanct.go has unprotected concurrent
access to its fields (timeTaken, errors, results, requests), causing data races
when the same global singleton Source instance is used across multiple
concurrent domain enumerations. Add a sync.RWMutex field to the Source struct
and protect all accesses to these fields: wrap the synchronous field resets in
Run() (around lines 26-28) with Lock/Unlock, wrap all field modifications in the
spawned goroutine within Run() (at lines 37, 41, 51, 61, 71) with Lock/Unlock,
and wrap all field reads in the Statistics() method (lines 105-112) with
RLock/RUnlock to ensure thread-safe access.
---
Nitpick comments:
In `@pkg/subscraping/sources/shodanct/shodanct.go`:
- Line 36: The domain parameter in the searchURL construction is interpolated
directly into the URL without escaping, which could cause issues if the domain
contains special characters. Modify the searchURL assignment to use
url.PathEscape on the domain parameter before embedding it in the fmt.Sprintf
call. This ensures the domain is properly URL-encoded for safe inclusion in the
URL path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e548b881-3208-4b11-976f-1cfebfeefc8c
📒 Files selected for processing (3)
pkg/passive/sources.gopkg/passive/sources_test.gopkg/subscraping/sources/shodanct/shodanct.go
| type Source struct { | ||
| timeTaken time.Duration | ||
| errors int | ||
| results int | ||
| requests int | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check how Agent uses sources and whether Run can be called concurrently
# Find Agent's EnumerateSubdomains or similar methods that invoke Run
ast-grep --pattern 'func ($_ *Agent) $METHOD($$$) $_ {
$$$
$_.Run($$$)
$$$
}'
# Check for goroutines launching source.Run
rg -nP -A 3 -B 3 'go func.*Run\(' --type=goRepository: projectdiscovery/subfinder
Length of output: 52
🏁 Script executed:
# First, let's examine the Source struct definition and Run() method
cat -n pkg/subscraping/sources/shodanct/shodanct.goRepository: projectdiscovery/subfinder
Length of output: 3406
🏁 Script executed:
# Check the sources.go file around line 108 to understand AllSources
fd -i "sources.go" -type f --exec head -n 150 {} \;Repository: projectdiscovery/subfinder
Length of output: 241
🏁 Script executed:
# Search for Run() method calls with context to understand concurrency patterns
rg -n "\.Run\(" --type=go -B 2 -A 2 | head -100Repository: projectdiscovery/subfinder
Length of output: 6110
🏁 Script executed:
# Find AllSources definition and usage
rg -n "AllSources" --type go -B 3 -A 3Repository: projectdiscovery/subfinder
Length of output: 8663
🏁 Script executed:
# Check how sources are initialized and used in passive.go
cat -n pkg/passive/passive.go | head -100Repository: projectdiscovery/subfinder
Length of output: 3894
🏁 Script executed:
# Look for the enumerate method that calls Run
rg -n "func.*Enumerate" pkg/passive/ --type go -A 20Repository: projectdiscovery/subfinder
Length of output: 2365
🏁 Script executed:
# Check if same Agent is reused across multiple domain enumerations
rg -n "EnumerateSubdomains\|New(" pkg/runner/ -B 2 -A 2 | head -50Repository: projectdiscovery/subfinder
Length of output: 171
🏁 Script executed:
# Check if same Agent is reused across multiple domain enumerations
rg -n "EnumerateSubdomains" pkg/runner/ -B 2 -A 2 | head -60Repository: projectdiscovery/subfinder
Length of output: 522
Unprotected concurrent access to Source struct fields causes data race.
The Source struct fields (timeTaken, errors, results, requests) are accessed without synchronization. Since AllSources contains global singleton instances that are reused across multiple domain enumerations, concurrent calls to Run() on the same Source instance will race on these fields.
In shodanct.go, Run() synchronously resets fields (lines 26–28), then spawns a goroutine that modifies them (lines 32, 37, 41, 51, 61, 71). The Statistics() method reads these fields without locks (lines 105–111). When the same Agent instance enumerates multiple domains, Run() can be called concurrently on the same source before the previous goroutine completes, causing data races.
Add a sync.RWMutex to protect these fields, or restructure to avoid reusing shared state across concurrent calls.
Also applies to: 26-28, 37-37, 41-41, 51-51, 61-61, 71-71, 105-112
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/subscraping/sources/shodanct/shodanct.go` around lines 16 - 21, The
Source struct in shodanct.go has unprotected concurrent access to its fields
(timeTaken, errors, results, requests), causing data races when the same global
singleton Source instance is used across multiple concurrent domain
enumerations. Add a sync.RWMutex field to the Source struct and protect all
accesses to these fields: wrap the synchronous field resets in Run() (around
lines 26-28) with Lock/Unlock, wrap all field modifications in the spawned
goroutine within Run() (at lines 37, 41, 51, 61, 71) with Lock/Unlock, and wrap
all field reads in the Statistics() method (lines 105-112) with RLock/RUnlock to
ensure thread-safe access.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/runner/util.go`:
- Around line 10-13: The two-value range pattern used with fileutil.Lines in the
loop is incompatible with projectdiscovery/utils v0.11.1, which does not
implement iter.Seq2[string, error]. Remove the err assignment from the range
statement and refactor the loop to use the correct API pattern for
fileutil.Lines in v0.11.1, which likely uses channel-based file streaming
instead of the two-value iterator pattern currently attempted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| for item, err := range fileutil.Lines(file) { | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Go version/toolchain declared by repository =="
fd -a '^go\.mod$' | while read -r mod; do
echo "--- $mod ---"
rg -n '^(go|toolchain)\s+' "$mod" || true
done
echo
echo "== projectdiscovery/utils dependency version =="
rg -n 'github\.com/projectdiscovery/utils' go.mod go.sum || true
echo
echo "== call sites using fileutil.Lines =="
rg -n -C2 '\bfileutil\.Lines\s*\(' --type go
echo
echo "== changed iterator pattern =="
rg -n -C3 'for\s+item,\s*err\s*:=\s*range\s+fileutil\.Lines\s*\(' --type goRepository: projectdiscovery/subfinder
Length of output: 1143
🌐 Web query:
projectdiscovery/utils fileutil.Lines iterator signature go 1.24
💡 Result:
Based on an analysis of the projectdiscovery/utils library and its related repositories, there is no function named fileutil.Lines that implements a Go 1.24 iter.Seq iterator. The projectdiscovery/utils repository (and the deprecated projectdiscovery/fileutil repository) provides file handling utilities, but standard methods for reading file lines, such as fileutil.ReadFile (or similarly named functions in the codebase), typically return a channel of strings (chan string, error) and utilize goroutines to stream data [1][2]. While Go 1.24 introduced the iter package with iter.Seq for idiomatic iteration [3], there is no evidence that projectdiscovery/utils has adopted this specific signature for a function named Lines as of June 2026. The projectdiscovery suite primarily uses channel-based concurrency patterns for file streaming in their Go tooling [1][2].
Citations:
- 1: https://github.com/projectdiscovery/fileutil/blob/main/file.go
- 2: https://github.com/projectdiscovery/goflags/blob/main/slice_common.go
- 3: https://pkg.go.dev/[email protected]
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Import of fileutil.Lines in util.go =="
rg -n 'import|fileutil' pkg/runner/util.go -B5 -A5
echo
echo "== Check if fileutil is defined locally =="
fd -t f 'fileutil' --type go
echo
echo "== Exact go.mod dependency lines =="
grep -A2 -B2 'projectdiscovery/utils' go.mod
echo
echo "== Check the actual fileutil.Lines definition if available =="
rg -n 'func.*Lines' --type go | head -20Repository: projectdiscovery/subfinder
Length of output: 725
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Check if go.mod references exact v0.11.1 or uses replace =="
cat go.mod | grep -A5 -B5 projectdiscovery/utils || true
echo
echo "== Check go.sum for v0.11.1 hashes =="
grep 'projectdiscovery/utils' go.sum
echo
echo "== Search for Lines function definition across Go files =="
rg -n 'func.*Lines.*\(' --type rust -U
echo
echo "== Try to find iterator patterns or iter.Seq in the codebase =="
rg -n 'iter\.Seq' --type rust
echo
echo "== Check if there are any build or lint files =="
ls -la | grep -E '(Makefile|\.github|\.golangci|go\.work)'
echo
echo "== Examine the exact function signature expectation =="
rg -n 'Lines\(' -A1 -B1 pkg/runner/util.goRepository: projectdiscovery/subfinder
Length of output: 1063
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Search for Lines function definition in all Go files =="
rg -n 'func.*Lines' --type go -A3
echo
echo "== Check if there's any test or example of fileutil.Lines usage =="
rg -n 'fileutil\.Lines' -B2 -A5 --type go
echo
echo "== Look at projectdiscovery/utils version in go.sum more carefully =="
cat go.sum | grep -E 'projectdiscovery/utils'
echo
echo "== Check if there are any comments about API compatibility or version info =="
rg -n 'v0\.11|fileutil' go.mod
echo
echo "== Try to understand the actual return type by looking at usage context =="
rg -n 'for.*range.*fileutil' -A10 -B2 --type goRepository: projectdiscovery/subfinder
Length of output: 129
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Show all usage of fileutil.Lines =="
rg -n 'fileutil\.Lines' --type go -B5 -A10
echo
echo "== Check for any recent changes or comments mentioning fileutil API =="
rg -i -n 'lines|fileutil|iterator' pkg/runner/util.go
echo
echo "== Display the complete util.go file to see full context =="
cat -n pkg/runner/util.go | head -40
echo
echo "== Check if there's any version mismatch or TODO comment =="
rg -n 'TODO|FIXME|BUG|XXX' pkg/runner/util.goRepository: projectdiscovery/subfinder
Length of output: 1929
Remove the two-value range pattern—fileutil.Lines does not support iteration over error values in projectdiscovery/utils v0.11.1.
The pattern for item, err := range fileutil.Lines(file) uses a two-value range construct that requires fileutil.Lines to return an iter.Seq2[string, error]. However, projectdiscovery/utils v0.11.1 does not implement this iterator signature; the library uses channel-based file streaming patterns instead. This code will not compile.
Verify the correct API contract for fileutil.Lines in v0.11.1 and refactor accordingly—likely returning to a channel-based or error-handling pattern consistent with the library's design.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/runner/util.go` around lines 10 - 13, The two-value range pattern used
with fileutil.Lines in the loop is incompatible with projectdiscovery/utils
v0.11.1, which does not implement iter.Seq2[string, error]. Remove the err
assignment from the range statement and refactor the loop to use the correct API
pattern for fileutil.Lines in v0.11.1, which likely uses channel-based file
streaming instead of the two-value iterator pattern currently attempted.
subfinder 2.15.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed ### 🎉 New Features * Added shodanct passive source by @dogancanbakir in projectdiscovery/subfinder#1796 * Added Option `-vR`, `-virustotal-res` for VirusTotal source by @Bundy01 in projectdiscovery/subfinder#1719 * Added machine-readable source listing with `-ls -oJ` by @Gerijacki in projectdiscovery/subfinder#1812 ### 🐞 Bug Fixes * Fixed source leaks by @Mzack9999 in projectdiscovery/subfinder#1801 * Fixed drain source channels on cancel so source goroutines exit instead of leaking on a blocked send by @Mzack9999 in projectdiscovery/subfinder#1799 * Fixed crtsh's query by dropping unused certificate metadata from SQL query by @ChrisJr404 in projectdiscovery/subfinder#1787 * Fixed VirusTotal source by capping pagination and providing clearer 429 message by @ChrisJr404 in projectdiscovery/subfinder#1788 * Fixed Anubis source by switching subdomain API to anubisdb.com by @jatinder14 in projectdiscovery/subfinder#1815 ### Other Changes * Fixed lint issues by @dogancanbakir in projectdiscovery/subfinder#1820 * Refactored loadFromFile to use bufio.Scanner by @nandaanomi in projectdiscovery/subfinder#1791 ## New Contributors * @ChrisJr404 made their first contribution in projectdiscovery/subfinder#1787 * @Bundy01 made their first contribution in projectdiscovery/subfinder#1719 * @nandaanomi made their first contribution in projectdiscovery/subfinder#1791 * @jatinder14 made their first contribution in projectdiscovery/subfinder#1815 * @Gerijacki made their first contribution in projectdiscovery/subfinder#1812 **Full Changelog**: https://github.com/projectdiscovery/subfinder/compare/v2.14.0...v2.15.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0">https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!16007
Closes #1795
Adds Shodan's keyless CT-logs endpoint (ctl.shodan.io) as a default passive source. Named shodanct to avoid clashing with the existing key-based shodan source.
Summary by CodeRabbit