Modules for expansion services, import and export in MISP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.6 KiB

# -*- coding: utf-8 -*-
import json
from onyphe import Onyphe
except ImportError:
print("pyonyphe module not installed.")
misperrors = {'error': 'Error'}
mispattributes = {'input': ['ip-src', 'ip-dst', 'hostname', 'domain'],
'output': ['hostname', 'domain', 'ip-src', 'ip-dst', 'url']}
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '1', 'author': 'Sebastien Larinier @sebdraven',
'description': 'Query on Onyphe',
'module-type': ['expansion', 'hover']}
# config fields that your code expects from the site admin
moduleconfig = ['apikey']
def handler(q=False):
4 years ago
if q:
4 years ago
request = json.loads(q)
if not request.get('config') or not request['config'].get('apikey'):
4 years ago
misperrors['error'] = 'Onyphe authentication is missing'
return misperrors
4 years ago
api = Onyphe(request['config'].get('apikey'))
4 years ago
if not api:
misperrors['error'] = 'Onyphe Error instance api'
ip = ''
if request.get('ip-src'):
ip = request['ip-src']
elif request.get('ip-dst'):
ip = request['ip-dst']
misperrors['error'] = "Unsupported attributes type"
return misperrors
4 years ago
return handle_expansion(api, ip, misperrors)
return False
def handle_expansion(api, ip, misperrors):
result = api.ip(ip)
if result['status'] == 'nok':
misperrors['error'] = result['message']
return misperrors
# categories = list(set([item['@category'] for item in result['results']]))
result_filtered = {"results": []}
urls_pasties = []
asn_list = []
4 years ago
os_list = []
4 years ago
domains_resolver = []
domains_forward = []
4 years ago
for r in result['results']:
if r['@category'] == 'pastries':
if r['source'] == 'pastebin':
urls_pasties.append('' % r['key'])
elif r['@category'] == 'synscan':
4 years ago
os_target = r['os']
if os_target != 'Unknown':
elif r['@category'] == 'resolver' and r['type'] == 'reverse':
4 years ago
elif r['@category'] == 'resolver' and r['type'] == 'forward':
4 years ago
4 years ago
result_filtered['results'].append({'types': ['url'], 'values': urls_pasties,
4 years ago
'categories': ['External analysis']})
4 years ago
result_filtered['results'].append({'types': ['AS'], 'values': list(set(asn_list)),
'categories': ['Network activity']})
4 years ago
result_filtered['results'].append({'types': ['target-machine'],
'values': list(set(os_list)),
'categories': ['Targeting data']})
4 years ago
4 years ago
result_filtered['results'].append({'types': ['domain'],
4 years ago
'values': list(set(domains_resolver)),
'categories': ['Network activity'],
'comment': 'resolver to %s' % ip})
4 years ago
4 years ago
result_filtered['results'].append({'types': ['domain'],
'values': list(set(domains_forward)),
4 years ago
'categories': ['Network activity'],
'comment': 'forward to %s' % ip})
return result_filtered
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo