threatfox dep upgrade + use auth for api access

This commit is contained in:
reyesj2
2025-08-21 11:47:54 -05:00
parent 67f8fca043
commit 220e485312
15 changed files with 40 additions and 10 deletions

View File

@@ -51,6 +51,8 @@ sensoroni:
live_flow: False live_flow: False
mailbox_email_address: mailbox_email_address:
message_source_id: message_source_id:
threatfox:
api_key:
urlscan: urlscan:
base_url: https://urlscan.io/api/v1/ base_url: https://urlscan.io/api/v1/
api_key: api_key:

View File

@@ -1,6 +1,6 @@
{ {
"name": "Threatfox", "name": "Threatfox",
"version": "0.1", "version": "0.2",
"author": "Security Onion Solutions", "author": "Security Onion Solutions",
"description": "This analyzer queries Threatfox to see if a domain, hash, or IP is considered malicious.", "description": "This analyzer queries Threatfox to see if a domain, hash, or IP is considered malicious.",
"supportedTypes" : ["domain","hash","ip"], "supportedTypes" : ["domain","hash","ip"],

View File

@@ -2,6 +2,8 @@ import requests
import helpers import helpers
import json import json
import sys import sys
import argparse
import os
def buildReq(observ_type, observ_value): def buildReq(observ_type, observ_value):
@@ -13,10 +15,20 @@ def buildReq(observ_type, observ_value):
return qterms return qterms
def sendReq(meta, query): def checkConfigRequirements(conf):
if not conf.get('api_key'):
sys.exit(126)
else:
return True
def sendReq(conf, meta, query):
# send a post request based off of our compiled query # send a post request based off of our compiled query
url = meta['baseUrl'] url = meta['baseUrl']
response = requests.post(url, json.dumps(query)) headers = {}
if conf.get('api_key'):
headers['Auth-Key'] = conf['api_key']
response = requests.post(url, json.dumps(query), headers=headers)
return response.json() return response.json()
@@ -51,23 +63,30 @@ def prepareResults(raw):
return results return results
def analyze(input): def analyze(conf, input):
# put all of our methods together, pass them input, and return # put all of our methods together, pass them input, and return
# properly formatted json/python dict output # properly formatted json/python dict output
data = json.loads(input) checkConfigRequirements(conf)
meta = helpers.loadMetadata(__file__) meta = helpers.loadMetadata(__file__)
data = helpers.parseArtifact(input)
helpers.checkSupportedType(meta, data["artifactType"]) helpers.checkSupportedType(meta, data["artifactType"])
query = buildReq(data['artifactType'], data['value']) query = buildReq(data['artifactType'], data['value'])
response = sendReq(meta, query) response = sendReq(conf, meta, query)
return prepareResults(response) return prepareResults(response)
def main(): def main():
if len(sys.argv) == 2: dir = os.path.dirname(os.path.realpath(__file__))
results = analyze(sys.argv[1]) parser = argparse.ArgumentParser(
description='Search ThreatFox for a given artifact')
parser.add_argument(
'artifact', help='the artifact represented in JSON format')
parser.add_argument('-c', '--config', metavar='CONFIG_FILE', default=dir + '/threatfox.yaml',
help='optional config file to use instead of the default config file')
args = parser.parse_args()
if args.artifact:
results = analyze(helpers.loadConfig(args.config), args.artifact)
print(json.dumps(results)) print(json.dumps(results))
else:
print("ERROR: Input is not in proper JSON format")
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -0,0 +1 @@
api_key: "{{ salt['pillar.get']('sensoroni:analyzers:threatfox:api_key', '') }}"

View File

@@ -263,6 +263,14 @@ sensoroni:
sensitive: False sensitive: False
advanced: True advanced: True
forcedType: string forcedType: string
threatfox:
api_key:
description: API key for the threatfox analyzer.
helpLink: sensoroni.html
global: False
sensitive: True
advanced: False
forcedType: string
urlscan: urlscan:
api_key: api_key:
description: API key for the Urlscan analyzer. description: API key for the Urlscan analyzer.