Skip to content
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

Added context output and indicator tagging to CreateIndicatorsFromStix #31140

Merged
merged 36 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
db1fcb8
Added context output and tagging to CreateIndicatorsFromSTIX.py
mohlcyber Nov 27, 2023
871eff6
Removed Spaces in CommandResults
mohlcyber Nov 27, 2023
b103f8d
Added Release Note
mohlcyber Nov 27, 2023
d17424c
Merge branch 'contrib/mohlcyber_contrib-mohlcyber-CreateIndicatorsFro…
mohlcyber Nov 27, 2023
e6a3024
Merge pull request #1 from demisto/master
mohlcyber Dec 7, 2023
c448a86
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
mohlcyber Dec 7, 2023
b80d81c
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
mohlcyber Dec 7, 2023
c8c21b8
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
mohlcyber Dec 7, 2023
68919eb
Update Packs/CommonScripts/ReleaseNotes/1_12_50.md
mohlcyber Dec 7, 2023
e6f9a01
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
mohlcyber Dec 7, 2023
5145f4a
fixes in CreateIndicatorsFromSTIX.py
mohlcyber Dec 7, 2023
5f3b296
Merge with Master and bumped up CommonScripts Version
mohlcyber Dec 7, 2023
4652699
Updated YML
mohlcyber Dec 7, 2023
e24f061
Updated CreateIndicatorsFromSTIX_test.py
mohlcyber Dec 7, 2023
f7c0de6
Updated CreateIndicatorsFromSTIX_test.py
mohlcyber Dec 7, 2023
41c8cc6
Updated Docker Image Version
mohlcyber Dec 7, 2023
d774642
Updated Release notes to align with docker version
mohlcyber Dec 7, 2023
6b1434b
Added Tags to context output.
mohlcyber Dec 14, 2023
f590192
Added outputs to CreateIndicatorsFromSTIX.yml
mohlcyber Dec 14, 2023
e98ba0e
Bumped up Docker Image version in Release Note and YML
mohlcyber Dec 14, 2023
7799b66
Merge pull request #2 from demisto/master
mohlcyber Dec 14, 2023
25346ea
Merge branch 'master' into contrib-mohlcyber-CreateIndicatorsFromSTIX
mohlcyber Dec 14, 2023
8255188
Adjusted Version
mohlcyber Dec 14, 2023
51cb9a5
Updated README.md
mohlcyber Dec 14, 2023
0e5df38
Updated CreateIndicatorsFromSTIX.yml with description periods.
mohlcyber Dec 14, 2023
d7ae812
Added CONTRIBUTORS.json
mohlcyber Dec 14, 2023
17bf4c5
Deleted CONTRIBUTORS.json
mohlcyber Dec 14, 2023
9f79f79
Update 1_13_5.md
adi88d Dec 14, 2023
8c11198
Update CreateIndicatorsFromSTIX.yml
adi88d Dec 14, 2023
474118c
Update README.md
adi88d Dec 14, 2023
8fc9b8f
Update README.md
adi88d Dec 14, 2023
ecf96ae
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
adi88d Dec 14, 2023
9f06a04
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
adi88d Dec 14, 2023
b131030
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/CreateInd…
adi88d Dec 14, 2023
16835bb
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/README.md
adi88d Dec 14, 2023
231d145
Update Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/README.md
adi88d Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_13_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#### Scripts

##### CreateIndicatorsFromSTIX

- Added the *add_context* and * tags* arguments for context output.
- Updated the Docker image to: *demisto/python3:3.10.13.83255*.
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,61 @@ def create_relationships_from_entity(indicator_relationships):
return entity_relationships


def create_indicators_loop(indicators):
def create_indicators_loop(args, indicators):
""" Create indicators using createNewIndicator automation

:param indicators: parsed indicators
:return: errors if exist
"""
relationships_objects = list()
errors = list()
context_data = []
mohlcyber marked this conversation as resolved.
Show resolved Hide resolved
add_context = argToBoolean(args.get('add_context', False))
tags = argToList(args.get('tags'))

for indicator in indicators:
indicator['type'] = indicator.get('indicator_type')
relationship_object = create_relationships_from_entity(indicator.get('relationships'))
if relationship_object:
relationships_objects.extend(relationship_object)

if len(tags) > 0:
if 'customFields' in indicator:
if 'tags' in indicator.get('customFields'):
[indicator['customFields']['tags'].append(ntag) for ntag in tags]

