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.

from CommonServerPython import *

# Disable insecure warnings
import urllib3
urllib3.disable_warnings()


class Client(BaseClient):
    """
    Client to use in the Threat Vault integration. Overrides BaseClient.
    """

    def __init__(self, api_key: str, verify: bool, proxy: bool, reliability: str):
        super().__init__(base_url='https://autofocus.paloaltonetworks.com/api/intel/v1', verify=verify, proxy=proxy,
                         headers={'Content-Type': 'application/json'})
        self._params = {'api_key': api_key}
        self.name = 'ThreatVault'
        self.reliability = reliability

    @logger
    def antivirus_signature_get_request(self, sha256: str = '', signature_id: str = '') -> dict:
        """Get antivirus signature by sending a GET request.

        Args:
            sha256: antivirus sha256.
            signature_id: signature ID.
        Returns:
            Response from API.
        """
        if (sha256 and signature_id) or (not sha256 and not signature_id):
            raise Exception('Please submit a sha256 or a signature_id.')
        if signature_id:
            suffix = f'/threatvault/panav/signature/{signature_id}'
        else:
            suffix = f'/file/{sha256}/signature'

        return self._http_request(method='GET', url_suffix=suffix, params=self._params)

    @logger
    def dns_signature_get_request(self, dns_signature_id: str) -> dict:
        """Get DNS signature by sending a GET request.

        Args:
            dns_signature_id: DNS signature ID.
        Returns:
            Response from API.
        """
        return self._http_request(method='GET', url_suffix=f'/threatvault/dns/signature/{dns_signature_id}',
                                  params=self._params)

    @logger
    def antispyware_get_by_id_request(self, signature_id: str) -> dict:
        """Get DNS signature by sending a GET request.

        Args:
            signature_id: signature ID.
        Returns:
            Response from API.
        """
        return self._http_request(method='GET', url_suffix=f'/threatvault/ips/signature/{signature_id}',
                                  params=self._params)

    @logger
    def ip_geo_get_request(self, ip_: str) -> dict:
        """Get IP geolocation by sending a GET request.

        Args:
            ip_: ip address.
        Returns:
            Response from API.
        """
        return self._http_request(method='GET', url_suffix=f'/ip/{ip_}/geolocation', params=self._params)

    @logger
    def search_request(self, path: str, from_: int, to_: int, signature_name: str = '', domain_name: str = '',
                       vendor: str = '', cve: str = '') -> dict:
        """Initiate a search by sending a POST request.

        Args:
            path: API endpoint path to search.
            from_: from which signature to return results.
            to_: to which signature to return results.
            signature_name: signature name.
            domain_name: domain name.
            vendor: vendor ID.
            cve: cve ID.
        Returns:
            Response from API.
        """
        if path == 'dns':  # DNS search
            if signature_name and domain_name:
                raise Exception('Please provide either a signature_name or a domain_name.')
        elif path == 'ips':  # Anti spyware search
            if (cve and (vendor or signature_name)) or (vendor and (cve or signature_name)) \
                    or (signature_name and (cve or vendor)):
                raise Exception('Please provide either a signature_name or a cve or a vendor.')

        data: Dict[str, Any] = {
            'from': from_,
            'size': to_ - from_
        }
        if signature_name:
            data['field'] = 'signatureName'
            data['value'] = signature_name
        elif domain_name:
            data['field'] = 'domainName'
            data['value'] = domain_name
        elif cve:
            data['field'] = 'cve'
            data['value'] = cve
        else:  # vendor name
            data['field'] = 'vendor'
            data['value'] = vendor

        return self._http_request(method='POST', url_suffix=f'/threatvault/{path}/search', params=self._params,
                                  json_data=data)

    @logger
    def signature_search_results_request(self, search_type: str, search_request_id: str) -> dict:
        """Get signature search results by sending a GET request.

        Args:
            search_type: search type.
            search_request_id: signature id.
        Returns:
            Response from API.
        """
        return self._http_request(method='GET',
                                  url_suffix=f'/threatvault/{search_type}/search/result/{search_request_id}',
                                  params=self._params)


