Skip to content

feat: multi-root regex subject support in Extract()#43

Open
je-bugshell wants to merge 2 commits into
owasp-amass:developfrom
je-bugshell:feat/multi-root-regex-subject
Open

feat: multi-root regex subject support in Extract()#43
je-bugshell wants to merge 2 commits into
owasp-amass:developfrom
je-bugshell:feat/multi-root-regex-subject

Conversation

@je-bugshell

Copy link
Copy Markdown

Summary

Building on #42, this is a proposal for improving how Extract() handles regex subjects that match multiple entities. Currently, only the first match is returned. With this change, all matching entities become root vertices, each with its own walked relation tree.

For example, <fqdn:#/.*\.owasp\.org$/#> - <portrelation:port> -> <service:*> would return results for every matching subdomain, not just the first one.

  • Results.Node replaced with Results.Nodes []*Vertex (JSON key changes from "entity" to "entities")
  • New findSubjects() collects all regex matches; delegates to findFirstSubject() for literal subjects
  • Extract() loops over all matched entities, walks each independently, skips entities without valid walks
  • Entities that match the regex but lack the required relation structure are silently skipped rather than causing an error

I'm not a Go developer, so this is AI-assisted. Would appreciate a careful review.

Note on JSON output

The JSON output shape changes from {"entity": {...}} to {"entities": [{...}]}. The only caller I could find (amass/internal/assoc/cli.go) serializes the result with json.MarshalIndent and doesn't access Results.Node directly, so it should work without code changes. Anything parsing the JSON output programmatically would need updating.

Depends on

Test plan

  • All 20 tests pass: go test ./triples/ -v
  • Existing tests updated from results.Node to results.Nodes[0]
  • TestExtractMultiRootRegexSubject: regex matching 2 of 3 FQDNs, match-all with partial walks, match-nothing
  • TestExtractServicesForWildcardFQDN: "give me all services for *.owasp.org"
  • TestExtractFQDNToIPToService: two-hop walk from regex FQDNs through IPs to Services
  • TestExtractRegexPartialWalks: 5 FQDNs match regex, only 2 have services

findFirstSubject() was passing the raw #/.../# key into subjectToAsset(),
which sent it as a literal SQL filter. Used FindEntitiesByType() with
in-memory valueMatch() filtering instead, same approach as performWalk().
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