Skip to content

Fix crashes, hangs and logic bugs found in the v5 engine and plugins - #1

Open
The-Inceptions wants to merge 22 commits into
developfrom
fix/review-findings
Open

The-Inceptions wants to merge 22 commits into
developfrom
fix/review-findings

Conversation

@The-Inceptions

Copy link
Copy Markdown
Owner

Summary

Fixes the confirmed findings from an ultrareview of the master → main changes (engine core, plugin framework and plugins/api, and the other plugins), plus a few related bugs found while checking them. There is one commit per fix.

Crashes and hangs

  • Session network semaphore deadlock. Acquire held a mutex while blocking and Release needed the same mutex, so once a session reached its connection limit every network plugin hung. It is now a resizable counter with a sync.Cond.
  • Log streaming crash. The pubsub logger raced on its subscriber list and leaked a goroutine per log line for each disconnected WebSocket client. When the session ended, those goroutines panicked with "send on closed channel". The logger now uses a locked map, non-blocking sends, Unsubscribe and an idempotent Close. The WebSocket handler reads control frames and unsubscribes when the client goes away. Session.Kill now uses sync.Once.
  • PutAsset nil dereference when CreateAsset fails. Bulk ingest runs it in a bare goroutine, so this crashed the engine.
  • IPVerse concurrent map access from up to 16 handler instances at once.
  • RDAP netip.MustParseAddr panic on malformed responses.

Logic bugs

  • RDAP dropped whole records when the "registration" or "last changed" event was missing, never tagged AutnumRecords with their source, and skipped TLS certificate verification.
  • PassiveTotal never sent a request.
  • JARM fingerprinted the Service instead of its host. It now also only runs in active mode.
  • Plugin startup rollback never stopped plugins that had already started.
  • crt.sh results were credited to HackerTarget, which made HackerTarget skip those names.
  • reservedAS tagged the netblock twice instead of tagging the AS.
  • Aviato never tried backup API keys.
  • Brute-force alterations corrupted the label while generating guesses.
  • CreateOrgAsset rewrote the caller's Organization struct, which the TXT handler shares across calls.
  • Horizontals queued the DomainRecord instead of the registered domain's FQDN.
  • Organization and location scope matching compared a 0–1 similarity score with a 0–100 confidence. Matching is now exact-only, because the similarity metric scores a contained name ("Apple" in "Pineapple Inc") as a perfect match.

Clarity and cleanup

  • The backlog's "ttl ≤ 0 means leases never expire" behavior is now explicit. No functional change.
  • Request contexts in plugin paging and API-key loops are cancelled after each request instead of deferred until the function returns.
  • Duplicate banner URLs are skipped, dead fingerprint code is removed, and a duplicated horizontals block is now one helper.

Behavior changes

  • PassiveTotal now queries when credentials are configured, and HackerTarget runs again alongside crt.sh.
  • JARM probing now runs, in active mode only.
  • RDAP requires valid certificates, so it fails behind a TLS-intercepting proxy whose CA isn't trusted.
  • A WebSocket log client that falls more than 1,000 lines behind misses lines instead of piling up goroutines.
  • Fuzzy organization/location matching is gone. With the default config (confidence 50) nothing changes.

Not included

  • Review findings that turned out to be false positives, because asset-db returns an error rather than an empty slice when nothing matches: ents[0] in PutAsset and dns/subs.go, and the http_probes len(tags) nit.
  • Separate issues found while checking the fixes:
    • completions dropped by sendElementOnExit leave backlog items leased forever;
    • IPVerse's ASN map is shared across sessions;
    • the horizontals TLSCertificate branch never queues the certificate;
    • engine.go doesn't shut down the dispatcher and session manager when plugin loading fails.

Test plan

  • CGO_ENABLED=0 go build ./... and go vet ./...
  • CGO_ENABLED=0 go test ./...
  • go test -race on engine/sessions/..., engine/pubsub, engine/plugins/brute, engine/plugins/scrape and engine/registry
  • New tests: semaphore, pubsub logger, backlog leases without expiry, exact-only scope matching, brute-force alterations, IPVerse reservations. The scope and alterations tests fail against the old code.
  • Smoke test: run the engine and a short passive amass enum against an authorized domain