def antivirus_signature_get(client: Client, args: dict) -> CommandResults:
    """Get antivirus signature.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    sha256 = str(args.get('sha256', ''))
    signature_id = str(args.get('signature_id', ''))

    try:
        response = client.antivirus_signature_get_request(sha256, signature_id)
        readable_output = tableToMarkdown(name="Antivirus:", t=response, removeNull=True)
    except Exception as err:
        if 'Error in API call [404] - Not Found' in str(err):
            response = {}
            readable_output = 'Antivirus signature was not found. Please try with a different sha256 or signature_id.'
        else:
            raise Exception(err)

    return CommandResults(
        outputs_prefix=f'{client.name}.Antivirus',
        outputs_key_field='signatureId',
        outputs=response,
        readable_output=readable_output,
        raw_response=response
    )


def file_command(client: Client, args: Dict) -> List[CommandResults]:
    """Get the reputation of a sha256 representing an antivirus
    Args:
        client: Client object with request.
        args: Usually demisto.args()
    Returns:
        list of CommandResults.
    """
    sha256_list = argToList(args.get('file'))
    command_results_list: List[CommandResults] = []
    dbot_reliability = DBotScoreReliability.get_dbot_score_reliability_from_str(client.reliability)

    for sha256 in sha256_list:
        try:
            response = client.antivirus_signature_get_request(sha256)
            dbot_score = Common.DBotScore(
                indicator=sha256,
                indicator_type=DBotScoreType.FILE,
                integration_name=client.name,
                score=Common.DBotScore.BAD,
                reliability=dbot_reliability
            )
            file = Common.File(
                sha256=sha256,
                dbot_score=dbot_score
            )
            readable_output = tableToMarkdown(name=f"SHA256 {sha256} Antivirus reputation:", t=response,
                                              removeNull=True)
        except Exception as err:
            if 'Error in API call [404] - Not Found' in str(err):
                response = {}
                dbot_score = Common.DBotScore(
                    indicator=sha256,
                    indicator_type=DBotScoreType.FILE,
                    integration_name=client.name,
                    reliability=dbot_reliability,
                    score=Common.DBotScore.NONE
                )
                file = Common.File(
                    sha256=sha256,
                    dbot_score=dbot_score
                )
                readable_output = f"SHA256 {sha256} Antivirus reputation is unknown to Threat Vault."
            else:
                raise Exception(err)

        command_results = CommandResults(
            outputs_prefix=f'{client.name}.Antivirus',
            outputs_key_field='signatureId',
            outputs=response,
            readable_output=readable_output,
            raw_response=response,
            indicator=file
        )
        command_results_list.append(command_results)

    return command_results_list


def dns_get_by_id(client: Client, args: dict) -> CommandResults:
    """Get DNS signature.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    dns_signature_id = str(args.get('dns_signature_id', ''))

    try:
        response = client.dns_signature_get_request(dns_signature_id)
        headers = ['signatureId', 'signatureName', 'domainName', 'createTime', 'category']
        readable_output = tableToMarkdown(name="DNS Signature:", t=response, headers=headers, removeNull=True)
    except Exception as err:
        if 'Error in API call [404] - Not Found' in str(err):
            response = {}
            readable_output = 'DNS signature was not found. Please try with a different dns_signature_id.'
        else:
            raise Exception(err)

    return CommandResults(
        outputs_prefix=f'{client.name}.DNS',
        outputs_key_field='signatureId',
        outputs=response,
        readable_output=readable_output,
        raw_response=response
    )


