Palo Alto Networks Threat Vault Deprecated

Deprecated. Use Threat Vault v2 instead.

Data Enrichment & Threat Intelligence · Threat Vault by Palo Alto Networks

Details

IDPalo Alto Networks Threat Vault
ProviderPalo Alto Networks
CategoryData Enrichment & Threat Intelligence
From Version5.0.0
Docker Imagedemisto/python3:3.10.1.26972
Supported ModulesAgentix XSIAM

README

Use the Palo Alto Networks Threat Vault to research the latest threats (vulnerabilities/exploits, viruses, and spyware) that Palo Alto Networks next-generation firewalls can detect and prevent.
TIM customers that upgraded to version 6.2 or above, can have the API Key pre-configured in their main account so no additional input is needed. To use this feature, upgrade your license so it includes the license key.

Configure Palo Alto Networks Threat Vault in Cortex

Parameter Description Required
api_key API Key True
insecure Trust any certificate (not secure) False
proxy Use system proxy settings False

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

threatvault-antivirus-signature-get


Gets the antivirus signature.

Base Command

threatvault-antivirus-signature-get

Input

Argument Name Description Required
sha256 The SHA256 hash of the antivirus signature. Optional
signature_id The signature ID of the antivirus. Optional

Context Output

Path Type Description
ThreatVault.Antivirus.active Bool Whether the antivirus signature is active.
ThreatVault.Antivirus.category String The category of the antivirus signature.
ThreatVault.Antivirus.createTime String The time the antivirus signature was created.
ThreatVault.Antivirus.release Unknown The release details of the antivirus signature.
ThreatVault.Antivirus.sha256 String The sha256 hash of the antivirus signature.
ThreatVault.Antivirus.signatureId Number The ID of the antivirus signature.
ThreatVault.Antivirus.signatureName String The name of the antivirus signature.

Command Example

!threatvault-antivirus-signature-get signature_id=93534285

Context Example

{
    "ThreatVault": {
        "Antivirus": {
            "active": true,
            "createTime": "2010-10-01 10:28:57 (UTC)",
            "release": {
                "antivirus": {
                    "firstReleaseTime": "2010-10-03 15:04:58 UTC",
                    "firstReleaseVersion": 334,
                    "latestReleaseVersion": 0
                },
                "wildfire": {
                    "firstReleaseVersion": 0,
                    "latestReleaseVersion": 0
                }
            },
            "sha256": [
                "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
                "9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8"
            ],
            "signatureId": 93534285,
            "signatureName": "Worm/Win32.autorun.crck"
        }
    }
}

Human Readable Output

Antivirus

active createTime release sha256 signatureId signatureName
true 2010-10-01 10:28:57 (UTC) wildfire: {“latestReleaseVersion”: 0, “firstReleaseVersion”: 0}
antivirus: {“latestReleaseVersion”: 0, “firstReleaseVersion”: 334, “firstReleaseTime”: “2010-10-03 15:04:58 UTC”}
7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8,
9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8
93534285 Worm/Win32.autorun.crck

file


Checks the reputation of an antivirus in Threat Vault.

Base Command

file

Input

Argument Name Description Required
file The SHA256 hash of the antivirus signature. Optional

Context Output

Path Type Description
DBotScore.Vendor String The vendor used to calculate the score.
DBotScore.Score Number The actual score.
DBotScore.Type String The indicator type.
DBotScore.Indicator String The indicator that was tested.
File.MD5 String The MD5 hash of the file.
File.SHA1 String The SHA1 hash of the file.
File.SHA256 String The SHA256 hash of the file.
File.Malicious.Vendor String For malicious files, the vendor that made the decision.

Command Example

!file file= 7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8

Context Example

{
    "DBotScore": [
        {
            "Indicator": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "Score": 0,
            "Type": "file",
            "Vendor": "Zimperium"
        },
        {
            "Indicator": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "Score": 3,
            "Type": "file",
            "Vendor": "ThreatVault"
        },
        {
            "Indicator": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "Score": 3,
            "Type": "hash",
            "Vendor": "WildFire"
        },
        {
            "Indicator": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "Score": 3,
            "Type": "file",
            "Vendor": "WildFire"
        }
    ],
    "File": {
        "MD5": "7e8d3744c0a06d3c7ca7f6dbfce3d576",
        "Malicious": {
            "Vendor": "WildFire"
        },
        "Name": null,
        "SHA1": null,
        "SHA256": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
        "Size": "117760",
        "Type": "PE"
    },
    "ThreatVault": {
        "Antivirus": {
            "active": true,
            "createTime": "2010-10-01 10:28:57 (UTC)",
            "release": {
                "antivirus": {
                    "firstReleaseTime": "2010-10-03 15:04:58 UTC",
                    "firstReleaseVersion": 334,
                    "latestReleaseVersion": 0
                },
                "wildfire": {
                    "firstReleaseVersion": 0,
                    "latestReleaseVersion": 0
                }
            },
            "sha256": [
                "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
                "9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8"
            ],
            "signatureId": 93534285,
            "signatureName": "Worm/Win32.autorun.crck"
        }
    },
    "WildFire": {
        "Report": {
            "SHA256": "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "Status": "Success"
        }
    },
    "Zimperium": {
        "Application": null
    }
}