🤖 Generated with Claude Code

Adem Rosic and others added 22 commits October 11, 2026 21:54
sessSemaphore.Acquire held its mutex while blocking on the channel
semaphore, and Release needed the same mutex to return a token. Once a
session reached its connection limit, every network plugin in that
session hung forever.

Replace the channel and mutex with a counter and a sync.Cond that is
resized in place, so waiters are never stranded on a replaced channel.
This also removes a divide-by-zero when NumOfSessions() returns 0 and
a permanent hang when more than MaxNetworkConns sessions exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three problems in the pubsub logger combined into a process crash:
Publish read the subscriber list without the lock, a full subscriber
channel made msgToSubscribers spawn a goroutine that blocked forever,
and there was no way to unsubscribe. Once a WebSocket log client
disconnected, every log line leaked a goroutine, and when the session
ended Close closed the channels under those goroutines, which then
panicked with "send on closed channel".

The logger now keeps subscribers in a map guarded by its lock, sends
without blocking and drops a message for a subscriber that has fallen
1000 messages behind, supports Unsubscribe, and can be closed more
than once. The WebSocket handler reads from the connection so pong and
close frames are processed, and unsubscribes and closes the connection
when the client goes away.

Session.Kill also closed its done channel after a non-atomic check, so
two concurrent CancelSession calls could close it twice and panic. It
now uses sync.Once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateAsset returns a nil entity with its error, but PutAsset returned
entity.ID on that path. PutAssets calls PutAsset from a bare goroutine,
so a failed database write during bulk ingest crashed the engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IPVerse handler runs up to 16 instances at once, but it read and
wrote its ASN map without synchronization. Concurrent map access is a
fatal error in Go, so a scan that found several autonomous systems at
the same time could crash the process.

Claim the ASN under a mutex before querying, and release the claim if
the query fails so a later event can retry it. This also stops
concurrent events for the same ASN from sending duplicate requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dresses

The RDAP netblock and autnum handlers threw away the whole record when
the response had no parsable "registration" or "last changed" event,
so no IPNetRecord or AutnumRecord was stored and the follow-up
handlers never ran for that netblock or ASN. The dates are now set
when present and left empty otherwise; asset-db accepts empty dates.

The netblock handler also used netip.MustParseAddr on the response's
start and end addresses, which panicked on a malformed response. It
now skips the record instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matchesOrg and matchesLocation compared a 0-1 similarity score against
a 0-100 confidence, so with any real confidence setting only exact
names ever matched. The fuzzy path only ran when the confidence was 1
or lower (for example, no transformation configured for the type), and
then it accepted almost any name at confidence 0 or 1.

Rather than switch fuzzy matching on, remove it. The Smith-Waterman-
Gotoh similarity is normalized by the shorter string, so a name
contained in a longer one scores as a perfect match ("Apple" vs
"Pineapple Inc"), which would let unrelated organizations widen the
scope. Exact matches behave as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ClaimNext treats ttl <= 0 as "leases never expire", which every
session relies on through SetLeaseTTL(0). It was written as a
block-scoped `ttl := 30 * time.Second` that shadowed the parameter,
which reads like a bug and was reported as one by code review.
"Fixing" the shadow would make entities that take longer than 30s to
process get dispatched a second time.

Express the same behavior with an explicit flag and a named constant,
correct the doc comments on ClaimNext, RequeueExpired and SetLeaseTTL,
explain the SetLeaseTTL(0) call, and add a test that pins the
behavior down. No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RDAP plugin set InsecureSkipVerify on the transport shared by its
bootstrap and RDAP clients. Anyone positioned on the network could
then feed forged bootstrap data or registration records into the
asset graph. RDAP only talks to IANA and the RIRs, which all present
valid certificates, so require verification and TLS 1.2 or later, the
same change made to amasshttp.DefaultClient in 6488957.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pagination loop was `for lastid != ""` with lastid starting empty,
so its body never ran and the plugin returned nothing even with valid
credentials. Its `continue` statements would also have retried a
failing request forever once the loop did run.

