Skip to content

[ti_opencti] OpenCTI integration - #7385

Merged
ebeahan merged 100 commits into
elastic:mainfrom
chrisberkhout:ti_opencti
Oct 16, 2023
Merged

[ti_opencti] OpenCTI integration#7385
ebeahan merged 100 commits into
elastic:mainfrom
chrisberkhout:ti_opencti

Conversation

@chrisberkhout

@chrisberkhout chrisberkhout commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

Proposed commit message

[ti_opencti] OpenCTI integration

A new integration for the OpenCTI threat intelligence platform:
https://www.filigran.io/en/solutions/products/opencti/

It queries a GraphQL API for indicator data using the CEL input,
populates ECS threat fields where possible and preserves additional
indicator-related data under an `opencti` prefix.

Background

OpenCTI integration development notes has some some background information about OpenCTI and the approach taken with this integration.

OpenCTI Mappings is a spreadsheet with field-level notes.

Status

What's working

This version is ready for final review and then release.

Since the demo timestamp mapping has been changed. The current mappings of the various timestamps are described in the README. The motivations for the change were to show incoming data at recent @timestamp values for a more intuitive user experience, and to build visualizations on logs-* rather than ad-hoc data views to avoid issues with persistent visualization errors and controls not working.

Potential future enhancements

  • Set up a transform to provide a view that shows the most recent non-expired data, as done elsewhere.
  • Support limiting the time range of the initial fetch.
  • Parse STIX rules for atomic indicators, so alert rules can work when no related observable is present, if requested.
    Infosec have said that, in general, observables will be present. For the demo.opencti.io data, only about 0.17% of indicators have a STIX pattern but no observables.

How to test this PR locally

Build and install the integration as usual:

cd packages/ti_opencti
elastic-package stack up -d
elastic-package build -v
elastic-package install -v
elastic-package test pipeline -v
elastic-package test system -v

With a free account on the OpenCTI public demo instance you can get an API key (in the UI under Profile > API access) that will work as a bearer token as long as you're logged in. The OpenCTI demo instance has about 1.2 million indicators. The API token and base URL are the only setting required when adding a policy.

Making dashboard changes

If dashboards need to be updated, it may be necessary to downgrade to version 8.7.1 of the stack and export them from there, to avoid failing with the error "packages with dashboards exported since Kibana 8.8.0 may not be installed till 8.10.0, please export the dashboard/s from a different version". To make the integration work on 8.7.1, some further changes are necessary:

