-
Notifications
You must be signed in to change notification settings - Fork 624
feat(metras): add Metras internal-enrichment connector for fleet-presence lookups (#7042) #7040
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
Open
Khidr6G
wants to merge
8
commits into
OpenCTI-Platform:master
Choose a base branch
from
Khidr6G:feature/metras-internal-enrichment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
827a815
feat(metras): add Metras internal-enrichment connector for fleet-pres…
Khidr6G 32cb0c6
fix(metras): none-safe refang/joins, fail-loud client, converter test…
Khidr6G a2d8c91
fix(metras): set manifest source_code, add file-enrichment test (#7042)
Khidr6G d88a331
fix(metras): address review feedback on internal-enrichment connector…
Khidr6G bf467f2
fix(metras): add required manifest fields for updated schema (#7042)
Khidr6G b5259c8
feat(metras): apply maintainer review — rename, sdk models, manifest …
Khidr6G 311d45d
fix(metras): pin pycti to 7.260728.0 to match connectors-sdk master (…
Khidr6G c96343d
fix(metras): make enrichment playbook-compatible — return original bu…
Khidr6G 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| __metadata__ | ||
| **/__pycache__ | ||
| **/__docs__ | ||
| **/.venv | ||
| **/venv | ||
| **/logs | ||
| **/config.yml | ||
| **/*.egg-info | ||
| **/*.gql | ||
| .plan | ||
| tests |
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM python:3.12-alpine | ||
|
|
||
| ENV CONNECTOR_TYPE=INTERNAL_ENRICHMENT | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| COPY src /opt/opencti-connector-metras-enrichment | ||
|
|
||
| RUN apk update && apk upgrade --no-cache && \ | ||
| apk --no-cache add libmagic libffi libxml2 libxslt && \ | ||
| apk --no-cache add --virtual .build-deps git build-base libffi-dev libxml2-dev libxslt-dev && \ | ||
| cd /opt/opencti-connector-metras-enrichment && \ | ||
| pip3 install --no-cache-dir -r requirements.txt && \ | ||
| apk del .build-deps | ||
|
|
||
| COPY entrypoint.sh / | ||
| RUN chmod +x /entrypoint.sh && \ | ||
| adduser -D -u 1000 connector && \ | ||
| chown -R connector:connector /opt/opencti-connector-metras-enrichment | ||
| USER connector | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] |
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # OpenCTI Metras Enrichment Connector (INTERNAL_ENRICHMENT) | ||
|
|
||
| Answers *"have I seen this in my fleet?"* by querying the [Metras](https://dashboard.metras.sa/) | ||
| platform when you enrich an observable in OpenCTI. Adds a context **Note** (and | ||
| **System identity** links to matched fleet endpoints) summarising local EDR/endpoint presence. | ||
|
|
||
| ## Supported observables (`CONNECTOR_SCOPE`) | ||
|
|
||
| | Observable | Metras lookups | Output | | ||
| |---|---|---| | ||
| | **IPv4-Addr** | `/v1/edr/alerts?agent_ip=`, `/v1/endpoints?interface_ip=` | Note (alert + endpoint hits) + `related-to` **System identity** per matched endpoint | | ||
| | **StixFile** | `/v1/edr/binary/list?query=sha256:` / `?query=sha1:`, `/v1/edr/binary/details?md5=` | Note (publisher, signer, signature/runnability status, first/last seen) + System identity | | ||
|
|
||
| > Matched fleet endpoints are emitted as `Identity(identity_class="system")` (internal assets, | ||
| > not IOCs), consistent with the Feed connector and OpenCTI maintainer guidance (PR #6164). | ||
|
|
||
| > **Why only IPv4 + StixFile?** Metras exposes no value-lookup for domains or URLs, and | ||
| > `/v4/threats/detail` requires incident identifiers (title+direction+type), not an observable | ||
| > value. Domain/URL enrichment is therefore not offered. | ||
| > | ||
| > Fleet presence is conveyed via **Notes + relationships**, not STIX Sightings (the `stix2` | ||
| > library forbids a Sighting referencing an observable). | ||
|
|
||
| ## Behavior & safety | ||
| - **Custom TLP check** (not `helper.check_max_tlp`) — skips observables above `METRAS_MAX_TLP`. | ||
| - **Refangs** values before querying Metras. | ||
| - **Partial results**: each lookup is wrapped; if at least one succeeds, results are sent. | ||
| If *all* lookups fail, a `ValueError` is raised so the failure is visible in the OpenCTI UI. | ||
| - Playbook-compatible (`playbook_compatible=True`, `entity_in_scope()` guard). | ||
|
|
||
| ## Requirements | ||
| - OpenCTI **7.260529.0** (`pycti==7.260529.0`). A Metras API key. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Env var | Required | Default | Description | | ||
| |---|---|---|---| | ||
| | `OPENCTI_URL` / `OPENCTI_TOKEN` / `CONNECTOR_ID` | yes | — | Standard connector settings | | ||
| | `CONNECTOR_NAME` | no | `Metras-Enrichment` | Connector name | | ||
| | `CONNECTOR_SCOPE` | no | `IPv4-Addr,StixFile` | Observable types to enrich | | ||
| | `CONNECTOR_AUTO` | no | `false` | Auto-enrich on observable creation | | ||
| | `CONNECTOR_LOG_LEVEL` | no | `info` | Log level | | ||
| | `METRAS_API_BASE_URL` | no | `https://api.metras.sa/api` | Metras API base URL | | ||
| | `METRAS_API_KEY` | yes | — | Metras API key | | ||
| | `METRAS_VERIFY_SSL` | no | `true` | Verify TLS certificates | | ||
| | `METRAS_MAX_TLP` | no | `amber+strict` | Max TLP to enrich (`clear`/`white`/`green`/`amber`/`amber+strict`/`red`) | | ||
|
|
||
| ## Usage | ||
| Right-click an IPv4 or file-hash observable → **Enrich** → *Metras-Enrichment*, or set | ||
| `CONNECTOR_AUTO=true` to enrich automatically. Triggering via API uses | ||
| `stixCoreObjectEdit.askEnrichment(connectorId)` on OpenCTI 7.260529.0+. | ||
|
|
||
| ## Troubleshooting | ||
| | Symptom | Cause / fix | | ||
| |---|---| | ||
| | "No Metras fleet data found" | The observable isn't present in your Metras fleet (expected for unknown IOCs) | | ||
| | Enrichment fails with auth error | Bad `METRAS_API_KEY` | | ||
| | File observable not enriched | Ensure `StixFile` is in `CONNECTOR_SCOPE` | | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.0.0 |
19 changes: 19 additions & 0 deletions
19
internal-enrichment/metras/__metadata__/connector_manifest.json
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "title": "Metras Enrichment Connector", | ||
| "slug": "metras-enrichment", | ||
| "description": "Enriches IPv4 and file-hash observables by querying Metras for fleet presence (EDR alerts, endpoint inventory, binary inventory), returning context Notes and system-identity links ('have I seen this in my environment?').", | ||
| "short_description": "Enrichment connector for Metras fleet sightings", | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
||
| "logo": null, | ||
| "use_cases": ["Enrichment & Analysis"], | ||
| "verified": false, | ||
| "last_verified_date": null, | ||
| "playbook_supported": true, | ||
| "max_confidence_level": 50, | ||
| "support_version": ">=7.260529.0", | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
||
| "subscription_link": null, | ||
| "source_code": null, | ||
| "manager_supported": false, | ||
| "container_version": "1.0.0", | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
||
| "container_image": "opencti/connector-metras-enrichment", | ||
| "container_type": "INTERNAL_ENRICHMENT" | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| opencti: | ||
| url: 'http://localhost:8080' | ||
| token: 'ChangeMe' | ||
|
|
||
| connector: | ||
| type: 'INTERNAL_ENRICHMENT' | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
||
| id: 'ChangeMe' # UUIDv4 | ||
| name: 'Metras-Enrichment' | ||
| scope: 'IPv4-Addr,StixFile' | ||
| log_level: 'info' | ||
| auto: false | ||
|
|
||
| metras: | ||
| api_base_url: 'https://api.metras.sa/api' | ||
| api_key: 'ChangeMe' | ||
| verify_ssl: true | ||
| max_tlp: 'amber+strict' | ||
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| services: | ||
| connector-metras-enrichment: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
|
Khidr6G marked this conversation as resolved.
Outdated
|
||
| image: opencti/connector-metras-enrichment:1.0.0 | ||
| environment: | ||
| - OPENCTI_URL=http://opencti:8080 | ||
| - OPENCTI_TOKEN=${OPENCTI_ADMIN_TOKEN} | ||
| - CONNECTOR_ID=${CONNECTOR_METRAS_ENRICHMENT_ID} | ||
| - CONNECTOR_TYPE=INTERNAL_ENRICHMENT | ||
|
Member
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. Never configurable, always hardcoded - should de removed |
||
| - CONNECTOR_NAME=Metras-Enrichment | ||
| - CONNECTOR_SCOPE=IPv4-Addr,StixFile | ||
| - CONNECTOR_LOG_LEVEL=info | ||
| - CONNECTOR_AUTO=false | ||
| - METRAS_API_BASE_URL=https://api.metras.sa/api | ||
| - METRAS_API_KEY=${METRAS_API_KEY} | ||
| - METRAS_VERIFY_SSL=true | ||
| - METRAS_MAX_TLP=amber+strict | ||
| restart: always | ||
| cap_drop: | ||
| - ALL | ||
| security_opt: | ||
| - no-new-privileges:true | ||
| read_only: true | ||
| tmpfs: | ||
| - /tmp | ||
| mem_limit: 512m | ||
| pids_limit: 100 | ||
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
| cd /opt/opencti-connector-metras-enrichment | ||
| exec python3 main.py |
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [tool.coverage.run] | ||
| source = ["connector", "metras_client"] | ||
|
|
||
| [tool.coverage.report] | ||
| show_missing = true |
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from connector.connector import MetrasEnrichmentConnector | ||
| from connector.settings import ConnectorSettings | ||
|
|
||
| __all__ = ["MetrasEnrichmentConnector", "ConnectorSettings"] |
Oops, something went wrong.
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.