Skip to content

feat: add shodanct passive source - #1796

Merged
Mzack9999 merged 2 commits into
devfrom
feat/shodanct-source
Jun 16, 2026
Merged

Mzack9999 merged 2 commits into
devfrom
feat/shodanct-source

Conversation

@dogancanbakir

@dogancanbakir dogancanbakir commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

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

  • New Features
    • Added Shodan Certificate Transparency as a new passive subdomain discovery source. It is enabled by default, requires no API key, and supports recursive enumeration.
  • Test Updates
    • Updated source list expectations to include the new CT source.
  • Chores
    • Improved file-loading behavior for line-based inputs by handling errors during iteration.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

A new Shodan CT passive scraping source is added that queries https://ctl.shodan.io/api/v1/domain/<domain>/hostnames to retrieve hostnames from certificate transparency logs. The source is registered in the passive source registry, marked as default and recursive-capable with no API key requirement, and test expectations are updated. Additionally, file reading error handling in the runner utility is refactored to check errors per-line instead of consuming a full channel.

Changes

Shodanct Passive Source

Layer / File(s) Summary
shodanct Source type, Run, and metadata
pkg/subscraping/sources/shodanct/shodanct.go
Defines Source struct with per-run counters and elapsed time. Run performs an async HTTP GET to ctl.shodan.io, decodes the JSON hostname array, extracts subdomains via session.Extractor.Extract, streams results while honoring context cancellation, and tracks request/error/result counts. Metadata methods mark the source as default, recursive-capable, and key-free.
Source registration and test expectations
pkg/passive/sources.go, pkg/passive/sources_test.go
Imports shodanct and appends &shodanct.Source{} to AllSources. Adds "shodanct" to the all-sources, default, and default-recursive expected lists in TestSourceCategorization.

File Utility Refactoring

Layer / File(s) Summary
loadFromFile per-line error checking
pkg/runner/util.go
Refactors loadFromFile to iterate over fileutil.Lines(file) with immediate per-line error checking, returning on error instead of using channel-based file reading.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 Hippity-hoppity, certificates galore,
Shodan CT brings subdomains by the score!
A GET request zips through the morning dew,
Hostnames extracted, all shiny and new.
No API key needed — free as a breeze,
shodanct hops in and does just as it please! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning All changes are directly related to implementing the shodanct source. The refactoring in util.go appears to be an unrelated change not mentioned in the objectives. Remove or justify the refactoring in pkg/runner/util.go, as it is unrelated to implementing the shodanct source [#1795].
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding the shodanct passive source for subdomain discovery.
Linked Issues check ✅ Passed The PR fully implements issue #1795 by creating a new shodanct source that queries the Shodan CT Logs API endpoint without requiring authentication.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/shodanct-source

Comment @coderabbitai help to get the list of available commands and usage tips.

@dogancanbakir dogancanbakir self-assigned this Jun 16, 2026
@dogancanbakir
dogancanbakir requested a review from Mzack9999 June 16, 2026 11:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/subscraping/sources/shodanct/shodanct.go (1)

36-36: 💤 Low value

Consider 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.PathEscape or constructing the URL with url.URL would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 640befe and 2ae4545.

📒 Files selected for processing (3)
  • pkg/passive/sources.go
  • pkg/passive/sources_test.go
  • pkg/subscraping/sources/shodanct/shodanct.go

Comment on lines +16 to +21
type Source struct {
timeTaken time.Duration
errors int
results int
requests int
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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=go

Repository: 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.go

Repository: 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 -100

Repository: projectdiscovery/subfinder

Length of output: 6110


🏁 Script executed:

# Find AllSources definition and usage
rg -n "AllSources" --type go -B 3 -A 3

Repository: 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 -100

Repository: 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 20

Repository: 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 -50

Repository: 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 -60

Repository: 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 82179ff6-61a8-4b41-95c4-04c91a7d34f4

📥 Commits

Reviewing files that changed from the base of the PR and between 2ae4545 and ba2f6d3.

📒 Files selected for processing (1)
  • pkg/runner/util.go

Comment thread pkg/runner/util.go
Comment on lines +10 to +13
for item, err := range fileutil.Lines(file) {
if err != nil {
return nil, err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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 go

Repository: 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:


🏁 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 -20

Repository: 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.go

Repository: 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 go

Repository: 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.go

Repository: 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.

@Mzack9999
Mzack9999 merged commit 2a8ce2f into dev Jun 16, 2026
9 checks passed
@Mzack9999
Mzack9999 deleted the feat/shodanct-source branch June 16, 2026 13:25
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Shodan CT Logs API as passive source

2 participants