Skip to content

x-pack/filebeat/module/threatintel/malwarebazaar: properly handle code_sign array - #31552

Merged
efd6 merged 2 commits into
elastic:mainfrom
efd6:29972-threatintel-malwarebazaar
May 11, 2022
Merged

x-pack/filebeat/module/threatintel/malwarebazaar: properly handle code_sign array#31552
efd6 merged 2 commits into
elastic:mainfrom
efd6:29972-threatintel-malwarebazaar

Conversation

@efd6

@efd6 efd6 commented May 9, 2022

Copy link
Copy Markdown
Contributor

What does this PR do?

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.

Why is it important?

Previously data in the code_sign field would prevent documents from being processed.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

…e_sign array

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.
@efd6 efd6 added bug Filebeat Filebeat Team:Security-External Integrations 8.3-candidate backport-v8.2.0 Automated backport with mergify backport-7.17 Automated backport to the 7.17 branch with mergify labels May 9, 2022
@efd6
efd6 requested a review from a team as a code owner May 9, 2022 05:09
@efd6 efd6 self-assigned this May 9, 2022
@efd6
efd6 requested a review from a team as a code owner May 9, 2022 05:09
@efd6
efd6 requested review from cmacknz and kvch and removed request for a team May 9, 2022 05:09
@elasticmachine

Copy link
Copy Markdown
Contributor

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic Bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels May 9, 2022
Comment thread CHANGELOG.next.asciidoc Outdated
"sha256WithRSAEncryption"
],
"threat.indicator.file.x509.serial_number": [
"",

@efd6 efd6 May 9, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cause of this empty string is here to test that the processor handles the unlikely cases where the code signing is missing fields. I attempted to conditionally not append when _ingest?._value?.<fieldname> != "" but this invariably broke the pipeline with timeouts (using a variety of candidate syntaxes).

@adriansr adriansr May 11, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it's not possible to access _ingest._value inside a condition as it is not visible to painless.

The only alternative I can suggest is to use a script processor to split the array of objects into separate array fields. But if we're not expecting missing fields then the current approach is good

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For illustrative purposes:

  - script:
      lang: painless
      if: 'ctx.abusech?.malwarebazaar?.code_sign != null'
      source: |
        Map dest = new HashMap();
        for (def obj : ctx.abusech.malwarebazaar.code_sign) {
          for (def entry : obj.entrySet()) {
            dest.computeIfAbsent(entry.getKey(), k -> new ArrayList()).add(entry.getValue());
          }
        }
        ctx["_temp_"] = dest;

  - rename:
      field: _temp_.subject_cn
      target_field: threat.indicator.file.x509.subject.common_name
      ignore_missing: true
  - rename:
      field: _temp_.issuer_cn
      target_field: threat.indicator.file.x509.issuer.common_name
      ignore_missing: true
  - rename:
      field: _temp_.algorithm
      target_field: threat.indicator.file.x509.public_key_algorithm
      ignore_missing: true
  - rename:
      field: _temp_.valid_from
      target_field: threat.indicator.file.x509.not_before
      ignore_missing: true
  - rename:
      field: _temp_.valid_to
      target_field: threat.indicator.file.x509.not_after
      ignore_missing: true
  - rename:
      field: _temp_.serial_number
      target_field: threat.indicator.file.x509.serial_number
      ignore_missing: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. We can revisit this if we find that empty fields ever find their way into the code_sign array.

@elasticmachine

elasticmachine commented May 9, 2022

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-09T05:11:00.206+0000

  • Duration: 71 min 58 sec

Test stats 🧪

Test Results
Failed 0
Passed 6235
Skipped 728
Total 6963

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@cmacknz
cmacknz removed their request for review May 9, 2022 12:54

@adriansr adriansr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@efd6
efd6 merged commit ee5da02 into elastic:main May 11, 2022
mergify Bot pushed a commit that referenced this pull request May 11, 2022
…e_sign array (#31552)

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.

(cherry picked from commit ee5da02)

# Conflicts:
#	x-pack/filebeat/module/threatintel/fields.go
#	x-pack/filebeat/module/threatintel/malwarebazaar/ingest/pipeline.yml
#	x-pack/filebeat/module/threatintel/malwarebazaar/test/malwarebazaar.ndjson.log-expected.json
mergify Bot pushed a commit that referenced this pull request May 11, 2022
…e_sign array (#31552)

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.

(cherry picked from commit ee5da02)
efd6 added a commit that referenced this pull request May 12, 2022
…e_sign array (#31552) (#31598)

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.

(cherry picked from commit ee5da02)

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
efd6 added a commit that referenced this pull request Jun 1, 2022
…e_sign array (#31552)

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.

(cherry picked from commit ee5da02)

# Conflicts:
#	x-pack/filebeat/module/threatintel/fields.go
#	x-pack/filebeat/module/threatintel/malwarebazaar/ingest/pipeline.yml
#	x-pack/filebeat/module/threatintel/malwarebazaar/test/malwarebazaar.ndjson.log-expected.json
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
…e_sign array (#31552)

Previously, the code_sign field was treated as a keyword which broke handling of
the structured data in the code signing details. The handling of the code signing
also incorrectly assumed that only a single value could be present (in reality,
this is the case for all examples in the malwarebazaar data set, but may not be
in the future) by using rename rather than appending the details to the relevant
x509 fields. This change maps the code_sign field as a nested field and appends
into the x509 fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.3-candidate backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.2.0 Automated backport with mergify bug Filebeat Filebeat

3 participants