FilterByList
Checks whether the specified item is in a list. The default list is the Demisto Indicators Whitelist.
python · Common Scripts
Source
import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * def empty_list_context(items, list_name): ec = {"List.In": [], "List.NotIn": items} human_readable = "The list " + list_name + " is empty" return human_readable, ec def build_filtered_data(lst, items, ignore_case, match_exact, regex_ignore_case_flag): not_white_listed = [] # type: list white_listed = [] # type: list human_readable = "" # fill whitelisted array with all the the values that match the regex items in listname argument list_to_lowercase = [list_item.lower().strip() for list_item in lst] for item in items: if match_exact: if ignore_case: if item.lower() not in list_to_lowercase: continue else: if item not in lst: continue human_readable += item + " is in the list\n" white_listed.append(item) else: for list_item in lst: if list_item and re.search(item, list_item, regex_ignore_case_flag): human_readable += item + " is in the list\n" white_listed.append(item) # fill not_white_listed array with all the the values that not in whitelisted for item in items: if item not in white_listed: human_readable += item + " is not part of the list\n" not_white_listed.append(item) return white_listed, not_white_listed, human_readable def filter_list(lst, items, ignore_case, match_exact, list_name, delimiter): # If the list is empty if not lst[0]["Contents"]: return empty_list_context(items, list_name) lst = lst[0]["Contents"].split(delimiter) regex_ignore_case_flag = re.IGNORECASE if ignore_case else 0 white_listed, not_white_listed, human_readable = build_filtered_data( lst, items, ignore_case, match_exact, regex_ignore_case_flag ) ec = {"List": {"ListName": list_name, "In": white_listed, "NotIn": not_white_listed}} return human_readable, ec def main(): args = demisto.args() list_name = args["listname"] ignore_case = args.get("ignorecase", "").lower() == "yes" match_exact = args.get("matchexact", "").lower() == "yes" items = argToList(args.get("values")) delimiter = args.get("delimiter", ",") lst = demisto.executeCommand("getList", {"listName": list_name}) if isError(lst[0]): return_error("List not found") human_readable, ec = filter_list(lst, items, ignore_case, match_exact, list_name, delimiter) return_outputs(human_readable, ec, None) # python2 uses __builtin__ python3 uses builtins if __name__ in ("__builtin__", "builtins"): main()
README
Checks whether the specified item is in a list. The default list is the XSOAR Indicators Whitelist.
Script Data
| Name | Description |
|---|---|
| Script Type | python2 |
| Tags | whitelist |
| Cortex XSOAR Version | 5.0.0 |
Used In
This script is used in the following playbooks and scripts.
- TIM - Process Domain Registrant With Whois
- TIM - Process Indicators Against Approved Hash List
- TIM - Process Indicators Against Business Partners Domains List
- TIM - Process Indicators Against Business Partners IP List
- TIM - Process Indicators Against Business Partners URL List
Inputs
| Argument Name | Description |
|---|---|
| values | The item to look for in the list. |
| listname | Name of the list against which to check the value. The default is the Indicators Whitelist. |
| ignorecase | Whether to ignore the case of the item for which you are searching. Default is “No”. |
| matchexact | Whether to match the exact item in the list, or look for any string that contains it. Default is “No”. |
| delimiter | A one-character string used to delimit fields. For example, a comma “,” should match the list separator configuration. |
Outputs
| Path | Description | Type |
|---|---|---|
| List.ListName | The name of the list you compared with. | string |
| List.In | The list of items in the list. | Unknown |
| List.NotIn | The list of items not in the list. | Unknown |