← 输入框|github.com|刷新
Skip to content

Add matchedRule to cascading scans #493

Closed

Description

@EndPositive

➹ New Feature implementation request

Is your feature request related to a problem?

As a secureCodeBox user, with cascading scans enabled, I would like to know on what CascadingRule a scan has been triggered.

Current situation

Cascading scans are triggered by checking if a CascadingRule matches one of the findings:

for (const finding of findings) {
// Check if one (ore more) of the CascadingRule matchers apply to the finding
const matches = cascadingRule.spec.matches.anyOf.some(matchesRule =>
isMatch(finding, matchesRule) || isMatchWith(finding, matchesRule, wildcardMatcher)
);
if (matches) {
cascadingScans.push(getCascadingScan(parentScan, finding, cascadingRule))
}
}

An example CascadingRule:

kind: CascadingRule
metadata:
name: "nmap-hostscan"
labels:
securecodebox.io/invasive: non-invasive
securecodebox.io/intensive: light
spec:
matches:
anyOf:
- category: "Subdomain"
osi_layer: "NETWORK"

The generated scan only contains ownerReferences, but no information on why it was triggered.

Describe the solution you'd like

We could copy the match onto the cascading scan's metadata:

apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
  name: "amass-example.com-nmap-hostscan"
  labels: [...]
  annotations: [...]
  ownerReferences: [...]
  matchedRule:
    category: "Subdomain"
    osi_layer: "NETWORK" 
spec:
  scanType: "nmap"
  parameters:
    # Treat all hosts as online -- skip host discovery
    - "-Pn"
    # Target Port of the finding
    - "example.com"
  cascades: true

Describe alternatives you've considered

We could also move the metadata.matchedRule to spec.matchedRule. Probably easier to implement with the types.

Additional context

Should be pretty simple to implement. If you like the format I can create a PR myself. Main or V3 as a base?

Activity

  1. changed the title [-]Add scan.[/-] [+]Add matchedRule to cascading scans[/+] on Jun 12, 2021
  2. rfelber commented on Jun 16, 2021

    @rfelber
    Member

    Thanks for your proposal and spec! It would be helpful if you can add some additional context about the problem context you have. Is it more about better debugging possibilities or is the “matchedRule” information helpful for other features you have in mind?

  3. J12934 commented on Jun 16, 2021

    @J12934
    Member

    It's not possible to set "custom keys" in the metadata field, these are the same for all Kuberntes resources.

    It's already possible to find out which "CascadingRule" matched, by looking at the cascading.securecodebox.io/chain annotation of the created scan. This contains a comma separated list of all CascadingRules triggered which lead to the scan to be created. The last entry in the list is the CascadingRule used to create the scan.

    Note: this only contains the name of the CascadingRule, and doesn't state which "MatchingRule" was used. Including these might be a big more difficult than in the example, as we expect that we need to support other types than the anyOf which is currently currently supported. E.g. supporting noneOf, allOf etc.
    The suggested structure would not allow this to be accurately described. I think it might be more helpful to include the id of the finding which triggered the scan. With that it would be easier you could compare the finding with the CascadingRule to figure out why it was triggered.

  4. EndPositive commented on Jun 17, 2021

    @EndPositive
    ContributorAuthor

    Thanks for the thorough answers! Here's some more context to my issue: I was working on a simple graph to visualize cascading scans. As you can see, Amass scan started an nmap scan.

    image

    The information for the graph is gathered using the ownerReferences field in a similar manner as kubectl-tree.

    On the links between nodes, we would love to give some more information on why nmap was started as a result of amass.

    @J12934 The addition of noneOf would indeed make things more complicated. As you said, it might be more useful to include the finding ID in the scan metadata as it gives the most flexibility in our implementation and won't require changes in secureCodeBox along the road when you want to implement noneOf, and allOf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions