mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-28 03:43:31 +01:00
urlhaus dep upgrades + update to use authenticated abusech api
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
import sys
|
||||
import helpers
|
||||
import argparse
|
||||
|
||||
|
||||
def checkConfigRequirements(conf):
|
||||
if not conf.get('api_key'):
|
||||
sys.exit(126)
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def buildReq(artifact_value):
|
||||
return {"url": artifact_value}
|
||||
|
||||
|
||||
def sendReq(meta, payload):
|
||||
def sendReq(conf, meta, payload):
|
||||
url = meta['baseUrl']
|
||||
response = requests.request('POST', url, data=payload)
|
||||
headers = {}
|
||||
if conf.get('api_key'):
|
||||
headers['Auth-Key'] = conf['api_key']
|
||||
response = requests.request('POST', url, data=payload, headers=headers)
|
||||
return response.json()
|
||||
|
||||
|
||||
@@ -31,21 +43,28 @@ def prepareResults(raw):
|
||||
return results
|
||||
|
||||
|
||||
def analyze(input):
|
||||
def analyze(conf, input):
|
||||
checkConfigRequirements(conf)
|
||||
meta = helpers.loadMetadata(__file__)
|
||||
data = helpers.parseArtifact(input)
|
||||
helpers.checkSupportedType(meta, data["artifactType"])
|
||||
payload = buildReq(data["value"])
|
||||
response = sendReq(meta, payload)
|
||||
response = sendReq(conf, meta, payload)
|
||||
return prepareResults(response)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 2:
|
||||
results = analyze(sys.argv[1])
|
||||
dir = os.path.dirname(os.path.realpath(__file__))
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Search URLhaus 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 + '/urlhaus.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))
|
||||
else:
|
||||
print("ERROR: Missing input JSON")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user