Changes necessary to run on 8.7.1
diff --git a/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs b/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
index f4d975ed9..20067bf9a 100644
--- a/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
+++ b/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
@@ -43,15 +43,15 @@ program: |
         {}
     )
   }).with({
-    "Body": {
-      "query": state.query,
+    "Body": '''{
+      "query": ''' + state.query.encode_json() + ''',
       "variables": {
-        "after": has(state.cursor) && has(state.cursor.value) ? state.cursor.value : null,
-        "first": state.page_size,
+        "after": ''' + (has(state.cursor) && has(state.cursor.value) ? state.cursor.value.encode_json() : 'null') + ''',
+        "first": ''' + string(state.page_size) + ''',
         "orderBy": "modified",
-        "orderMode": "asc",
+        "orderMode": "asc"
       }
-    }.encode_json()
+    }'''
   }).do_request().as(resp,
     bytes(resp.Body).decode_json().as(body, state.with({
       "events": body.data.indicators.edges.map(e, e.node.with(
diff --git a/packages/ti_opencti/manifest.yml b/packages/ti_opencti/manifest.yml
index 02d8ca449..881eb2eff 100644
--- a/packages/ti_opencti/manifest.yml
+++ b/packages/ti_opencti/manifest.yml
@@ -11,7 +11,7 @@ categories:
   - threat_intel
 conditions:
   kibana:
-    version: "^8.9.0"
+    version: "^8.7.1"
 screenshots:
   - src: /img/screenshot1.png
     title: "Dashboard: OpenCTI Overview"

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Related issues

Screenshots

Please see the screenshots in the integration.

@chrisberkhout chrisberkhout added the enhancement New feature or request label Aug 14, 2023
@elasticmachine

elasticmachine commented Aug 14, 2023

Copy link
Copy Markdown

💔 Build Failed

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: 2023-10-12T14:52:14.782+0000

  • Duration: 115 min 43 sec

Test stats 🧪

Test Results
Failed 0
Passed 5027
Skipped 6
Total 5033

Steps errors 2

Expand to view the steps failures

Test integration: aws
  • Took 3 min 33 sec . View more details here
  • Description: eval "$(../../build/elastic-package stack shellinit)" ../../build/elastic-package test -v --report-format xUnit --report-output file --test-coverage
Google Storage Download
  • Took 0 min 0 sec . View more details here

🤖 GitHub comments

Expand to view the GitHub comments

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

  • /test : Re-trigger the build.

@chrisberkhout chrisberkhout added the New Integration Issue or pull request for creating a new integration package. label Aug 15, 2023
@ebeahan
ebeahan requested a review from a team August 22, 2023 14:21
@marc-gr marc-gr self-assigned this Aug 22, 2023
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/input.yml.hbs Outdated
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/input.yml.hbs Outdated
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/input.yml.hbs Outdated
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/input.yml.hbs Outdated
@elasticmachine

elasticmachine commented Aug 23, 2023

Copy link
Copy Markdown

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (464/464) 💚
Files 96.126% (794/826) 👎 -3.874
Classes 96.126% (794/826) 👎 -3.874
Methods 92.455% (7695/8323) 👎 -7.545
Lines 88.365% (175204/198274) 👎 -7.158
Conditionals 100.0% (0/0) 💚
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs Outdated

@ebeahan ebeahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work! I added some nits as a scanned your progress so far.

For the list of remaining items under To Do, let's talk to @jamiehynds if there are items/features we can descope in this initial version. For example, maybe we don't need to support additional auth methods, likemTLS certificate and OAuth2, up front.

Comment thread packages/ti_opencti/LICENSE.txt Outdated
Comment thread packages/ti_opencti/img/sample-screenshot.png Outdated
Comment thread packages/ti_opencti/img/sample-logo.svg Outdated
Comment thread packages/ti_opencti/manifest.yml Outdated
Comment thread packages/ti_opencti/manifest.yml Outdated
Comment thread packages/ti_opencti/data_stream/indicator/manifest.yml Outdated
Comment thread packages/ti_opencti/changelog.yml Outdated
@chrisberkhout

Copy link
Copy Markdown
Contributor Author

/test

@chrisberkhout

Copy link
Copy Markdown
Contributor Author

/test

@chrisberkhout
chrisberkhout marked this pull request as ready for review October 2, 2023 09:15
@chrisberkhout
chrisberkhout requested a review from a team as a code owner October 2, 2023 09:15
@elasticmachine

Copy link
Copy Markdown

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

Comment thread packages/ti_opencti/_dev/build/build.yml Outdated
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs Outdated
Comment thread packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs Outdated
Comment thread packages/ti_opencti/data_stream/indicator/fields/ecs.yml Outdated
Comment thread packages/ti_opencti/data_stream/indicator/fields/opencti.yml Outdated
@efd6

efd6 commented Oct 3, 2023

Copy link
Copy Markdown
Contributor

@jsoriano I suspect the "run all the things" testing here is because of the change to links_table.yml. This is a similar situation to what I saw when I changed the pr template. Should we be doing a full test of all packages when this file changes? (I can see that we should do a check to make sure the change has not broken any generated docs).

@jsoriano

jsoriano commented Oct 3, 2023

Copy link
Copy Markdown
Contributor

Should we be doing a full test of all packages when this file changes? (I can see that we should do a check to make sure the change has not broken any generated docs).

Yes, it looks like a check would be enough, or we could try to make the pipeline smarter and detect what packages are using each link. Could you please open an issue to improve the situation? Though this file doesn't change frequently.

@jsoriano jsoriano 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.

Change in CODEOWNERS and links table looks good to me.

@efd6

efd6 commented Oct 8, 2023

Copy link
Copy Markdown
Contributor

The test failure here is unrelated; due to sql_input. This is being tested because of the change in the links_table.yml file. This is #8077.

@taylor-swanson taylor-swanson 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.

Just a couple of typos to fix, but otherwise LGTM

Comment thread packages/ti_opencti/_dev/build/docs/README.md Outdated
Comment thread packages/ti_opencti/_dev/build/docs/README.md Outdated
Comment thread packages/ti_opencti/data_stream/indicator/fields/opencti.yml Outdated
@ebeahan

ebeahan commented Oct 16, 2023

Copy link
Copy Markdown
Member

@chrisberkhout anything else you need here or is this ready to merge and release?

@chrisberkhout

Copy link
Copy Markdown
Contributor Author

@ebeahan All feedback addressed and tests for this integration are passing. I think this is good to go.

It looks like I can't override and merge without tests passing, but if someone else can that would be good.

@ebeahan
ebeahan merged commit 96d2416 into elastic:main Oct 16, 2023
@elasticmachine

Copy link
Copy Markdown

Package ti_opencti - 0.1.0 containing this change is available at https://epr.elastic.co/search?package=ti_opencti

@chrisberkhout
chrisberkhout deleted the ti_opencti branch October 17, 2023 09:11
@colin-stubbs

Copy link
Copy Markdown
Contributor

a pleasant surprise to see this pop up, nice work @chrisberkhout !

orestisfl pushed a commit to orestisfl/integrations that referenced this pull request May 15, 2026
* Initial commit of ti_opencti.

* Fix cel program, add sys test, show vars.

* Note about CEL encode_json() workaround.

* Update graphql query.

* Add some initial field config.

* Older start to ingest pipeline.

* Basic ingest pipeline.

* A working pipeline.

* Basic mappings done, for indicator and observables and each observable type.

* Delete obsolete system test data.

* Update CODEOWNERS.

* Add responses for system test.

* Add pipeline tests.

* Fixes to make tests run without error.

* Rename pipeline test files to have test- prefix.

* Rename input.yml.hbs to cel.yml.hbs.

* Tidy whitespace.

* Move state section with GraphQL query to the end.

* Switch to dynamic ECS mappings.

* Override expected values for some ECS fields, so validation passes during system tests.

* Remove not necessary and not allowed expected_values fields.

* Match threat.indicator.confidence value to ECS expectations (Med->Medium).

* Remove LICENSE.txt, to fall back to the default at the repo root.

* Replace placeholder logo with OpenCTI logo.

* Correct ecs.version field value.

* Add a link to the GraphQL schema.

* Remove commented-out fields from GraphQL query.

* Update pipeline tests expected results for correct ecs.version.

* For ECS, remove any subnet mask from IP values arriving in CIDR notation.

* Add descriptions for opencti fields.

* Update package manifest format version.

* Fill out draft PR number in changelog.

* Expanded GraphQL API info comment.

* Update field types for opencti fields.

* Move additional hash fields to ECS file since they're nested under the ECS threat fields.

* Fix related.hash to be one array, not separated out by hash algorithm.

* Move opencti.* field definitions to their own file.

* Tolerate URLs that can't be parsed. e.g. '127.0.0.1:8080/path/'.

* Extract file extensions from file names.

* Don't extract a drive_letter or directory from a directory path.

* Revert "Replace placeholder logo with OpenCTI logo."

This reverts commit 7e27677d4b6ecb43601fe1ed0c7dec0b71baac06.

* Replace placeholder logo with OpenCTI logo (this time as an SVG).

* Remove config variable preserve_duplicate_custom_fields.

* Update some fields.

* Combine and test kill chain fields.

* Merge opencti.observable.process.startup_info into one object, index as flattened.

* Clean up createdBy after renaming the fields it contains.

* Don't keep description if it's empty or null.

* Clean up related.* lists properly.

* Set threat.indicator.reference using _conf.url.

* Clean up temporary variable usage: put them at the root with a _tmp prefix.

* Tidy.

* Handle preserve_original_event in the CEL expression.

* Fix tags in pipeline tests.

* Rename placeholder screenshot.

* Tidy up manifest.yml files, options and option handling.

* Remove the workout for CEL's encode_json() on nested data, since the fix is in 8.9.0.

* Improve CEL program.

* Fix formatting.

* Fix mix up of handlebars vs CEL variables.

* Bring back the CEL encode_json() workaround.

* Remove the CEL encode_json() workaround.

* Remove handlebars template logic from CEL expression.

* Include generated sample event.

* README.

* Set the threat.indicator.url.full field.

* Allow Kibana 8.9.0 (also 8.9.0 is the minimum beats for CEL encode_json() fix).

* Add pipeline step to set ecs-indicator-detail tag.

* Set value for threat.feed.dashboard_id.

* Bring back expected_values overrides for threat.indicator.{name,type}, since they're now needed.

* Add dashboards.

* Add screenshots (wide versions).

* Screenshots - narrow versions.

* Screenshot of the "Add Integration" page on Fleet added.

* New expected_values workaround.

* README: ECS fields doc.

* Map created to event.created and leave @timestamp to receive its default value.

* Clean up timestamp documentation.

* Update dashboards to use logs-* and bring back controls.

* Improve URL for linking to OpenCTI documentation.

* README: Additional info about data models and approach to mapping.

* Populate threat.indicator.url.* fields for domain-name and hostname indicator types.

* Mark as secret the vars for api_key, oauth2 and ssl.

* Version bump.

* Update package manifest.yml to format_version 3.0.0.

* Ignore error 'expected filter in dashboard: no filter found', since it conflicts with the 'SEI Integration Dashboard styling guide' recommendation 'Only use filters on visualizations panels, not dashboards'.

* Avoid failing pipeline benchmarks due to missing _conf.url field.

* Revert "Mark as secret the vars for api_key, oauth2 and ssl."

This reverts commit 9a90cdaa084c15cf54a81c29e08a5c02954220ea.

* ECS 8.10

* Relocate redact config.

* Use triple curly brackets to access field values in template snippets.

* Single-quote string to avoid escaping.

* Improved failure handler.

* Don't keep empty hash fields.

* Remove unused ad-hoc data views from dashboards.

* Switch opencti field definitions to be nested rather than flattened.

* Fix field type for hash group.

* Do clean up observable fieldsets and observable itself at the end of observable processing.

* Comment on which validation is excluded.

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

Labels

enhancement New feature or request Integration:ti_opencti OpenCTI New Integration Issue or pull request for creating a new integration package.

10 participants