-
Notifications
You must be signed in to change notification settings - Fork 2
/
otx_hash.py
executable file
·69 lines (60 loc) · 1.95 KB
/
otx_hash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#############################################
# OTX Maltego Plugin
#
# Email: [email protected]
#############################################
import json
import requests
import sys
from MaltegoTransform import *
import traceback
from OTXv2 import OTXv2
import IndicatorTypes
import re
from OTXSettings import OTXSetting
def getPulse(general_result):
found_pulse = ''
if 'pulse_info' in general_result:
if 'pulses' in general_result['pulse_info']:
for pulse in general_result['pulse_info']['pulses']:
pulse_title = pulse['name']
pulse_id = pulse['id']
pulse_author = pulse['author']['username']
# We want one pulse, preferably the official one
if found_pulse == '' or pulse_author == 'AlienVault':
found_pulse = pulse_title + ' ID:' + pulse_id
return found_pulse
def main():
otx_settings = OTXSetting()
otx = OTXv2(otx_settings.API_KEY)
hash = sys.argv[1]
indicator_type = IndicatorTypes.FILE_HASH_SHA256
if len(hash) == 40:
indicator_type = IndicatorTypes.FILE_HASH_SHA1
if len(hash) == 32:
indicator_type == IndicatorTypes.FILE_HASH_MD5
general_result = otx.get_indicator_details_by_section(indicator_type, hash, 'general')
found_pulse = getPulse(general_result)
if found_pulse != '':
m.addEntity("otx.OTXPulse", found_pulse)
analysis_result = otx.get_indicator_details_by_section(indicator_type, hash, 'analysis')
try:
domainsJ = analysis_result['analysis']['plugins']['cuckoo']['result']['network']['domains']
for dns in domainsJ:
# { 'ip': '', 'domain': '' }
if len(str(dns).split("'")) > 6:
domain = str(dns).split("'")[7]
ip = str(dns).split("'")[3]
m.addEntity("maltego.IPv4Address", ip)
m.addEntity("maltego.Domain", domain)
except Exception as ex:
pass
return
if __name__ == '__main__':
m = MaltegoTransform()
m.addUIMessage("[INFO] Enriching Hash via OTX")
try:
main()
except Exception as e:
m.addUIMessage("[Error] " + str(e) + '\n' + traceback.format_exc())
m.returnOutput()