def antispyware_get_by_id(client: Client, args: dict) -> CommandResults:
    """Get anti spyware signature.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    signature_id = str(args.get('signature_id', ''))

    try:
        response = client.antispyware_get_by_id_request(signature_id)
        headers = ['signatureId', 'signatureName', 'signatureType', 'status', 'firstReleaseTime', 'latestReleaseTime']
        readable_output = tableToMarkdown(name="Anti Spyware Signature:", t=response, headers=headers, removeNull=True)
    except Exception as err:
        if 'Error in API call [404] - Not Found' in str(err):
            response = {}
            readable_output = 'Anti spyware signature was not found. Please try with a different signature_id.'
        else:
            raise Exception(err)

    return CommandResults(
        outputs_prefix=f'{client.name}.AntiSpyware',
        outputs_key_field='signatureId',
        outputs=response,
        readable_output=readable_output,
        raw_response=response
    )


def ip_geo_get(client: Client, args: dict) -> CommandResults:
    """Get IP geo location.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    ip_ = str(args.get('ip', ''))

    try:
        response = client.ip_geo_get_request(ip_)
        readable_output = tableToMarkdown(name="IP location:", t=response, removeNull=True)
    except Exception as err:
        if 'Error in API call [404] - Not Found' in str(err):
            response = {}
            readable_output = 'IP location was not found. Please try with a different IP.'
        else:
            raise Exception(err)

    return CommandResults(
        outputs_prefix=f'{client.name}.IP',
        outputs_key_field='ipAddress',
        outputs=response,
        readable_output=readable_output,
        raw_response=response
    )


def ip_command(client: Client, args: dict) -> List[CommandResults]:
    """Get IP geo location.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        list of CommandResults.
    """
    ip_list = argToList(args.get('ip', ''))
    command_results_list: List[CommandResults] = []
    dbot_reliability = DBotScoreReliability.get_dbot_score_reliability_from_str(client.reliability)

    for ip_ in ip_list:
        try:
            response = client.ip_geo_get_request(ip_)
            dbot_score = Common.DBotScore(
                indicator=ip_,
                indicator_type=DBotScoreType.IP,
                integration_name=client.name,
                reliability=dbot_reliability,
                score=Common.DBotScore.NONE
            )
            ip_obj = Common.IP(
                ip=ip_,
                dbot_score=dbot_score,
                geo_country=response.get('countryName'),
            )
            readable_output = tableToMarkdown(name="IP location:", t=response, removeNull=True)
        except Exception as err:
            if 'Error in API call [404] - Not Found' in str(err):
                response = {}
                dbot_score = Common.DBotScore(
                    indicator=ip_,
                    indicator_type=DBotScoreType.IP,
                    integration_name=client.name,
                    reliability=dbot_reliability,
                    score=Common.DBotScore.NONE
                )
                ip_obj = Common.IP(
                    ip=ip_,
                    dbot_score=dbot_score
                )
                readable_output = 'IP location was not found. Please try with a different IP.'
            else:
                raise Exception(err)

        command_results = CommandResults(
            outputs_prefix=f'{client.name}.IP',
            outputs_key_field='ipAddress',
            outputs=response,
            readable_output=readable_output,
            raw_response=response,
            indicator=ip_obj
        )
        command_results_list.append(command_results)

    return command_results_list


def antivirus_signature_search(client: Client, args: dict) -> CommandResults:
    """Initiate antivirus signature search.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    signature_name = str(args.get('signature_name', ''))
    from_ = int(args.get('from', 0))
    to_ = from_ + int(args.get('to', 10))

    response = client.search_request('panav', from_, to_, signature_name)

    outputs = response
    outputs.update({'search_type': 'panav', 'from': from_, 'to': to_})
    readable_output = tableToMarkdown(name="Antivirus Signature Search:", t=outputs, removeNull=True)

    return CommandResults(
        outputs_prefix=f'{client.name}.Search',
        outputs_key_field='search_request_id',
        outputs=outputs,
        readable_output=readable_output,
        raw_response=response
    )


def dns_signature_search(client: Client, args: dict) -> CommandResults:
    """Initiate DNS signature search.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    signature_name = str(args.get('signature_name', ''))
    from_ = int(args.get('from', 0))
    to_ = from_ + int(args.get('to', 10))
    domain_name = str(args.get('domain_name', ''))

    response = client.search_request('dns', from_, to_, signature_name, domain_name=domain_name)

    outputs = response
    outputs.update({'search_type': 'dns', 'from': from_, 'to': to_})
    readable_output = tableToMarkdown(name="DNS Signature Search:", t=outputs, removeNull=True)

    return CommandResults(
        outputs_prefix=f'{client.name}.Search',
        outputs_key_field='search_request_id',
        outputs=outputs,
        readable_output=readable_output,
        raw_response=response
    )


