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

Private Upload Mode - ThreatExchange v2 #28249

Merged
merged 23 commits into from Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4003b6e
ThreatExchange integration
darkushin Jul 18, 2023
900b4ca
ThreatExchange updates
darkushin Jul 18, 2023
7335666
Merge branch 'master' of github.com:demisto/content into private_uplo…
darkushin Jul 25, 2023
32c6c97
Merge branch 'master' of github.com:demisto/content into private_uplo…
darkushin Aug 10, 2023
98f7d66
Merge branch 'master' of github.com:demisto/content into private_uplo…
darkushin Aug 13, 2023
65ef1a1
Added param to instance configuration
darkushin Aug 13, 2023
7057d03
pre-commit
darkushin Aug 13, 2023
5556709
updated RN
darkushin Aug 13, 2023
4e3e65d
Merge branch 'master' into private_upload_mode_untested_integrations
darkushin Aug 14, 2023
0c0c572
Merge branch 'master' of github.com:demisto/content into private_uplo…
darkushin Aug 14, 2023
dde4060
RN test
darkushin Aug 14, 2023
935e4ca
CR updates
darkushin Aug 14, 2023
761598e
Removed Threat_Crowd
darkushin Aug 14, 2023
5b749e6
Update Packs/ThreatExchange/ReleaseNotes/2_0_12.md
darkushin Aug 14, 2023
ba3b329
Merge branch 'master' into private_upload_mode_untested_integrations
darkushin Aug 14, 2023
6d53e11
Merge branch 'master' into private_upload_mode_untested_integrations
RosenbergYehuda Sep 20, 2023
301196a
docker
RosenbergYehuda Sep 20, 2023
34f84a1
format
RosenbergYehuda Sep 20, 2023
2d18304
Merge remote-tracking branch 'origin' into private_upload_mode_untest…
RosenbergYehuda Sep 20, 2023
2970dea
skip tests since theres no instance
RosenbergYehuda Sep 20, 2023
d0ca951
Merge remote-tracking branch 'origin' into private_upload_mode_untest…
RosenbergYehuda Sep 20, 2023
b65edb9
no testing instance
RosenbergYehuda Sep 21, 2023
1253be9
Merge remote-tracking branch 'origin' into private_upload_mode_untest…
RosenbergYehuda Sep 21, 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
20 changes: 11 additions & 9 deletions Packs/ThreatExchange/Integrations/ThreatExchangeV2/README.md
Expand Up @@ -21,10 +21,11 @@ For Cortex XSOAR versions 6.0 and below, the App Secret should be set in the *pa
3. Click **Add instance** to create and configure a new integration instance.

| **Parameter** | **Description** | **Required** |
| --- | --- | --- |
| --- | -- | --- |
| App ID | | True |
| App Secret | | True |
| Source Reliability | Reliability of the source providing the intelligence data | True |
| Share Level Type | A designation of how the indicator may be shared based on the US-CERT's Traffic Light Protocol | False |
| Use system proxy settings | | False |
| Trust any certificate (not secure) | | False |
| Malicious Threshold | If the percentage of 'Malicious' reported statuses is above this threshold the indicator will be defined as malicious, otherwise suspicious. | False |
Expand Down Expand Up @@ -284,13 +285,14 @@ Checks URL Reputation
`url`
#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| url | URL to be checked. | Required |
| limit | The maximum number of results per page. The maximum is 1000. Default is 20. | Optional |
| headers | A comma-separated list of headers to display in human-readable format. For example: header1,header2,header3. | Optional |
| since | The start timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |
| until | The end timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |
| **Argument Name** | **Description** | **Required** |
darkushin marked this conversation as resolved.
Show resolved Hide resolved
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --- |
| url | URL to be checked. | Required |
| limit | The maximum number of results per page. The maximum is 1000. Default is 20. | Optional |
| headers | A comma-separated list of headers to display in human-readable format. For example: header1,header2,header3. | Optional |
| since | The start timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |
| until | The end timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |
| share_level | A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol. Default is RED. | Optional |


#### Context Output
Expand Down Expand Up @@ -421,7 +423,7 @@ Checks domain reputation.
| headers | A comma-separated list of headers to display in human-readable format. For example: header1,header2,header3. | Optional |
| since | The start timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |
| until | The end timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago). | Optional |

| share_level | A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol. Default is RED. | Optional |

#### Context Output

