-
Notifications
You must be signed in to change notification settings - Fork 51
/
mimir.py
254 lines (182 loc) · 6.8 KB
/
mimir.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env python2.7
import pycurl
import pickle
import os.path, os, sys
import time
import StringIO
import json
from selenium import webdriver
from blessings import Terminal
from ipwhois import IPWhois
from pprint import pprint
t = Terminal()
c = pycurl.Curl()
# Check if PyCurl version supports OpenSSL, if not, rebuild.
if "OpenSSL" not in pycurl.version:
print "\n[" + t.red("!") + "]Warning! Heuristics indicate your verion of PyCurl does not support OpenSSL."
print "[" + t.green("+") + "]Detected PyCurl version: " + pycurl.version
print "[" + t.green("+") + "]In order for Mimir to be able to connect to HoneyDB, OpenSSL is required."
print "\n[" + t.magenta("?") + "]Would you like to automatically resolve this issue?"
rebuild = raw_input("[Y]es/[N]o: ").lower()
if rebuild == 'y':
print "\n[" + t.green("+") + "]Invoking 'rebuild.sh'...\n"
time.sleep(1.5)
try:
os.system("chmod +x rebuild.sh")
os.system("./rebuild.sh")
except Exception as e:
print "\n[" + t.red("!") + "]Critical. An error was raised while attemting to invoke external utility"
print e
sys.exit(1)
print "\n[" + t.green("+") + "]PyCurl has been rebuilt with OpenSSL support. All systems nominal."
print "\n[" + t.green("+") + "]Mimir needs to be restarted for changes to take effect. Quitting..."
time.sleep(2.5)
sys.exit(1)
elif rebuild == 'n':
print "\n[" + t.green("+") + "]Not resolving."
else:
print "\n[" + t.red("!") + "]Unhandled option. Quitting."
sys.exit(1)
print t.cyan("""
oooo oooo ooooo oooo oooo ooooo oooooooooo
8888o 888 888 8888o 888 888 888 888
88 888o8 88 888 88 888o8 88 888 888oooo88
88 888 88 888 88 888 88 888 888 88o
o88o 8 o88o o888o o88o 8 o88o o888o o888o 88o8
Threat Intel Interface
\n""")
# Check if we have API ID/key saved
if not os.path.isfile("HDB-api-ID.p"):
print "[" + t.green("+") + "]Please provide your HoneyDB API ID\n"
DB_API_ID = raw_input("API ID: ")
pickle.dump(DB_API_ID, open( "HDB-api-ID.p", "wb" ))
print "[" + t.green("+") + "]Please provide your HoneyDB API key\n"
DB_API_KEY = raw_input("API key: ")
pickle.dump(DB_API_KEY, open( "HDB-api-key.p", "wb" ))
print "[" + t.green("+") + "]Your API data has been saved to 'HDB-api-ID.p' and 'HDB-api-key.p' in the current directory.\n"
else:
try:
DB_API_ID = pickle.load(open( "HDB-api-ID.p", "rb" ))
DB_API_KEY = pickle.load(open( "HDB-api-key.p", "rb" ))
except IOError as e:
print "\n[" + t.red("!") + "]Critical. An IO error was raised while attempting to read API data.\n"
print e
sys.exit(1)
ID_path = os.path.abspath("HDB-api-ID.p")
KEY_path = os.path.abspath("HDB-api-key.p")
print "\n[" + t.green("+") + "]Your API ID was succesfully loaded from " + ID_path
print "[" + t.green("+") + "]Your API key was succesfully loaded from " + KEY_path
# WHOIS function
def whois():
print "[" + t.green("+") + "]Please provide an IP for WHOIS lookup."
TARGET = raw_input("\n<" + t.cyan("WHOIS") + ">$ ")
obj = IPWhois(TARGET)
results = obj.lookup_rdap(depth=1)
pprint(results)
print "\n[" + t.magenta("?") + "]Would you like to append the WHOIS record to a text file?\n"
logs = raw_input("[Y]es/[N]o: ").lower()
format = json.dumps(results, indent = 2)
if logs == "y":
with open( "whois.log", "ab" ) as outfile:
outfile.write("Host: " + TARGET + "\n")
outfile.write(format)
outfile.close()
print "[" + t.green("+") + "]Results saved to whois.log in the current directory.\n"
elif logs == "n":
print "[" + t.green("+") + "]Returning to main menu.\n"
else:
print "[" + t.red("!") + "]Unhandled Option.\n"
def hosts():
a = StringIO.StringIO()
# Options for PyCurl
opts = ['X-HoneyDb-ApiId: ' + DB_API_ID, 'X-HoneyDb-ApiKey: ' + DB_API_KEY]
c.setopt(pycurl.HTTPHEADER, (opts))
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.URL, "https://riskdiscovery.com/honeydb/api/bad-hosts")
c.setopt(c.WRITEDATA, a)
try:
c.perform()
except Exception as e:
print "\n[" + t.red("!") + "]Critical. An error was raised with the following message"
print e
os.system("clear")
print "\n\n[" + t.green("+") + "]Retrieved Bad Hosts, formatting..."
time.sleep(1)
response_h = json.loads(a. getvalue())
pprint(response_h)
format = json.dumps(response_h, indent = 2)
with open('hosts.log', 'ab') as outfile:
outfile.write(format)
outfile.close()
print "\n\nResults saved to 'hosts.log' in the current directory"
def feed():
b = StringIO.StringIO()
# Options for PyCurl
opts = ['X-HoneyDb-ApiId: ' + DB_API_ID, 'X-HoneyDb-ApiKey: ' + DB_API_KEY]
c.setopt(pycurl.HTTPHEADER, (opts))
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.URL, "https://riskdiscovery.com/honeydb/api/twitter-threat-feed")
c.setopt(c.WRITEDATA, b)
try:
c.perform()
except Exception as e:
print "\n[" + t.red("!") + "]Critical. An error was raised with the following message"
print e
os.system("clear")
print "\n\n[" + t.green("+") + "]Retrieved Threat Feed, formatting..."
time.sleep(1)
response_f = json.loads(b. getvalue())
pprint(response_f)
format = json.dumps(response_f, indent = 2)
with open('feed.log', 'ab') as outfile:
outfile.write(format)
outfile.close()
print "\n\nResults saved to 'feed.log' in the current directory"
try:
while True:
print "\n\n[" + t.green("+") + "]Welcome to Mimir. Please select an action."
print """
1. Fetch Threat Feed 5. Visualize Top Malicious Hosts in Browser
2. Fetch Bad Host List 6. Visualize Top Targeted Services in Browser
3. Perform WHOIS Lookup 7. Visualize Results for Single Host in Browser
4. Invoke Nmap Scan 8. Quit
"""
option = raw_input("\n<" + t.cyan("MIMIR") + ">$ ")
if option == '1':
feed()
elif option =='2':
hosts()
elif option == '3':
whois()
elif option == '4':
host = raw_input("\n[" + t.green("+") + "]Please enter a target to scan: ")
try:
os.system("nmap -T4 -Pn --reason " + host)
except Exception as e:
print "\n[" + t.red("!") + "]Critical. An error was raised with the following message "
print e
elif option == '5':
try:
driver = webdriver.Firefox()
driver.get("https://riskdiscovery.com/honeydb/#hosts")
except:
pass
elif option == '6':
try:
driver = webdriver.Firefox()
driver.get("https://riskdiscovery.com/honeydb/#services")
except:
pass
elif option == '7':
host = raw_input("\n[" + t.green("+") + "]Please enter a host: ")
try:
driver = webdriver.Firefox()
driver.get("https://riskdiscovery.com/honeydb/#host/" + host )
except:
pass
elif option == '8':
break
else:
print "\n[" + t.red("!") + "]Unhandled Option."
except KeyboardInterrupt:
print "\n\n[" + t.red("!") + "]Critical. User aborted."