-
Notifications
You must be signed in to change notification settings - Fork 14.9k
RPC vulns and services reports resources and parents (service only) #21305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adfoster-r7
merged 3 commits into
rapid7:master
from
sjanusz-r7:db-vulns-and-services-rpc-new-report-approach
May 15, 2026
+35
−12
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -453,6 +453,8 @@ def rpc_hosts(xopts) | |
| # * 'state' [String] Service state. | ||
| # * 'name' [String] Service name. | ||
| # * 'info' [String] Additional information about the service. | ||
| # * 'resource' [Hash] Service resource. | ||
| # * 'parents' [Array<Hash>] List of parent services with same set of keys as the service. | ||
| # @example Here's how you would use this from the client: | ||
| # rpc.call('db.services', {}) | ||
| def rpc_services( xopts) | ||
|
|
@@ -471,18 +473,8 @@ def rpc_services( xopts) | |
| ret = {} | ||
| ret[:services] = [] | ||
|
|
||
| wspace.services.includes(:host).where(conditions).offset(offset).limit(limit).each do |s| | ||
| service = {} | ||
| host = s.host | ||
| service[:host] = host.address || "unknown" | ||
| service[:created_at] = s[:created_at].to_i | ||
| service[:updated_at] = s[:updated_at].to_i | ||
| service[:port] = s[:port] | ||
| service[:proto] = s[:proto].to_s | ||
| service[:state] = s[:state].to_s | ||
| service[:name] = s[:name].to_s | ||
| service[:info] = s[:info].to_s | ||
| ret[:services] << service | ||
| wspace.services.includes(:host, :parents).where(conditions).offset(offset).limit(limit).each do |s| | ||
| ret[:services] << process_service(s) | ||
| end | ||
| ret | ||
| } | ||
|
|
@@ -511,6 +503,7 @@ def rpc_services( xopts) | |
| # * 'host' [String] Vulnerable host. | ||
| # * 'name' [String] Exploit that was used. | ||
| # * 'refs' [String] Vulnerability references. | ||
| # * 'resource' [String] Vulnerability resource. | ||
| # @example Here's how you would use this from the client: | ||
| # rpc.call('db.vulns', {}) | ||
| def rpc_vulns(xopts) | ||
|
|
@@ -541,6 +534,7 @@ def rpc_vulns(xopts) | |
| vuln[:host] = v.host.address || nil | ||
| vuln[:name] = v.name | ||
| vuln[:refs] = reflist.join(',') | ||
| vuln[:resource] = v.resource | ||
| ret[:vulns] << vuln | ||
| end | ||
| ret | ||
|
|
@@ -1988,6 +1982,35 @@ def rpc_disconnect | |
| end | ||
|
|
||
|
|
||
| private | ||
|
|
||
| # Process an Mdm::Service object to a hash, with recursive parent lookup. | ||
| # | ||
| # @param mdm_service [Mdm::Service] The service record to process. | ||
| # @param recursion_count [Integer] Current recursion iteration count | ||
| # @return [Hash] Serialized service data. | ||
| def process_service(mdm_service, recursion_count = 0) | ||
| return { error: :recursion_limit_reached } unless recursion_count >= 0 && recursion_count < 6 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we bump this to 10, and raise an exception here for the depth issue instead? 👀 Not a blocker, I believe we can avoid the n+1 query issues here with a native SQL query |
||
|
|
||
| service = {} | ||
| host = mdm_service.host | ||
|
|
||
| service[:host] = host.address || "unknown" | ||
| service[:created_at] = mdm_service[:created_at].to_i | ||
| service[:updated_at] = mdm_service[:updated_at].to_i | ||
| service[:port] = mdm_service[:port] | ||
| service[:proto] = mdm_service[:proto].to_s | ||
| service[:state] = mdm_service[:state].to_s | ||
| service[:name] = mdm_service[:name].to_s | ||
| service[:info] = mdm_service[:info].to_s | ||
| service[:resource] = mdm_service[:resource] | ||
| service[:parents] = mdm_service.parents.map do |parent| | ||
| process_service(parent, recursion_count + 1) | ||
| end | ||
|
|
||
| service | ||
| end | ||
|
|
||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.