misp-modules/misp_modules/modules/expansion/ransomcoindb.py

83 lines
3.6 KiB
Python
Raw Permalink Normal View History

import json
from . import check_input_attribute, checking_error, standard_error_message
2019-11-26 01:52:31 +01:00
from ._ransomcoindb import ransomcoindb
2019-11-26 11:15:47 +01:00
from pymisp import MISPObject
copyright = """
Copyright 2019 (C) by Aaron Kaplan <aaron@lo-res.org>, all rights reserved.
This file is part of the ransomwarecoindDB project and licensed under the AGPL 3.0 license
"""
2019-11-26 11:15:47 +01:00
debug = False
misperrors = {'error': 'Error'}
# mispattributes = {'input': ['sha1', 'sha256', 'md5', 'btc', 'xmr', 'dash' ], 'output': ['btc', 'sha1', 'sha256', 'md5', 'freetext']}
2019-11-26 11:15:47 +01:00
mispattributes = {'input': ['sha1', 'sha256', 'md5', 'btc'], 'output': ['btc', 'sha1', 'sha256', 'md5', 'freetext'], 'format': 'misp_standard'}
2024-08-12 11:23:10 +02:00
moduleinfo = {
'version': '0.1',
'author': 'Aaron Kaplan',
'description': 'Module to access the ransomcoinDB (see https://ransomcoindb.concinnity-risks.com)',
'module-type': ['expansion', 'hover'],
'name': 'RandomcoinDB Lookup',
'logo': '',
'requirements': ['A ransomcoinDB API key.'],
'features': 'The module takes either a hash attribute or a btc attribute as input to query the ransomcoinDB API for some additional data.\n\nIf the input is a btc address, we will get the associated hashes returned in a file MISP object. If we query ransomcoinDB with a hash, the response contains the associated btc addresses returned as single MISP btc attributes.',
'references': ['https://ransomcoindb.concinnity-risks.com'],
'input': 'A hash (md5, sha1 or sha256) or btc attribute.',
'output': 'Hashes associated to a btc address or btc addresses associated to a hash.',
'descrption': 'Module to access the ransomcoinDB with a hash or btc address attribute and get the associated btc address of hashes.',
}
moduleconfig = ['api-key']
def handler(q=False):
""" the main handler function which gets a JSON dict as input and returns a results dict """
if q is False:
return False
q = json.loads(q)
2020-02-25 15:22:06 +01:00
if "config" not in q or "api-key" not in q["config"]:
return {"error": "Ransomcoindb API key is missing"}
if not q.get('attribute') or not check_input_attribute(q['attribute'], requirements=('type', 'value')):
return {'error': f'{standard_error_message}, {checking_error}.'}
if q['attribute']['type'] not in mispattributes['input']:
return {'error': 'Unsupported attribute type.'}
api_key = q["config"]["api-key"]
r = {"results": []}
""" the "q" query coming in should look something like this:
{'config': {'api-key': '<api key here>'},
'md5': 'md5 or sha1 or sha256 or btc',
2019-11-25 18:56:12 +01:00
'module': 'ransomcoindb',
'persistent': 1}
"""
2019-11-26 11:15:47 +01:00
attribute = q['attribute']
answer = ransomcoindb.get_data_by('BTC', attribute['type'], attribute['value'], api_key)
""" The results data type should be:
r = { 'results': [ {'types': 'md5', 'values': [ a list of all md5s or all binaries related to this btc address ] } ] }
"""
if attribute['type'] in ['md5', 'sha1', 'sha256']:
r['results'].append({'types': 'btc', 'values': [a['btc'] for a in answer]})
elif attribute['type'] == 'btc':
# better: create a MISP object
files = []
for a in answer:
obj = MISPObject('file')
obj.add_attribute('md5', a['md5'])
obj.add_attribute('sha1', a['sha1'])
obj.add_attribute('sha256', a['sha256'])
files.append(obj)
r['results'] = {'Object': [json.loads(f.to_json()) for f in files]}
return r
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo