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

Configure Hooks to run per scan #728

Closed

Description

@EndPositive

➹ New Feature implementation request

It would be extremely helpful if you can decide on a per-scan basis which hooks to run.

Example use case

Installed hooks: Cascading Scans, DefectDojo persistence provider

Started scan:

apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
  name: "nmap-open-ports"
spec:
  scanType: "nmap"
  parameters:
    - "-p-"
    # Against Host
    - "example.com"

The initial scan would create this finding:

 {
    "name":"Open Port: 443 (http)",
    "category":"Open Port",
    "attributes":{
       "port":443,
       "state":"open",
       "service":"http",
       "serviceProduct":"nginx",
       "serviceVersion":null,
       "tunnel":"ssl"
    },
 },

Cascading Rule:

apiVersion: "cascading.securecodebox.io/v1"
kind: CascadingRule
metadata:
  name: "nmap-service-detection"
spec:
  matches:
    anyOf:
      - category: "Open Port"
        attributes:
          state: open
  scanSpec:
    scanType: "nmap"
    parameters:
      - "-p{{attributes.port}}"
      - "-sV"
      - "--service-all"
      # Against Host
      - "{{$.hostOrIP}}"

When triggered, the Cascading Scan would create the following finding with more service information:

 {
    "name":"Open Port: 443 (http)",
    "category":"Open Port",
    "attributes":{
       "port":443,
       "state":"open",
       "service":"http",
       "serviceProduct":"nginx",
       "serviceVersion":"1.20.1",
       "tunnel":"ssl"
    },
 },

In this case, I would like to not import the initial scan results into DefectDojo but still run the Cascading Scan hook.

Describe the solution you'd like

Once #695 is merged, we could use Hook Priorities to solve this problem. One could deploy Cascading Scans with a priority of 1 and DefectDojo with 0. Then on a per-scan basis one may define what hook ranges to execute.

apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
  name: "nmap-open-ports"
spec:
  hookRanges:
    - "1"
  scanType: "nmap"
  parameters:
    - "-p-"
    # Against Host
    - "example.com"

hookRanges would be a list of ranges to execute. A range could have the following formats:

  • 0-1: Execute hooks with priority between 0 and 1 (inclusive)
  • 0: Execute hooks with priority 0.

The orderedHookStatusses status field would still include the skipped hooks but marks them with state Skipped.

Describe alternatives you've considered

Proposed workarounds involved setting up multiple namespaces with different hooks installed and then running the scan in that namespace.

Activity

  1. J12934 commented on Oct 15, 2021

    @J12934
    Member

    I like the idea of beeing able to select / filter out certain hooks in a namespace.
    I would suggest to use labels and labelSelectors to select which hooks should be run instead of hook prios.

  2. EndPositive commented on Oct 19, 2021

    @EndPositive
    ContributorAuthor

    Hi @J12934, that seems reasonable considering that we have the same mechanism for selecting cascading rules.

    I would like to work on this. Could you provide a sample spec here?

  3. J12934 commented on Oct 19, 2021

    @J12934
    Member

    Would expect it to look something like the to following (to support both both matchLabels & matchExpressions)

    apiVersion: "execution.securecodebox.io/v1"
    kind: Scan
    metadata:
      name: "nmap-open-ports"
    spec:
      hookSelector:
        matchLabels:
          type: defectdojo
      scanType: "nmap"
      parameters:
        - "-p-"
        # Against Host
        - "example.com"

    with matchExpressions:

    apiVersion: "execution.securecodebox.io/v1"
    kind: Scan
    metadata:
      name: "nmap-open-ports"
    spec:
      hookSelector:
        matchExpressions:
          key: defectdojo
          operator: In
          values: [ "foo", "bar" ]
      scanType: "nmap"
      parameters:
        - "-p-"
        # Against Host
        - "example.com"
  4. malexmave commented on Oct 22, 2021

    @malexmave
    Member

    Another case where this is helpful is for scan types that aren't supported in DefectDojo. For example, at the moment, Git-repo-scanner is not supported, and the DD import is affected by #746, making most of the findings disappear before the cascadingScans hook is even triggered. This means that they never get the chance to run on most of the findings of the repo scanner. Given that the fix for the DD issue seems to require changing the default behavior of the DD importer (in the DD instance), it may in some cases be easier to just disable the DD hook for the repo-scanner and only import the results of the cascadingScan.

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