Page like the BinaryEdge plugin: the cursor and a 500-page cap are
shared across credentials, a failed request moves on to the next
credential from the same page, and paging stops when the API returns
an empty or unchanged cursor. The request context is now cancelled
after each request instead of piling up deferred cancels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JARM plugin built its fingerprint targets from the Service entity
rather than the FQDN or IP address on the other end of the port edge.
support.JARMFingerprint only accepts an FQDN or IP address, so every
attempt failed and no JARM hash was ever stored.

Because the fix turns on real TLS probing that has never run before,
the handler now also returns early unless the session is in active
mode, as the HTTP probes do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LoadAndStartPlugins passed its started list to stopPlugins when a
plugin failed to start, but never added anything to that list, so the
plugins that had already started were left running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The crt.sh plugin's source name was copied from the HackerTarget
plugin. Source names drive the "last monitored" markers, so crt.sh,
which runs first, marked every FQDN as already checked by
HackerTarget, and HackerTarget then skipped those names within its
TTL. crt.sh results were also attributed to HackerTarget at
confidence 100.

Existing databases keep the old tags until their TTL runs out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reservedAS created the AS 0 entity and then added the source property
to the netblock a second time instead of to the new AS, so the AS was
stored without its source. Only neo4j is affected in practice, since
the sqlite and postgres repositories reject AS number 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RDAP autsys handler's lookup() only returns a stored AutnumRecord
that carries the plugin's source property, but store() only tagged the
registration edge, never the record itself. Within the TTL, lookups of
an already-stored record always missed, so the record was never
dispatched again to the autnum handler's downstream processing.

Tag the record the same way the netblock handler tags IPNetRecords.
Records stored before this change stay untagged until their TTL runs
out and they are stored again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The employees and funding-rounds handlers declared their page counters
outside the API-key loop and used `continue` on HTTP failures. The
`continue` advanced the page, so a failure on the first key ended the
paging and the post-loop check then left the key loop: backup keys
were never tried.

Break out of the page loop on HTTP failures instead, so the next key
retries the same page. The request contexts are now cancelled after
each request instead of piling up deferred cancels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
additions, deletions and substitutions wrote into the label's own rune
slice while generating guesses, so every guess after the first was
built from an already-modified label. For "abc", deletions produced
"bc" three times instead of "bc", "ac" and "ab", and substitutions
left earlier positions replaced. additions had the same problem
whenever the rune slice had spare capacity, which is the usual case.
Alteration-based brute forcing therefore produced fewer and partly
wrong guesses.

Build each guess in a new slice, and add tests with exact expected
output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateOrgAsset normalized the Organization it was given in place,
overwriting Name, Jurisdiction and ID. The TXT record handler passes
shared structs from its package-level prefixes map, so after the first
match "Google LLC" stayed "google" for the rest of the process, and
later sessions lost the real display name claim. The unsynchronized
read of that shared struct in the TXT handler was also a data race.

Normalize a copy instead, which fixes this for every caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a DomainRecord's registrant organization or location was in
scope, processDomainRecord looked up the registered domain's FQDN but
then queued the DomainRecord itself. The FQDN handlers (DNS, brute
forcing and the rest) therefore never reviewed the newly in-scope
domain. Queue the FQDN, as the organization, location and TLS
certificate handlers already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fingerprint add/list/match functions and their imports were
committed already commented out and are referenced nowhere. Only the
Fingerprint type is used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Many plugins created a timeout context per request inside a paging or
API-key loop but released it with `defer cancel()`, so every context
and its timer stayed alive until the whole query returned. Call
cancel() as soon as the request returns instead; RequestWebPage reads
and closes the response body before it returns, so nothing uses the
context afterwards.

The JARM probe loop had the same problem and also deferred closing
each connection, keeping up to ten sockets open per target. It now
cancels the dial context right after dialing and closes each
connection after its probe, with the probe exchange moved into a
small helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The banner URL handler stored and dispatched every regex match from a
service's response body, and pages routinely repeat the same link many
times. Skip URLs already seen in the same banner. The key is the full
raw URL, since stringset lowercases its keys and would merge URLs whose
paths differ only in case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The organization and location handlers contained the same block,
byte for byte, that walks from a contact record to the registration
records and TLS certificates it belongs to and expands the scope from
them. Move it into one helper on horizPlugin so a fix to one copy
can't miss the other. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant