feat: multi-root regex subject support in Extract()#43
Open
je-bugshell wants to merge 2 commits into
Open
Conversation
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Nodereplaced withResults.Nodes []*Vertex(JSON key changes from"entity"to"entities")findSubjects()collects all regex matches; delegates tofindFirstSubject()for literal subjectsExtract()loops over all matched entities, walks each independently, skips entities without valid walksI'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 withjson.MarshalIndentand doesn't accessResults.Nodedirectly, so it should work without code changes. Anything parsing the JSON output programmatically would need updating.Depends on
Test plan
go test ./triples/ -vresults.Nodetoresults.Nodes[0]TestExtractMultiRootRegexSubject: regex matching 2 of 3 FQDNs, match-all with partial walks, match-nothingTestExtractServicesForWildcardFQDN: "give me all services for*.owasp.org"TestExtractFQDNToIPToService: two-hop walk from regex FQDNs through IPs to ServicesTestExtractRegexPartialWalks: 5 FQDNs match regex, only 2 have services