context = {'value': indicator['value'], 'type': indicator['type']}
mohlcyber marked this conversation as resolved.
Show resolved Hide resolved
if 'tags' in indicator.get('customFields'):
context['tags'] = indicator['customFields']['tags']

res = demisto.executeCommand("createNewIndicator", indicator)
context_data.append(context)

if is_error(res[0]):
errors.append(f'Error creating indicator - {(res[0]["Contents"])}')
result = CommandResults(
readable_output=f"Create Indicators From STIX: {len(indicators) - len(errors)} indicators were created.",
relationships=relationships_objects
)

if add_context:
result = CommandResults(
readable_output=f"Create Indicators From STIX: {len(indicators) - len(errors)} indicators were created.",
relationships=relationships_objects,
outputs_prefix='StixIndicators',
outputs_key_field='value',
outputs=context_data
)
else:
result = CommandResults(
readable_output=f"Create Indicators From STIX: {len(indicators) - len(errors)} indicators were created.",
relationships=relationships_objects
)

return result, errors


def main(): # pragma: no cover
args = demisto.args()
entry_id = args.get("entry_id", "")
indicators = parse_indicators_using_stix_parser(entry_id)
results, errors = create_indicators_loop(indicators)
results, errors = create_indicators_loop(args, indicators)
return_results(results)
if errors:
return_error(json.dumps(errors, indent=4))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ args:
- description: The entry ID of the STIX file.
name: entry_id
required: true
- auto: PREDEFINED
defaultValue: "false"
description: Adds indicators to context.
name: add_context
predefined:
- "true"
- "false"
- description: A comma-separated list of tags to add to indicators.
name: tags
mohlcyber marked this conversation as resolved.
Show resolved Hide resolved
outputs:
- contextPath: StixIndicators.type
description: Type of the indicator.
- contextPath: StixIndicators.value
description: Value of the indicator.
- contextPath: StixIndicators.tags
description: Tags of the indicator.
comment: Creates indicators from the submitted STIX file. Supports STIX 1.0 and STIX 2.x. This automation creates indicators and adds an indicator's relationships if available.
commonfields:
id: CreateIndicatorsFromSTIX
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
from CreateIndicatorsFromSTIX import *


def test_create_indicators_loop(mocker):
def test_create_indicators_loop_wo_args(mocker):
"""
Given:
- A collection of indicators in XSOAR Format
Expand All @@ -15,12 +12,40 @@ def test_create_indicators_loop(mocker):
Then:
- Validate the indicators extract without errors.
"""
args = {}
with open('test_data/expected_result_example3.json') as json_f:
indicators = json.load(json_f)
mocker.patch.object(demisto, 'executeCommand', return_value=[None])
results, errors = create_indicators_loop(indicators=indicators)
results, errors = create_indicators_loop(args, indicators)

assert errors == []
assert results.readable_output == 'Create Indicators From STIX: 2 indicators were created.'


def test_create_indicators_loop_w_args(mocker):
"""
Given:
- A collection of indicators in XSOAR Format

When:
- Parsing stix indicators.

Then:
- Validate the indicators extract without errors.
"""
args = {
'add_context': 'true',
'tags': 'tag1,tag2'
}

with open('test_data/expected_result_example3.json') as json_f:
indicators = json.load(json_f)
mocker.patch.object(demisto, 'executeCommand', return_value=[None])
results, errors = create_indicators_loop(args, indicators)

assert errors == []
assert results.readable_output == 'Create Indicators From STIX: 2 indicators were created.'
mohlcyber marked this conversation as resolved.
Show resolved Hide resolved
assert results.outputs[0]['tags'] == ['tag1', 'tag2']


def test_parse_indicators_using_stix_parser(mocker):
Expand Down
10 changes: 9 additions & 1 deletion Packs/CommonScripts/Scripts/CreateIndicatorsFromSTIX/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ Wrapper for the **StixParser** automation. This automation creates indicators an
| **Argument Name** | **Description** |
| --- | --- |
| entry_id | The entry ID of the STIX file. |
| add_context | Adds indicators to context. |
| tags | A comma-separated list of tags to add to indicators. |

## Outputs

---
There are no outputs for this script.

| **Path** | **Description** | **Type** |
| --- | --- | --- |
| StixIndicators.type | Type of the indicator. | String |
| StixIndicators.value | Value of the indicator. | String |
| StixIndicators.tags | Tags of the indicator. | Unknown |
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.13.4",
"currentVersion": "1.13.5",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down