def antispyware_signature_search(client: Client, args: dict) -> CommandResults:
    """Initiate anti spyware signature search.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    signature_name = str(args.get('signature_name', ''))
    from_ = int(args.get('from', 0))
    to_ = from_ + int(args.get('to', 10))
    vendor = str(args.get('vendor', ''))
    cve = str(args.get('cve', ''))

    response = client.search_request('ips', from_, to_, signature_name, vendor=vendor, cve=cve)

    outputs = response
    outputs.update({'search_type': 'ips', 'from': from_, 'to': to_})
    readable_output = tableToMarkdown(name="Anti Spyware Signature Search:", t=outputs, removeNull=True)

    return CommandResults(
        outputs_prefix=f'{client.name}.Search',
        outputs_key_field='search_request_id',
        outputs=outputs,
        readable_output=readable_output,
        raw_response=response
    )


def signature_search_results(client: Client, args: dict):
    """Retrieve signature search results.

    Args:
        client: Client object with request.
        args: Usually demisto.args()

    Returns:
        CommandResults.
    """
    search_request_id = str(args.get('search_request_id', ''))
    search_type = str(args.get('search_type', ''))

    try:
        response = client.signature_search_results_request(search_type, search_request_id)

        outputs = response
        outputs.update({'search_request_id': search_request_id})
        if response.get('status') == 'submitted':  # search was not completed
            readable_output = f'Search {search_request_id} is still in progress.'
        else:
            headers = ['signatureId', 'signatureName', 'domainName', 'cve', 'signatureType', 'status', 'category',
                       'firstReleaseTime', 'latestReleaseTime']
            outputs.update({'status': 'completed'})
            title = f'Signature search are showing {outputs.get("page_count")} of {outputs.get("total_count")} results:'
            readable_output = tableToMarkdown(name=title, t=outputs.get('signatures'),
                                              headers=headers, removeNull=True)
        return CommandResults(
            outputs_prefix=f'{client.name}.Search',
            outputs_key_field='search_request_id',
            outputs=outputs,
            readable_output=readable_output,
            raw_response=response
        )
    except Exception as err:
        if 'Not Found' in str(err):
            return_warning(f'Search request ID {search_request_id} was not found.')
        else:
            raise


def test_module(client: Client, *_) -> str:
    """Performs basic get request to get ip geo data.

    Args:
        client: Client object with request.

    Returns:
        string.
    """
    client.ip_geo_get_request(ip_='1.1.1.1')
    return 'ok'


def main():
    """
        PARSE AND VALIDATE INTEGRATION PARAMS
    """
    params = demisto.params()
    auto_focus_key_retriever = AutoFocusKeyRetriever(params.get('api_key'))
    reliability = params.get('integrationReliability', 'D - Not usually reliable')
    if not DBotScoreReliability.is_valid_type(reliability):
        raise Exception("Please provide a valid value for the Source Reliability parameter.")

    verify = not params.get('insecure', False)
    proxy = params.get('proxy')

    try:
        command = demisto.command()
        LOG(f'Command being called is {demisto.command()}')
        client = Client(api_key=auto_focus_key_retriever.key, verify=verify, proxy=proxy, reliability=reliability)
        commands = {
            'threatvault-antivirus-signature-get': antivirus_signature_get,
            'file': file_command,
            'threatvault-dns-signature-get-by-id': dns_get_by_id,
            'threatvault-antispyware-signature-get-by-id': antispyware_get_by_id,
            'threatvault-ip-geo-get': ip_geo_get,
            'ip': ip_command,
            'threatvault-antivirus-signature-search': antivirus_signature_search,
            'threatvault-dns-signature-search': dns_signature_search,
            'threatvault-antispyware-signature-search': antispyware_signature_search,
            'threatvault-signature-search-results': signature_search_results,
        }
        if demisto.command() == 'test-module':
            # This is the call made when pressing the integration Test button.
            return_results(test_module(client))
        elif command in commands:
            return_results(commands[command](client, demisto.args()))
        else:
            raise NotImplementedError(f'Command "{command}" was not implemented.')

    except Exception as err:
        return_error(str(err), err)


if __name__ in ('__main__', '__builtin__', 'builtins'):
    main()