Human Readable Output

WildFire File Report

FileType MD5 SHA256 Size Status
PE 7e8d3744c0a06d3c7ca7f6dbfce3d576 7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8 117760 Completed

threatvault-dns-signature-get-by-id


Gets the DNS signature.
For more information about getting the IDs, see: https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-admin/threat-prevention/learn-more-about-and-assess-threats/learn-more-about-threat-signatures.html

Base Command

threatvault-dns-signature-get-by-id

Input

Argument Name Description Required
dns_signature_id The ID of the DNS signature. Optional

Context Output

Path Type Description
ThreatVault.DNS.active Bool Whether the DNS signature is active.
ThreatVault.DNS.category String The category of the DNS signature.
ThreatVault.DNS.createTime String The time the DNS signature was created.
ThreatVault.DNS.domainName String The domain name of the DNS signature.
ThreatVault.DNS.release Unknown The release details of the DNS signature.
ThreatVault.DNS.signatureId Number The ID of the DNS signature.
ThreatVault.DNS.signatureName String The name of the DNS signature.

Command Example

!threatvault-dns-signature-get-by-id signature_id=325235352

Context Example

{
    "ThreatVault": {
        "DNS": {}
    }
}

Human Readable Output

DNS signature was not found. Please try with a different dns_signature_id.

threatvault-antispyware-signature-get-by-id


Gets the antispyware signature.
For more information about getting the IDs, see: https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-admin/threat-prevention/learn-more-about-and-assess-threats/learn-more-about-threat-signatures.html

Base Command

threatvault-antispyware-signature-get-by-id

Input

Argument Name Description Required
signature_id ID of the antispyware signature. Optional

Context Output

Path Type Description
ThreatVault.AntiSpyware.firstReleaseVersion Number The first released version of the antispyware.
ThreatVault.AntiSpyware.signatureName String The name of the antispyware signature.
ThreatVault.AntiSpyware.firstReleaseTime AntiSpyware The time the antispyware was first released.
ThreatVault.AntiSpyware.vendor String The antispyware vendor.
ThreatVault.AntiSpyware.latestReleaseTime String The latest release time of the antispyware.
ThreatVault.AntiSpyware.metadata Unknown The metadata of the antispyware.
ThreatVault.AntiSpyware.signatureType String The signature type of the antispyware.
ThreatVault.AntiSpyware.cve String The status of the antispyware CVE.
ThreatVault.AntiSpyware.status String The status of the antispyware.
ThreatVault.AntiSpyware.signatureId Number The antispyware signature ID.
ThreatVault.AntiSpyware.latestReleaseVersion Number The latest released version of the antispyware.

Command Example

!threatvault-antispyware-signature-get-by-id signature_id=10001

Context Example

{
    "ThreatVault": {
        "AntiSpyware": {
            "cve": "",
            "firstReleaseTime": "2011-05-23 UTC",
            "firstReleaseVersion": 248,
            "latestReleaseTime": "2020-11-06 UTC",
            "latestReleaseVersion": 8340,
            "metadata": {
                "action": "alert",
                "category": "spyware",
                "changeData": "",
                "description": "This signature detects a variety of user-agents in HTTP request headers that have been known to be used by the Autorun family of malicious software, and not known to be used by legitimate clients. The request header should be inspected to investigate the suspect user-agent. If the user-agent is atypical or unexpected, the endpoint should be inspected to determine the user-agent used to generate the request on the machine (typically malware).",
                "panOsMaximumVersion": "",
                "panOsMinimumVersion": "6.1.0",
                "reference": "http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?Name=Win32/Autorun,http://blogs.technet.com/b/mmpc/archive/2011/02/08/breaking-up-the-romance-between-malware-and-autorun.aspx,http://nakedsecurity.sophos.com/2011/06/15/usb-autorun-malware-on-the-wane/",
                "severity": "medium"
            },
            "signatureId": 10001,
            "signatureName": "Autorun User-Agent Traffic",
            "signatureType": "spyware",
            "status": "released",
            "vendor": ""
        }
    }
}

Human Readable Output

Anti Spyware Signature

