-
Notifications
You must be signed in to change notification settings - Fork 620
feat(google-ti-feeds): add malware/threat actor filter (#7024) #7090
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
throuxel
wants to merge
1
commit into
master
Choose a base branch
from
feat/7024-gti-association-filters
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 all commits
Commits
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 |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| OPENCTI_URL='http://localhost:PORT' | ||
| OPENCTI_TOKEN='ChangeMe' | ||
| CONNECTOR_ID='ChangeMe' | ||
| GTI_API_KEY='ChangeMe' | ||
|
|
||
| # GTI_IMPORT_INDICATORS=false | ||
| # GTI_INDICATOR_TYPES=file,ip,url,domain | ||
| # GTI_INDICATOR_IMPORT_START_DATE=PT1H | ||
| # GTI_INDICATOR_MIN_SCORE=50 | ||
| # GTI_INDICATOR_REQUIRE_MALWARE_FAMILY=false | ||
| # GTI_INDICATOR_REQUIRE_THREAT_ACTOR=false | ||
|
|
||
| # GTI_IMPORT_SOFTWARE_TOOLKITS=false | ||
| # GTI_SOFTWARE_TOOLKIT_IMPORT_START_DATE=P1D | ||
| # GTI_SOFTWARE_TOOLKIT_ORIGINS=google threat intelligence | ||
| # GTI_SOFTWARE_TOOLKIT_EXTRA_FILTERS= | ||
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -74,6 +74,41 @@ def _is_below_min_score(self, entry: IOCDeltaEntry) -> bool: | |
|
|
||
| return attrs.gti_assessment.threat_score.value < min_score | ||
|
|
||
| def _lacks_required_association(self, entry: IOCDeltaEntry) -> bool: | ||
| """Check whether an IOC entry lacks the required malware/threat actor associations. | ||
|
|
||
| The filter is disabled when both indicator_require_malware_family and | ||
| indicator_require_threat_actor are False (default). When one or both are | ||
| enabled, the indicator must have at least one matching association (OR | ||
| logic between the two). This filter is combined with the score filter | ||
| using AND logic. | ||
| """ | ||
| require_malware = self.config.indicator_require_malware_family | ||
| require_threat_actor = self.config.indicator_require_threat_actor | ||
|
|
||
| if not require_malware and not require_threat_actor: | ||
| return False | ||
|
|
||
| rels = entry.relationships | ||
|
|
||
| has_malware = ( | ||
| rels is not None | ||
| and rels.malware_families is not None | ||
| and len(rels.malware_families.data) > 0 | ||
| ) | ||
| has_threat_actor = ( | ||
| rels is not None | ||
| and rels.threat_actors is not None | ||
| and len(rels.threat_actors.data) > 0 | ||
| ) | ||
|
|
||
| if require_malware and not require_threat_actor: | ||
| return not has_malware | ||
| if require_threat_actor and not require_malware: | ||
| return not has_threat_actor | ||
| # Both required: OR logic — at least one must be present | ||
| return not (has_malware or has_threat_actor) | ||
|
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. suggestion: Purely personal, but I prefer this representation of boolean using De Morgan's Law: return not has_malware and not has_threat_actor |
||
|
|
||
| def convert(self, ioc_data: dict[str, Any]) -> list[Any]: | ||
| """Convert a single IOC delta entry to STIX objects.""" | ||
| try: | ||
|
|
@@ -97,6 +132,17 @@ def convert(self, ioc_data: dict[str, Any]) -> list[Any]: | |
| ) | ||
| return [] | ||
|
|
||
| if self._lacks_required_association(entry): | ||
| self.logger.debug( | ||
| "IOC entry lacks required malware/threat actor association, skipping", | ||
| { | ||
| "prefix": LOG_PREFIX, | ||
| "type": entry.type, | ||
| "id": entry.id, | ||
| }, | ||
| ) | ||
|
throuxel marked this conversation as resolved.
|
||
| return [] | ||
|
|
||
| try: | ||
| self.logger.debug( | ||
| "Converting IOC delta entry to STIX", | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Maybe it could be easier to read if this method is checking the lack of association but the opposite, the presence of association: