IsInternalDomainName
This script accepts multiple values for both arguments and will iterate through each of the domains to check if the specified subdomains are located in at least one of the specified main domains. If the tested subdomain is in one of the main domains, the result will be true. For example, if the domain_to_check values are apps.paloaltonetworks.com and apps.paloaltonetworks.bla and the domains_to_compare values are paloaltonetworks.com and demisto.com, the result for apps.paloaltonetworks.com will be true since it is a part of the paloaltonetworks.com domain. The result for apps.paloaltonetworks.bla will be false since it is not a part of the paloaltonetworks.com or demisto.com domain.
python · Common Scripts
Source
""" Script to check if a domain or a sub domain is part of a given domain """ from CommonServerPython import * MAXIMUM_NUMBER_OF_RECORDS = 10 def is_sub_domain_contained(main_domain: str, sub_domain: str) -> bool: """Check if the subdomain is contained within the main domain. Args: main_domain (str): The main domain. sub_domain (str): The sub domain. Returns: bool: True if the main_domain contains the sub_domain, False otherwise """ main_domain_parts = list(reversed(main_domain.split("."))) sub_domain_pats = list(reversed(sub_domain.split("."))) if len(main_domain_parts) > len(sub_domain_pats): return False return all(value == sub_domain_pats[i] for i, value in enumerate(main_domain_parts)) def check_sub_domains_in_domain(domains_to_compare: list, sub_domains_to_check: list): """ Args: domains_to_compare (list) : list of main domains that should be compared with sub domains sub_domains_to_check (list) : list of domains or sub domains that should be checked Returns: CommandResults included: 1. outputs (dict of) : { IsInternalDomain: [{ - DomainToTest : a subdomain (from the given list of subdomains) - DomainToCompare : list of given main domains - IsInternal : True / False if this subdomain is / is not in at least one of the given main domains. }] } 2. readable_output (markdown table) : contains first 10 entries with the above headers: ["DomainToTest", "DomainToCompare", "IsInternal"] """ context_entry = [] markdown = [] headers = ["DomainToTest", "DomainToCompare", "IsInternal"] for sub_domain in sub_domains_to_check: # in case sub domain is in at least one of the given main domains is_in_domain = any(is_sub_domain_contained(main_domain, sub_domain) for main_domain in domains_to_compare) context_entry.append({"DomainToTest": sub_domain, "DomainToCompare": domains_to_compare, "IsInternal": is_in_domain}) markdown.append({"DomainToTest": sub_domain, "DomainToCompare": domains_to_compare, "IsInternal": is_in_domain}) table = tableToMarkdown("", markdown[:MAXIMUM_NUMBER_OF_RECORDS], headers) return CommandResults(outputs={"IsInternalDomain": context_entry}, readable_output=table) def validate_args(domains_to_compare, sub_domains_to_check): if len(domains_to_compare) == 0: return_error("Error: please specify at least one possible main domain to compare with.") elif len(sub_domains_to_check) == 0: return_error("Error: please specify at least one possible sub domain to check.") def main(): args = demisto.args() domains_to_compare = argToList(args.get("main_domains")) sub_domains_to_check = argToList(args.get("possible_sub_domains_to_test")) validate_args(domains_to_compare, sub_domains_to_check) return_results(check_sub_domains_in_domain(domains_to_compare, sub_domains_to_check)) if __name__ in ("__main__", "__builtin__", "builtins"): main()
README
This script accepts multiple values for both arguments and will iterate through each of the domains to check if the specified subdomains are located in at least one of the specified main domains.
If the tested subdomain is in one of the main domains, the result will be true.
For example, if the domain_to_check values are apps.paloaltonetworks.com and apps.paloaltonetworks.bla and the domains_to_compare values are paloaltonetworks.com and demisto.com, the result for apps.paloaltonetworks.com will be true since it is a part of the paloaltonetworks.com domain. The result for apps.paloaltonetworks.bla will be false since it is not a part of the paloaltonetworks.com or demisto.com domain.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | Utility |
| Cortex XSOAR Version | 5.0.0 |
Inputs
| Argument Name | Description |
|---|---|
| main_domains | A comma-separated list of main domains. The subdomains will be compared to this list of main domains. For example, google.com. |
| possible_sub_domains_to_test | A comma-separated list of subdomains. These subdomains will be compared to the list of main domains. |
Outputs
| Path | Description | Type |
|---|---|---|
| IsInternalDomain.DomainToTest | The subdomain that was checked to see if it is part of the specified domains. | String |
| IsInternalDomain.IsInternal | True, if the subdomain is part of one of the specified domains. Otherwise, false. | Boolean |
| IsInternalDomain.DomainToCompare | The names of the main domains that were used to compare the subdomains to. | String |