signatureId signatureName signatureType status firstReleaseTime latestReleaseTime
10001 Autorun User-Agent Traffic spyware released 2011-05-23 UTC 2020-11-06 UTC

threatvault-ip-geo-get


Get the IP address geolocation.

Base Command

threatvault-ip-geo-get

Input

Argument Name Description Required
ip The IP address to search. Optional

Context Output

Path Type Description
ThreatVault.IP.CountryCode String The country code.
ThreatVault.IP.CountryName String The country name.
ThreatVault.IP.ipAddress String The IP address.

Command Example

!threatvault-ip-geo-get ip=8.8.8.8

Context Example

{
    "ThreatVault": {
        "IP": {
            "countryCode": "US",
            "countryName": "United States",
            "ipAddress": "8.8.8.8"
        }
    }
}

Human Readable Output

IP location

countryCode countryName ipAddress
US United States 8.8.8.8

ip


Check IP location.

Base Command

ip

Input

Argument Name Description Required
ip IP address to query, e.g., !ip 1.1.1.1 Optional

Context Output

Path Type Description
IP.Address String The IP address.
IP.Geo.Country String The country of the IP address.
DBotScore.Vendor String The vendor used to calculate the score.
DBotScore.Score Number The actual score.
DBotScore.Type String The indicator type.
DBotScore.Indicator String The indicator that was tested.

Command Example

!ip ip=1.1.1.1

Context Example

{
    "DBotScore": {
        "Indicator": "1.1.1.1",
        "Score": 0,
        "Type": "ip",
        "Vendor": "ThreatVault"
    },
    "IP": {
        "Address": "1.1.1.1",
        "Geo": {
            "Country": "Australia"
        }
    },
    "ThreatVault": {
        "IP": {
            "countryCode": "AU",
            "countryName": "Australia",
            "ipAddress": "1.1.1.1"
        }
    }
}

Human Readable Output

IP location

countryCode countryName ipAddress
AU Australia 1.1.1.1

threatvault-antivirus-signature-search


Initiates an antivirus signature search.

Base Command

threatvault-antivirus-signature-search

Input

Argument Name Description Required
signature_name The signature name to search. Required
from From which signature to return results. Default is 0. Optional
to To which signature to return results. Default is from plus 10. Optional

Context Output

Path Type Description
ThreatVault.Search.search_request_id String The ID that was searched.
ThreatVault.Search.status String The status of the search.

Command Example

!threatvault-antivirus-signature-search signature_name=Worm/Win32.autorun.crck

Context Example

{
    "ThreatVault": {
        "Search": {
            "from": 0,
            "search_request_id": "5d10d1f1-2191-11eb-8c3b-396ee8360b80",
            "search_type": "panav",
            "status": "submitted",
            "to": 10
        }
    }
}

Human Readable Output

Antivirus Signature Search

from search_request_id search_type status to
0 5d10d1f1-2191-11eb-8c3b-396ee8360b80 panav submitted 10

threatvault-dns-signature-search


Initiates a DNS signature search.

Base Command

threatvault-dns-signature-search

Input

Argument Name Description Required
signature_name The signature name to search. Optional
domain_name The domain name to search. Optional
from From which signature to return results. Default is 0. Optional
to To which signature to return results. Default is from plus 10. Optional

Context Output

Path Type Description
ThreatVault.Search.search_request_id String The ID to search.
ThreatVault.Search.status String The status of the search.

Command Example

!threatvault-dns-signature-search domain_name=google.com

Context Example

{
    "ThreatVault": {
        "Search": {
            "from": 0,
            "search_request_id": "5a2e4b67-2191-11eb-aaa0-476a91ad21a0",
            "search_type": "dns",
            "status": "submitted",
            "to": 10
        }
    }
}

Human Readable Output

DNS Signature Search

from search_request_id search_type status to
0 5a2e4b67-2191-11eb-aaa0-476a91ad21a0 dns submitted 10

threatvault-antispyware-signature-search


Initiates an antispyware signature search.

Base Command

threatvault-antispyware-signature-search

Input

Argument Name Description Required
signature_name The signature name to search. Optional
vendor The vendor name to search. Optional
cve The CVE name to search. Optional
from From which signature to return results. Default is 0. Optional
to To which signature to return results. Default is from plus 10. Optional

Context Output

Path Type Description
ThreatVault.Search.search_request_id String The ID to search.
ThreatVault.Search.status String The status of the search.

Command Example

!threatvault-antispyware-signature-search cve=CVE-2015-8650

Context Example

{
    "ThreatVault": {
        "Search": {
            "from": 0,
            "search_request_id": "5bb4285c-2191-11eb-b288-43f099eed11d",
            "search_type": "ips",
            "status": "submitted",
            "to": 10
        }
    }
}

Human Readable Output

