PanwIndicatorCreateQueries

The script accepts indicators as input and creates an indicator query in the relevant Palo Alto Networks products.

python · Comprehensive Investigation by Palo Alto Networks

Details

IDPanwIndicatorCreateQueries
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
TagsPanw

README

The script accepts indicators as input and creates an indicator query in the relevant Palo Alto Networks products.

Script Data


Name Description
Script Type python3
Tags Panw
Cortex XSOAR Version 5.0.0

Inputs


Argument Name Description
ip A commma-separated list of IP addresses for which to create the query.
hash A commma-separated list of file hashes for which to create the query.
domain A commma-separated list of domains for which to create the query.

Outputs


Path Description Type
Query.IP.CortexTrapsIP The query for the specified IP address indicators. This query is relevant for the Cortex Traps table “tms.threat”, which is the agent IP. String
Query.IP.CortexAnalyticsIP The query for the specified IP address indicators. This query is relevant for the Cortex Analytics table “tms.analytics”, which is the agent IP. String
Query.IP.CortexTrafficIP The query for the specified IP address indicators. This query is relevant for the Cortex Traffic table “panw.traffic”, and includes both source and destination. String
Query.IP.CortexThreatIP The query for the specified IP address indicators. This query is relevant for the Cortex Threat table “panw.threat”, and includes both source and destination. String
Query.IP.AutofocusSessionsIP The query (in JSON format) for the specified IP address indicators. This query is relevant for AutoFocus, includes both source and destination. String
Query.IP.PanoramaIP The query (in Panorama syntax) for the specified IP address indicators. This query is relevant for Panorama, and is valid for all log types. String
Query.Hash.CortexTrapsHash The query for the specified file hash indicators. This query is relevant for the Cortex Traps table “tms.threat”, which contains only SHA256 hashes. String
Query.Hash.CortexAnalyticsHash The query for the specified file hash indicators. This query is relevant for the Cortex Analytics table “tms.analytics”, which contains only SHA256 hashes. String
Query.Hash.CortexThreatHash The query for the specified file hash indicators. This query is relevant for the Cortex Threat table “panw.threat”, which contains only SHA256 hashes. String
Query.Hash.AutofocusSessionsHash The query (in JSON format) for the specified file hash indicators. This query is relevant for AutoFocus, and supports the following file hashes: MD5, SHA1, and SHA256. String
Query.Hash.PanoramaHash The query (in Panorama syntax) for the specified file hash indicators. This query is relevant for the WildFire log in Panorama, and only supports SHA256 hashes. String
Query.Domain.CortexThreatDomain The query for the domain indicators. This query is relevant for the Cortex Threat table “panw.threat”. String
Query.Domain.AutofocusSessionsDomain The query (in JSON format) for the domain indicators. This query is relevant for AutoFocus. String
Query.Domain.PanoramaDomain The query (in Panorama syntax) for the domain indicators. This query is relevant for Panorama. String
from PanwIndicatorCreateQueries import generate_ip_queries, generate_hash_queries, generate_domain_queries


def test_generate_ip_queries():
    """Unit test
    Given
    - generate_ip_queries command
    - command args(single and multiple ips)
    When
    - executing generate_ip_queries command
    Then
    - Validate that the proper query is created
    """
    expected1 = {"CortexTrapsIP": "SELECT * from tms.threat where endPointHeader.agentIp='8.8.8.8'"}
    expected2 = {
        "CortexTrapsIP": "SELECT * from tms.threat where endPointHeader.agentIp='8.8.8.8' OR endPointHeader.agentIp='1.1.1.1'"
    }
    queries1_1 = generate_ip_queries(["8.8.8.8"])
    queries1_2 = generate_ip_queries(["8.8.8.8", "12345"])
    queries2_1 = generate_ip_queries(["8.8.8.8", "1.1.1.1"])
    assert expected1["CortexTrapsIP"] == queries1_1["CortexTrapsIP"]
    assert expected1["CortexTrapsIP"] == queries1_2["CortexTrapsIP"]
    assert expected2["CortexTrapsIP"] == queries2_1["CortexTrapsIP"]


def test_generate_hash_queries():
    """Unit test
    Given
    - generate_hash_queries command
    - command args(single and multiple hashes)
    When
    - executing generate_hash_queries command
    Then
    - Validate that the proper query is created
    """
    cortex_traps_single_hash = {"CortexTrapsHash": "SELECT * from tms.threat where messageData.files.sha256='ababababababababab'"}
    queries_single_hash = generate_hash_queries(["ababababababababab"])
    assert queries_single_hash["CortexTrapsHash"] == cortex_traps_single_hash["CortexTrapsHash"]

    cortex_traps_multiple_hash = {
        "CortexTrapsHash": "SELECT * from tms.threat where messageData.files.sha256='ababababababababab' OR "
        "messageData.files.sha256='cbcbcbcbcbcbcbcbcb'"
    }
    auto_focus_hash_query = (
        '{"operator": "any", "children": ['
        '{"field": "alias.hash_lookup", "operator": "contains", "value": "ababababababababab"}, '
        '{"field": "alias.hash_lookup", "operator": "contains", "value": "cbcbcbcbcbcbcbcbcb"}]}'
    )
    queries_multiple_hashes = generate_hash_queries(["ababababababababab", "cbcbcbcbcbcbcbcbcb"])
    assert queries_multiple_hashes["CortexTrapsHash"] == cortex_traps_multiple_hash["CortexTrapsHash"]
    assert queries_multiple_hashes["AutofocusSessionsHash"] == auto_focus_hash_query


def test_generate_domain_queries():
    """Unit test
    Given
    - generate_domain_queries command
    - command args(single and multiple domains)
    When
    - executing generate_domain_queries command
    Then
    - Validate that the proper query is created
    """
    expected1 = {"CortexThreatDomain": "SELECT * from panw.threat where misc LIKE 'demisto.com'"}
    expected2 = {
        "CortexThreatDomain": "SELECT * from panw.threat where misc LIKE 'demisto.com' OR misc LIKE 'paloaltonetworks.com'"
    }
    queries1_1 = generate_domain_queries(["demisto.com"])
    queries2_1 = generate_domain_queries(["demisto.com", "paloaltonetworks.com"])
    assert expected1["CortexThreatDomain"] == queries1_1["CortexThreatDomain"]
    assert expected2["CortexThreatDomain"] == queries2_1["CortexThreatDomain"]