Expand Down
Expand Up @@ -5,7 +5,6 @@
"""

import collections
from typing import Tuple
import urllib3
from CommonServerUserPython import * # noqa
from CommonServerPython import * # noqa # pylint: disable=unused-wildcard-import
Expand Down Expand Up @@ -102,7 +101,7 @@ def file(self, file: str, since: Optional[int], until: Optional[int], limit: Opt
)
return response

def domain(self, domain: str, since: Optional[int], until: Optional[int],
def domain(self, domain: str, since: Optional[int], until: Optional[int], share_level: str,
limit: Optional[int] = DEFAULT_LIMIT) -> Dict:
"""
See Also:
Expand All @@ -111,6 +110,7 @@ def domain(self, domain: str, since: Optional[int], until: Optional[int],
domain: Domain
since: Returns malware collected after a timestamp
until: Returns malware collected before a timestamp
share_level: A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol.
limit: Defines the maximum size of a page of results. The maximum is 1,000

Returns: The API call response
Expand All @@ -126,19 +126,22 @@ def domain(self, domain: str, since: Optional[int], until: Optional[int],
'strict_text': True,
'since': since,
'until': until,
'limit': limit
'limit': limit,
'share_level': share_level
})
)
return response

def url(self, url: str, since: Optional[int], until: Optional[int], limit: Optional[int] = DEFAULT_LIMIT) -> Dict:
def url(self, url: str, since: Optional[int], until: Optional[int], share_level: str,
limit: Optional[int] = DEFAULT_LIMIT) -> Dict:
"""
See Also:
https://developers.facebook.com/docs/threat-exchange/reference/apis/threat-descriptors
Args:
url: URL
since: Returns malware collected after a timestamp
until: Returns malware collected before a timestamp
share_level: A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol.
limit: Defines the maximum size of a page of results. The maximum is 1,000

Returns: The API call response
Expand All @@ -154,7 +157,8 @@ def url(self, url: str, since: Optional[int], until: Optional[int], limit: Optio
'strict_text': True,
'since': since,
'until': until,
'limit': limit
'limit': limit,
'share_level': share_level
})
)
return response
Expand Down Expand Up @@ -348,7 +352,7 @@ def calculate_dbot_score(reputation_data: List, params: Dict[str, Any]) -> int:
return score


def calculate_engines(reputation_data: List) -> Tuple[int, int]:
def calculate_engines(reputation_data: List) -> tuple[int, int]:
"""
Calculates the number of engines that scanned the indicator, and how many of them are positive
- i.e returned malicious status.
Expand Down Expand Up @@ -431,7 +435,7 @@ def convert_string_to_epoch_time(date: Optional[str], arg_name: Optional[str] =
return int(epoch_time)
else: # date was given in a wrong format
if arg_name:
raise ValueError('Invalid date: "{}"="{}"'.format(arg_name, date))
raise ValueError(f'Invalid date: "{arg_name}"="{date}"')

return None

Expand Down Expand Up @@ -464,7 +468,7 @@ def ip_command(client: Client, args: Dict[str, Any], params: Dict[str, Any]) ->
limit = arg_to_number(args.get('limit'), arg_name='limit')
headers = argToList(args.get('headers'))
reliability = params.get('feedReliability')
results: List[CommandResults] = list()
results: List[CommandResults] = []

for ip in ips:
if not is_ip_valid(ip, accept_v6_ips=True): # check IP's validity
Expand Down Expand Up @@ -536,7 +540,7 @@ def file_command(client: Client, args: Dict[str, Any], params: Dict[str, Any]) -
limit = arg_to_number(args.get('limit'), arg_name='limit')
headers = argToList(args.get('headers'))
reliability = params.get('feedReliability')
results: List[CommandResults] = list()
results: List[CommandResults] = []

for file in files:
if get_hash_type(file) not in ('sha256', 'sha1', 'md5'): # check file's validity
Expand Down Expand Up @@ -612,16 +616,26 @@ def domain_command(client: Client, args: Dict[str, Any], params: Dict[str, Any])
limit = arg_to_number(args.get('limit'), arg_name='limit')
headers = argToList(args.get('headers'))
reliability = params.get('feedReliability')
results: List[CommandResults] = list()
share_level = args.get('share_level', params.get('share_level', 'RED'))
demisto.debug(f'Setting share level to {share_level}')
results: List[CommandResults] = []

for domain in domains:
try:
raw_response = client.domain(domain, since, until, limit)
raw_response = client.domain(domain, since, until, share_level, limit)
except Exception as exception:
# If anything happens, handle like there are no results
err_msg = f'Could not process domain: "{domain}"\n {str(exception)}'
demisto.debug(err_msg)
raw_response = {}
readable_output = f'Processing domain "{domain}" resulted in an exception. See logs for the exact error.'
result = CommandResults(
outputs={},
readable_output=readable_output,
raw_response=raw_response
)
results.append(result)
continue
if data := raw_response.get('data'):
score = calculate_dbot_score(reputation_data=data, params=params)
num_of_engines, num_of_positive_engines = calculate_engines(reputation_data=data)
Expand Down Expand Up @@ -681,15 +695,25 @@ def url_command(client: Client, args: Dict[str, Any], params: Dict[str, Any]) ->
limit = arg_to_number(args.get('limit'), arg_name='limit')
headers = argToList(args.get('headers'))
reliability = params.get('feedReliability')
results: List[CommandResults] = list()
share_level = args.get('share_level', params.get('share_level', 'RED'))
demisto.debug(f'Setting share level to {share_level}')
results: List[CommandResults] = []
for url in urls:
try:
raw_response = client.url(url, since, until, limit)
raw_response = client.url(url, since, until, share_level, limit)
except Exception as exception:
# If anything happens, handle like there are no results
err_msg = f'Could not process URL: "{url}"\n {str(exception)}'
demisto.debug(err_msg)
raw_response = {}
readable_output = f'Processing URL "{url}" resulted in an exception. See logs for the exact error.'
result = CommandResults(
outputs={},
readable_output=readable_output,
raw_response=raw_response
)
results.append(result)
continue
if data := raw_response.get('data'):
score = calculate_dbot_score(reputation_data=data, params=params)
num_of_engines, num_of_positive_engines = calculate_engines(reputation_data=data)
Expand Down
Expand Up @@ -38,6 +38,17 @@ configuration:
- F - Reliability cannot be judged
required: true
type: 15
- defaultvalue: 'RED'
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we get this param in the main func?

display: Share Level Type
name: share_level
type: 15
required: false
additionalinfo: A designation of how the indicator may be shared based on the US-CERT's Traffic Light Protocol.
options:
- RED
- AMBER
- GREEN
- WHITE
- defaultvalue: 'false'
display: Use system proxy settings
name: proxy
Expand Down Expand Up @@ -263,6 +274,14 @@ script:
name: since
- description: 'The end timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago).'
name: until
- auto: PREDEFINED
description: A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol.
name: share_level
predefined:
- RED
- AMBER
- GREEN
- WHITE
description: Checks the URL reputation.
name: url
outputs:
Expand Down Expand Up @@ -359,6 +378,14 @@ script:
name: since
- description: 'The end timestamp for collecting malware. Supported time formats: epoch time (e.g., 1619870400), ISO 8601 (e.g., 2021-05-01T12:00:00), and free text (e.g., 24 hours ago).'
name: until
- auto: PREDEFINED
description: A designation of how the indicator may be shared, based on the US-CERT's Traffic Light Protocol.
name: share_level
predefined:
- RED
- AMBER
- GREEN
- WHITE
description: Checks a domain reputation.
name: domain
outputs:
Expand Down Expand Up @@ -659,7 +686,7 @@ script:
- contextPath: ThreatExchange.Object.id
description: ID of a ThreatExchange object.
type: String
dockerimage: demisto/python3:3.10.12.63474
dockerimage: demisto/python3:3.10.12.68714
runonce: false
script: '-'
subtype: python3
Expand Down
8 changes: 8 additions & 0 deletions Packs/ThreatExchange/ReleaseNotes/2_0_12.md
@@ -0,0 +1,8 @@

#### Integrations

##### ThreatExchange v2

darkushin marked this conversation as resolved.
Show resolved Hide resolved
- Added support for the *share_level* argument in the ***!url*** and ***!domain*** commands.
- Added support for the *Share Level Type* parameter to the instance configuration.
darkushin marked this conversation as resolved.
Show resolved Hide resolved
- Updated the Docker image to: *demisto/python3:3.10.12.68714*.
2 changes: 1 addition & 1 deletion Packs/ThreatExchange/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "ThreatExchange",
"description": "Receive threat intelligence about applications, IP addresses, URLs and hashes, a service by Facebook",
"support": "xsoar",
"currentVersion": "2.0.11",
"currentVersion": "2.0.12",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down