Anti Spyware Signature Search

from search_request_id search_type status to
0 5bb4285c-2191-11eb-b288-43f099eed11d ips submitted 10

threatvault-signature-search-results


Initiates an antispyware signature search.

Base Command

threatvault-signature-search-results

Input

Argument Name Description Required
search_request_id The ID to search. Required
search_type Search type. “ips” for antispyware, “dns” for DNS, and “panav” for antivirus. Required

Context Output

Path Type Description
ThreatVault.Search.search_request_id String The ID that was searched.
ThreatVault.Search.status String The status of the search.
ThreatVault.Search.page_count Number The number of results returned in this specific search.
ThreatVault.Search.total_count Number The number of results available for this specific search.
ThreatVault.Search.search_type String The search type. Can be either “ips”, “dns”. or “panav”.
ThreatVault.Searchf.signatures Unknown A list of all the signatures found for this specific search.

Command Example

!threatvault-signature-search-results search_type=dns search_request_id=8e9e2289-218f-11eb-b876-aba382af19b4

Context Example

{
    "ThreatVault": {
        "Search": {
            "page_count": 10,
            "search_request_id": "8e9e2289-218f-11eb-b876-aba382af19b4",
            "signatures": [
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-03-03 14:45:03 (UTC)",
                    "domainName": "mail-google.com.co",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-03-03 15:11:53 UTC",
                            "firstReleaseVersion": 1890,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 44101494,
                    "signatureName": "generic:mail-google.com.co"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-03-16 12:06:22 (UTC)",
                    "domainName": "www.google.com.shufaren.com.cn",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-03-16 15:13:36 UTC",
                            "firstReleaseVersion": 1903,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 45245562,
                    "signatureName": "generic:ogle.com.shufaren.com.cn"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-08-01 12:05:04 (UTC)",
                    "domainName": "verify.google.com.drive.viewdocument.buyers-exporters.com",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-08-01 15:12:15 UTC",
                            "firstReleaseVersion": 2055,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 60834054,
                    "signatureName": "generic:ent.buyers-exporters.com"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-08-01 12:05:05 (UTC)",
                    "domainName": "www.google.com-document-view.alibabatradegroup.com",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-08-01 15:12:15 UTC",
                            "firstReleaseVersion": 2055,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 60834216,
                    "signatureName": "generic:ew.alibabatradegroup.com"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-09-02 06:35:01 (UTC)",
                    "domainName": "accounts.google.com-sl.com",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-09-02 15:12:14 UTC",
                            "firstReleaseVersion": 2087,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 63218626,
                    "signatureName": "generic:counts.google.com-sl.com"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-10-10 23:06:14 (UTC)",
                    "domainName": "firstpagegoogle.com.au",
                    "release": {
                        "antivirus": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 69081944,
                    "signatureName": "None:firstpagegoogle.com.au"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-10-17 17:26:42 (UTC)",
                    "domainName": "plus.google.com.sxn.us",
                    "release": {
                        "antivirus": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 70722314,
                    "signatureName": "generic:plus.google.com.sxn.us"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-11-22 16:47:53 (UTC)",
                    "domainName": "chinagoogle.com.cn",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-11-22 15:10:51 UTC",
                            "firstReleaseVersion": 2178,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 82194404,
                    "signatureName": "generic:chinagoogle.com.cn"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-12-01 16:37:43 (UTC)",
                    "domainName": "google.com.im",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-12-01 15:11:36 UTC",
                            "firstReleaseVersion": 2191,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 83804135,
                    "signatureName": "generic:google.com.im"
                },
                {
                    "active": true,
                    "category": "malware",
                    "createTime": "2015-12-02 17:13:32 (UTC)",
                    "domainName": "documents.google.com.hjkeme3fxcncyygkfmsjvxsn.shhitmobil.com.ua",
                    "release": {
                        "antivirus": {
                            "firstReleaseTime": "2015-12-02 15:11:48 UTC",
                            "firstReleaseVersion": 2192,
                            "latestReleaseVersion": 0
                        },
                        "wildfire": {
                            "firstReleaseVersion": 0,
                            "latestReleaseVersion": 0
                        }
                    },
                    "signatureId": 84099818,
                    "signatureName": "generic:sjvxsn.shhitmobil.com.ua"
                }
            ],
            "status": "completed",
            "total_count": 5385
        }
    }
}

Human Readable Output

Signature search are showing 10 of 5385 results

signatureId signatureName domainName category
44101494 generic:mail-google.com.co mail-google.com.co malware
45245562 generic:ogle.com.shufaren.com.cn www.google.com.shufaren.com.cn malware
60834054 generic:ent.buyers-exporters.com verify.google.com.drive.viewdocument.buyers-exporters.com malware
60834216 generic:ew.alibabatradegroup.com www.google.com-document-view.alibabatradegroup.com malware
63218626 generic:counts.google.com-sl.com accounts.google.com-sl.com malware
69081944 None:firstpagegoogle.com.au firstpagegoogle.com.au malware
70722314 generic:plus.google.com.sxn.us plus.google.com.sxn.us malware
82194404 generic:chinagoogle.com.cn chinagoogle.com.cn malware
83804135 generic:google.com.im google.com.im malware
84099818 generic:sjvxsn.shhitmobil.com.ua documents.google.com.hjkeme3fxcncyygkfmsjvxsn.shhitmobil.com.ua malware

Configuration parameters

  • api_key — API Key
  • integrationReliability — Source Reliability
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (10)

  • file Deprecated

    Checks the reputation of an antivirus in Threat Vault.

  • ip Deprecated

    Check IP location.

  • threatvault-antispyware-signature-get-by-id Deprecated

    Gets the antispyware signature. For more details see the integration README.

  • threatvault-antispyware-signature-search Deprecated

    Initiates an antispyware signature search.

  • threatvault-antivirus-signature-get Deprecated

    Gets the antivirus signature.

  • threatvault-antivirus-signature-search Deprecated

    Initiates an antivirus signature search.

  • threatvault-dns-signature-get-by-id Deprecated

    Gets the DNS signature. For more details see the integration README.

  • threatvault-dns-signature-search Deprecated

    Initiates a DNS signature search.

  • threatvault-ip-geo-get Deprecated

    Get the IP address geolocation.

  • threatvault-signature-search-results Deprecated

    Initiates an antispyware signature search.

import pytest
from Threat_Vault import Client, antivirus_signature_get, file_command, dns_get_by_id, antispyware_get_by_id, \
    ip_geo_get, ip_command, antispyware_signature_search, signature_search_results


def test_antivirus_get_by_id(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-antivirus-signature.html
    Given:
        - an antivirus signature ID
    When:
        - mocking the server response for an ID, running antivirus_signature_get
    Then:
        - validating the returned context data
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        "active": True,
        "createTime": "2010-10-01 10:28:57 (UTC)",
        "release": {
            "antivirus": {
                "firstReleaseTime": "2010-10-03 15:04:58 UTC",
                "firstReleaseVersion": 334,
                "latestReleaseVersion": 0
            },
            "wildfire": {
                "firstReleaseVersion": 0,
                "latestReleaseVersion": 0
            }
        },
        "sha256": [
            "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8"
        ],
        "signatureId": 93534285,
        "signatureName": "Worm/Win32.autorun.crck"
    }
    mocker.patch.object(client, 'antivirus_signature_get_request', return_value=return_data)
    command_results = antivirus_signature_get(client, args={'signature_id': '93534285'})
    output = command_results.to_context()
    expected_result = {
        'ThreatVault.Antivirus(val.signatureId && val.signatureId == obj.signatureId)':
            {
                "active": True,
                "createTime": "2010-10-01 10:28:57 (UTC)",
                "release": {
                    "antivirus": {
                        "firstReleaseTime": "2010-10-03 15:04:58 UTC",
                        "firstReleaseVersion": 334,
                        "latestReleaseVersion": 0
                    },
                    "wildfire": {
                        "firstReleaseVersion": 0,
                        "latestReleaseVersion": 0
                    }
                },
                "sha256": [
                    "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
                    "9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8"
                ],
                "signatureId": 93534285,
                "signatureName": "Worm/Win32.autorun.crck"
            }
    }

    assert output.get('EntryContext') == expected_result


def test_antivirus_get_by_id_no_ids():
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-antivirus-signature.html
    Given:
        - no args
    When:
        - running antivirus_signature_get
    Then:
        - validating the raised error
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')

    with pytest.raises(Exception, match="Please submit a sha256 or a signature_id."):
        antivirus_signature_get(client, args={})


def test_file_command(mocker):
    """
    Given:
        - sha256 representing an antivirus
    When:
        - running file_command command
    Then
        - Validate the reputation of the sha256 is malicious.
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        "active": True,
        "createTime": "2010-10-01 10:28:57 (UTC)",
        "release": {
            "antivirus": {
                "firstReleaseTime": "2010-10-03 15:04:58 UTC",
                "firstReleaseVersion": 334,
                "latestReleaseVersion": 0
            },
            "wildfire": {
                "firstReleaseVersion": 0,
                "latestReleaseVersion": 0
            }
        },
        "sha256": [
            "7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8",
            "9e12c5cdb069f74487c11758e732d72047b72bedf4373aa9e3a58e8e158380f8"
        ],
        "signatureId": 93534285,
        "signatureName": "Worm/Win32.autorun.crck"
    }
    mocker.patch.object(client, 'antivirus_signature_get_request', return_value=return_data,
                        reliability='D - Not usually reliable')
    command_results_list = file_command(
        client, args={'file': '7a520be9db919a09d8ccd9b78c11885a6e97bc9cc87414558254cef3081dccf8'})

    assert command_results_list[0].indicator.dbot_score.score == 3


def test_dns_get_by_id(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-anti-spyware-signature.html
    Given:
        - a dns signature ID
    When:
        - mocking the server response for an ID, running dns_get_by_id
    Then:
        - validating the returned context data
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        'signatureId': 325235352, 'signatureName': 'generic:accounts.google.com.sign-google.com',
        'domainName': 'accounts.google.com.sign-google.com', 'createTime': '2020-01-15 23:57:54 (UTC)',
        'category': 'malware', 'active': True,
        'release': {
            'wildfire': {'latestReleaseVersion': 0, 'firstReleaseVersion': 0},
            'antivirus': {'latestReleaseVersion': 0, 'firstReleaseVersion': 0}
        }
    }
    mocker.patch.object(client, 'dns_signature_get_request', return_value=return_data)
    command_results = dns_get_by_id(client, args={'dns_signature_id': '325235352'})
    output = command_results.to_context()
    expected_result = {
        'ThreatVault.DNS(val.signatureId && val.signatureId == obj.signatureId)':
            {
                'signatureId': 325235352, 'signatureName': 'generic:accounts.google.com.sign-google.com',
                'domainName': 'accounts.google.com.sign-google.com', 'createTime': '2020-01-15 23:57:54 (UTC)',
                'category': 'malware', 'active': True,
                'release': {
                    'wildfire': {'latestReleaseVersion': 0, 'firstReleaseVersion': 0},
                    'antivirus': {'latestReleaseVersion': 0, 'firstReleaseVersion': 0}
                }
            }
    }

    assert output.get('EntryContext') == expected_result


def test_antispyware_get_by_id(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-vulnerability-signature.html
    Given:
        - a anti spyware signature ID
    When:
        - mocking the server response for an ID, running antispyware_get_by_id
    Then:
        - validating the returned context data
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        'metadata': {
            'severity': 'medium',
            'reference': 'http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?Name=Win32/Autorun,'
                         'http://blogs.technet.com/b/mmpc/archive/2011/02/08/breaking-up-the-romance-between-malware-'
                         'and-autorun.aspx,http://nakedsecurity.sophos.com/2011/06/15/usb-autorun-malware-on-the-wane/',
            'panOsMaximumVersion': '',
            'description': 'This signature detects a variety of user-agents in HTTP request headers that have been'
                           ' known to be used by the Autorun family of malicious software, and not known to be used by'
                           ' legitimate clients. The request header should be inspected to investigate the suspect'
                           ' user-agent. If the user-agent is atypical or unexpected, the endpoint should be inspected'
                           ' to determine the user-agent used to generate the request on the machine'
                           ' (typically malware).',
            'panOsMinimumVersion': '6.1.0', 'action': 'alert', 'category': 'spyware', 'changeData': ''
        },
        'cve': '', 'signatureName': 'Autorun User-Agent Traffic', 'vendor': '', 'signatureType': 'spyware',
        'firstReleaseTime': '2011-05-23 UTC', 'signatureId': 10001, 'latestReleaseTime': '2020-10-30 UTC',
        'latestReleaseVersion': 8338, 'status': 'released', 'firstReleaseVersion': 248
    }
    mocker.patch.object(client, 'antispyware_get_by_id_request', return_value=return_data)
    command_results = antispyware_get_by_id(client, args={'signature_id': '10001'})
    output = command_results.to_context()
    expected_result = {
        'ThreatVault.AntiSpyware(val.signatureId && val.signatureId == obj.signatureId)':
            {
                'metadata':
                    {
                        'severity': 'medium',
                        'reference': 'http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?Name='
                                     'Win32/Autorun,http://blogs.technet.com/b/mmpc/archive/2011/02/08/breaking-up-'
                                     'the-romance-between-malware-and-autorun.aspx,http://nakedsecurity.sophos.com/'
                                     '2011/06/15/usb-autorun-malware-on-the-wane/', 'panOsMaximumVersion': '',
                        'description': 'This signature detects a variety of user-agents in HTTP request headers that'
                                       ' have been known to be used by the Autorun family of malicious software, and'
                                       ' not known to be used by legitimate clients. The request header should be'
                                       ' inspected to investigate the suspect user-agent. If the user-agent is atypical'
                                       ' or unexpected, the endpoint should be inspected to determine the user-agent'
                                       ' used to generate the request on the machine (typically malware).',
                        'panOsMinimumVersion': '6.1.0', 'action': 'alert', 'category': 'spyware', 'changeData': ''
                    },
                'cve': '', 'signatureName': 'Autorun User-Agent Traffic', 'vendor': '', 'signatureType': 'spyware',
                'firstReleaseTime': '2011-05-23 UTC', 'signatureId': 10001, 'latestReleaseTime': '2020-10-30 UTC',
                'latestReleaseVersion': 8338, 'status': 'released', 'firstReleaseVersion': 248
            }
    }

    assert output.get('EntryContext') == expected_result


def test_ip_geo_get(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-geolocation.html
    Given:
        - an ip
    When:
        - mocking the server response for an IP, running ip_geo_get
    Then:
        - validating the returned context data
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {'ipAddress': '1.1.1.1', 'countryCode': 'AU', 'countryName': 'Australia'}
    mocker.patch.object(client, 'ip_geo_get_request', return_value=return_data)
    command_results = ip_geo_get(client, args={'ip': '1.1.1.1'})
    output = command_results.to_context()
    expected_result = {
        'ThreatVault.IP(val.ipAddress && val.ipAddress == obj.ipAddress)':
            {
                'ipAddress': '1.1.1.1', 'countryCode': 'AU', 'countryName': 'Australia'
            }
    }

    assert output.get('EntryContext') == expected_result


def test_ip_command(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-direct-searches/get-geolocation.html
    Given:
        - an ip
    When:
        - mocking the server response for an IP, running ip_command
    Then:
        - validating the generated indicator dbot score
        - validating the generated indicator country
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {'ipAddress': '8.8.8.8', 'countryCode': 'US', 'countryName': 'United States'}
    mocker.patch.object(client, 'ip_geo_get_request', return_value=return_data)
    command_results_list = ip_command(client, args={'ip': '8.8.8.8'})

    assert command_results_list[0].indicator.dbot_score.score == 0
    assert command_results_list[0].indicator.geo_country == 'United States'


def test_antispyware_signature_search_wrongful_arguments():
    """
    Given:
        - wrongful args to the antispyware_signature_search command
    When:
        - running antispyware_signature_search
    Then:
        - validating the raised error
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    wrong_args_err = 'Please provide either a signature_name or a cve or a vendor.'

    with pytest.raises(Exception, match=wrong_args_err):
        antispyware_signature_search(client, args={'signature_name': '1234', 'cve': 'CVE-2020'})
    with pytest.raises(Exception, match=wrong_args_err):
        antispyware_signature_search(client, args={'signature_name': '1234', 'vendor': 'panw'})
    with pytest.raises(Exception, match=wrong_args_err):
        antispyware_signature_search(client, args={'vendor': 'panw', 'cve': 'CVE-2020'})


def test_signature_search_results_dns(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-autofocus-searches/search-signatures.html
    Given:
        - a search_request_id
    When:
        - mocking the server response for a search_request_id of a domainName, running signature_search_results
    Then:
        - validating the returned context data
        - validating the returned human readable
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        "page_count": 1,
        "signatures": [
            {
                "active": True,
                "category": "malware",
                "createTime": "2015-03-03 14:45:03 (UTC)",
                "domainName": "mail-google.com.co",
                "release": {
                    "antivirus": {
                        "firstReleaseTime": "2015-03-03 15:11:53 UTC",
                        "firstReleaseVersion": 1890,
                        "latestReleaseVersion": 0
                    },
                    "wildfire": {
                        "firstReleaseVersion": 0,
                        "latestReleaseVersion": 0
                    }
                },
                "signatureId": 44101494,
                "signatureName": "generic:mail-google.com.co"
            }
        ],
        "total_count": 5306
    }
    mocker.patch.object(client, 'signature_search_results_request', return_value=return_data)
    command_results = signature_search_results(client, args={'search_request_id': 'mock_domain', 'size': '1'})
    output = command_results.to_context()
    expected_context = {
        'ThreatVault.Search(val.search_request_id && val.search_request_id == obj.search_request_id)':
            {
                "page_count": 1,
                "signatures": [
                    {
                        "active": True,
                        "category": "malware",
                        "createTime": "2015-03-03 14:45:03 (UTC)",
                        "domainName": "mail-google.com.co",
                        "release": {
                            "antivirus": {
                                "firstReleaseTime": "2015-03-03 15:11:53 UTC",
                                "firstReleaseVersion": 1890,
                                "latestReleaseVersion": 0
                            },
                            "wildfire": {
                                "firstReleaseVersion": 0,
                                "latestReleaseVersion": 0
                            }
                        },
                        "signatureId": 44101494,
                        "signatureName": "generic:mail-google.com.co"
                    }
                ],
                "total_count": 5306,
                'search_request_id': 'mock_domain',
                'status': 'completed'
            }
    }
    expected_hr = '### Signature search are showing 1 of 5306 results:\n|signatureId|signatureName|domainName|' \
                  'category|\n|---|---|---|---|\n| 44101494 | generic:mail-google.com.co | mail-google.com.co |' \
                  ' malware |\n'

    assert output.get('EntryContext') == expected_context
    assert output.get('HumanReadable') == expected_hr


def test_signature_search_results_anti_spyware_cve(mocker):
    """
    https://docs.paloaltonetworks.com/autofocus/autofocus-api/perform-autofocus-searches/search-signatures.html
    Given:
        - a search_request_id
    When:
        - mocking the server response for a search_request_id of a cve, running signature_search_results
    Then:
        - validating the returned context data
        - validating the returned human readable
    """
    client = Client(api_key='XXXXXXXX-XXX-XXXX-XXXX-XXXXXXXXXXXX', verify=True, proxy=False,
                    reliability='D - Not usually reliable')
    return_data = {
        "page_count": 1,
        "signatures": [
            {
                "cve": "CVE-2015-8650",
                "firstReleaseTime": "2015-12-28 UTC",
                "firstReleaseVersion": 548,
                "latestReleaseTime": "2020-10-30 UTC",
                "latestReleaseVersion": 8338,
                "metadata": {
                    "action": "reset-both",
                    "category": "code-execution",
                    "changeData": "",
                    "description": "Adobe Flash Player is prone to an use after free vulnerability while parsing"
                                   " certain crafted SWF files. The vulnerability is due to the lack of proper checks"
                                   " on SWF file, leading to an use after free vulnerability. An attacker could"
                                   " exploit the vulnerability by sending a crafted SWF file. A successful attack"
                                   " could lead to remote code execution with the privileges of the current"
                                   " logged-in user.",
                    "panOsMaximumVersion": "",
                    "panOsMinimumVersion": "7.1.0",
                    "reference": "https://helpx.adobe.com/security/products/flash-player/apsb16-01.html",
                    "severity": "high"
                },
                "signatureId": 38692,
                "signatureName": "Adobe Flash Player Use After Free Vulnerability",
                "signatureType": "vulnerability",
                "status": "released",
                "vendor": "APSB16-01"
            }
        ],
        "status": "completed",
        "total_count": 1
    }
    mocker.patch.object(client, 'signature_search_results_request', return_value=return_data)
    command_results = signature_search_results(client, args={'search_request_id': 'mock_cve', 'size': '1'})
    output = command_results.to_context()
    expected_context = {
        'ThreatVault.Search(val.search_request_id && val.search_request_id == obj.search_request_id)':
            {
                "page_count": 1,
                "search_request_id": "mock_cve",
                "signatures": [
                    {
                        "cve": "CVE-2015-8650",
                        "firstReleaseTime": "2015-12-28 UTC",
                        "firstReleaseVersion": 548,
                        "latestReleaseTime": "2020-10-30 UTC",
                        "latestReleaseVersion": 8338,
                        "metadata": {
                            "action": "reset-both",
                            "category": "code-execution",
                            "changeData": "",
                            "description": "Adobe Flash Player is prone to an use after free vulnerability while"
                                           " parsing certain crafted SWF files. The vulnerability is due to the lack"
                                           " of proper checks on SWF file, leading to an use after free vulnerability."
                                           " An attacker could exploit the vulnerability by sending a crafted SWF file."
                                           " A successful attack could lead to remote code execution with the"
                                           " privileges of the current logged-in user.",
                            "panOsMaximumVersion": "",
                            "panOsMinimumVersion": "7.1.0",
                            "reference": "https://helpx.adobe.com/security/products/flash-player/apsb16-01.html",
                            "severity": "high"
                        },
                        "signatureId": 38692,
                        "signatureName": "Adobe Flash Player Use After Free Vulnerability",
                        "signatureType": "vulnerability",
                        "status": "released",
                        "vendor": "APSB16-01"
                    }
                ],
                "status": "completed",
                "total_count": 1,
            }
    }
    expected_hr = '### Signature search are showing 1 of 1 results:\n|signatureId|signatureName|cve|' \
                  'signatureType|status|firstReleaseTime|latestReleaseTime|\n|---|---|---|---|---|---|---|\n|' \
                  ' 38692 | Adobe Flash Player Use After Free Vulnerability | CVE-2015-8650 |' \
                  ' vulnerability | released | 2015-12-28 UTC | 2020-10-30 UTC |\n'

    assert output.get('EntryContext') == expected_context
    assert output.get('HumanReadable') == expected_hr