forked from JamesHabben/evolve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolve.py
More file actions
executable file
·376 lines (332 loc) · 12.6 KB
/
Copy pathevolve.py
File metadata and controls
executable file
·376 lines (332 loc) · 12.6 KB
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#!/usr/bin/env python
__author__ = 'james.habben'
evolveVersion = '1.5'
import sys
import argparse
if __name__ == '__main__':
print 'Python Version: ' + sys.version
print 'Evolve Version: ' + evolveVersion
argParser = argparse.ArgumentParser(description='Web interface for Volatility Framework.')
argParser.add_argument('-d', '--dbfolder', help='Optional database location')
argParser.add_argument('-f', '--file', help='RAM dump to analyze')
argParser.add_argument('-l', '--local', help='Restrict webserver to serving \'localhost\' only')
argParser.add_argument('-w', '--webport', help='Port to bind Web Server on', default=8080)
argParser.add_argument('-p', '--profile', help='Memory profile to use with Volatility')
argParser.add_argument('-r', '--run', help='Give a comma separated list of plugins to run on startup')
args = argParser.parse_args()
sys.argv = []
if not args.file:
#raise BaseException("RAM dump file is required.")
print "RAM dump file is required."
exit()
import os
#import volatility
#import bottle
import sqlite3
import json
import multiprocessing
import hashlib
import re
import urllib
import volatility.constants as constants
import volatility.registry as registry
import volatility.commands as commands
import volatility.conf as conf
import volatility.obj as obj
#import volatility.plugins.taskmods as taskmods
import volatility.addrspace as addrspace
#import volatility.utils as utils
#import volatility.renderers as render
#import volatility.plugins as plugins
#from bottle import route, Bottle, run, request
from morphs.BaseMorph import BaseMorph
results = multiprocessing.Queue()
Plugins = dict(plugins=[], hash=0)
profile = ''
def BuildPluginList():
con = sqlite3.connect(config.OUTPUT_FILE)
curs = con.cursor()
curs.execute('select name from sqlite_master where type = \'table\';')
tables = []
for tab in curs.fetchall():
tables.append(tab[0].lower())
curs.close()
con.close()
Plugins['plugins'] = []
for cmdname in sorted(cmds):
command = cmds[cmdname]
if command.is_valid_profile(profile) or cmdname in tables:
Plugins['plugins'].append({'name':cmdname,'help':command.help(), 'data':0, 'error':'', 'rowcount':0})
def BuildMorphList():
morphpath = os.path.join(os.path.dirname(__file__), 'morphs')
for morphfile in os.listdir(morphpath):
if morphfile.endswith('py') and morphfile.lower() not in ['basemorph.py','__init__.py']:
print "found morph: " + morphfile
__import__('morphs.' + morphfile.replace('.py',''))
Plugins['morphs'] = []
for sub in BaseMorph.__subclasses__():
#sub.__init__(sub)
Plugins['morphs'].append({'name':sub.name, 'display':sub.displayname,'plugins':sub.plugins, 'helptext':sub.helptext})
#Plugins['hash'] = hash(json.dumps(Plugins['plugins'], sort_keys=True))
def UpdatePluginList():
# Plugin['data']: 0=no data; 1=data; 2=running;
con = sqlite3.connect(config.OUTPUT_FILE)
curs = con.cursor()
curs.execute('select name from sqlite_master where type = \'table\';')
tables = []
for tab in curs.fetchall():
tables.append(tab[0].lower())
jobs = {}
while not results.empty():
#jobs.append(results.get())
j = results.get()
jobs = j
curs.close()
con.close()
for cmdname in Plugins['plugins']:
if cmdname['data'] == 1 and cmdname['name'] not in tables:
cmdname['data'] = 0
if cmdname['error'] == '' and cmdname['data'] != 2 and cmdname['name'] in tables:
cmdname['data'] = 1
if cmdname['data'] == 2 and cmdname['name'] in jobs.keys():
cmdname['error'] = jobs[cmdname['name']]
if cmdname['name'] in tables:
cmdname['data'] = 1
else:
cmdname['data'] = 0
#Plugins['hash'] = hash(json.dumps(Plugins['plugins'], sort_keys=True))
if __name__ == '__main__':
print 'Volatility Version: ' + constants.VERSION
config = conf.ConfObject()
registry.PluginImporter()
#config = conf.ConfObject()
registry.register_global_options(config, addrspace.BaseAddressSpace)
registry.register_global_options(config, commands.Command)
config.parse_options(False)
profs = registry.get_plugin_classes(obj.Profile)
if args.profile:
config.PROFILE = args.profile
else:
config.PROFILE = 'WinXPSP2x86'
if config.PROFILE not in profs:
#raise BaseException("Invalid profile " + config.PROFILE + " selected")
print 'Invalid profile ' + config.PROFILE + ' selected'
exit()
config.LOCATION = 'file://' + args.file
config.OUTPUT_FILE = args.file + '.sqlite'
if args.dbfolder:
print 'Hashing input file...',
config.OUTPUT_FILE = os.path.join(args.dbfolder, hashlib.md5(open(args.file).read()).hexdigest() + '.sqlite')
print 'done'
config.parse_options()
profile = profs[config.PROFILE]()
cmds = registry.get_plugin_classes(commands.Command, lower = True)
BuildPluginList()
BuildMorphList()
UpdatePluginList()
#print 'Python Version: ' + sys.version
#print 'Volatility Version: ' + constants.VERSION
#print 'Evolve Version: ' + evolveVersion
from bottle import route, Bottle, run, request, static_file
@route('/')
def index():
return static_file('evolve.htm',root='web')
@route('/web/:path#.+#', name='web')
def static(path):
return static_file(path, root='web')
@route('/data/plugins')
def ajax_plugins():
UpdatePluginList()
return json.dumps(Plugins)
@route('/data/meta')
def evolve_meta():
meta = {}
meta['profilename'] = config.PROFILE
meta['filepath'] = config.LOCATION
meta['evolveversion'] = evolveVersion
meta['volversion'] = constants.VERSION
return json.dumps(meta)
@route('/data/profilelist')
def profile_list():
plugins = registry.get_plugin_classes(obj.Profile)
result = []
for clsname, cls in sorted(plugins.items()):
try:
doc = cls.__doc__.strip().splitlines()[0]
except AttributeError:
doc = 'No docs'
result.append((clsname, doc))
return json.dumps(result)
@route('/config/profile/<pname>')
def set_profile(pname):
global profile
global cmds
global config
config.PROFILE = pname
print 'Set profile to {0}'.format(pname)
BuildPluginList()
UpdatePluginList()
@route('/data/view/<name>', method='GET')
@route('/data/view/<name>', method='POST')
@route('/data/view/<name>/morph/<morph>', method='GET')
@route('/data/view/<name>/morph/<morph>', method='POST')
def plugin_data(name, morph=''):
result = {'columns':[],'data':[]}
con = sqlite3.connect(config.OUTPUT_FILE)
if request.method == 'POST' and request.forms.get('query'):
query = request.forms.get('query')
else:
query = 'SELECT * FROM ' + name
curs = con.cursor()
try:
curs.execute(query)
result['data'] = curs.fetchall()
result['columns'] = [i[0] for i in curs.description]
except Exception as err:
result['error'] = err.message
result['name'] = name
result['query'] = query
result['morphs'] = []
for m in Plugins['morphs']:
if name in m['plugins']:
result['morphs'].append(m['name'])
if morph:
for sub in BaseMorph.__subclasses__():
if sub.name == morph:
cls = sub()
cls.morph(result)
return json.dumps(result)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
@route('/data2/plugin/<name>')
def plugin_data2(name):
con = sqlite3.connect(config.OUTPUT_FILE)
con.row_factory = dict_factory
cur = con.cursor()
cur.execute('SELECT * FROM ' + name)
return json.dumps( cur.fetchall())
@route('/run/plugin/<name>')
def run_plugin(name):
for cmdname in Plugins['plugins']:
if cmdname['name'] == name:
cmdname['data'] = 2 # running
break
p = multiprocessing.Process(target=run_plugin_process, kwargs=dict(name=name, queue=results, config=config, cmds=cmds))
p.daemon = True
p.start()
return
@route('/config/morph/<name>', method='GET')
def morph_config(name):
for sub in BaseMorph.__subclasses__():
if sub.name.lower() == name.lower():
cls = sub()
data = {
'name':cls.name,
'display':cls.displayname,
'helptext':cls.helptext,
'plugins':cls.plugins,
'config':cls.config
}
return json.dumps(data)
@route('/config/morph/<name>', method='POST')
def morph_set_config(name):
try:
for sub in BaseMorph.__subclasses__():
if sub.name.lower() == name.lower():
cls = sub()
#cls.SetConfig(request.forms.dict)
cls.SetConfig(request.json)
break
return json.dumps({'result':'success'})
except Exception as err:
print err.message + ': ' + str(err.args)
return json.dumps({'result':'error','msg':err.message + ': ' + str(err.args)})
# backend function for the jqueryFileTree
@route('/browse/server', method='POST')
def dirlist():
r = ['<ul class="jqueryFileTree" style="display: none;">']
try:
r = ['<ul class="jqueryFileTree" style="display: none;">']
#d = request.forms.get('dir')
d = urllib.unquote(request.forms.get('dir'))
if os.name == 'nt':
if d == '/':
drives = re.findall(r"[A-Z]+:.*$",os.popen('mountvol /').read(),re.MULTILINE)
drives.sort()
for dr in drives:
r.append('<li class="directory collapsed"><a href="#" rel="%s">%s</a></li>' % (dr,dr))
else:
for f in os.listdir(d):
ff=os.path.join(d,f)
if os.path.isdir(ff):
r.append('<li class="directory collapsed"><a href="#" rel="%s">%s</a></li>' % (ff,f))
else:
e=os.path.splitext(f)[1][1:] # get .ext and remove dot
r.append('<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>' % (e,ff,f))
else:
for f in os.listdir(d):
ff=os.path.join(d,f)
if os.path.isdir(ff):
r.append('<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % (ff,f))
else:
e=os.path.splitext(f)[1][1:] # get .ext and remove dot
r.append('<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>' % (e,ff,f))
r.append('</ul>')
except Exception,e:
r.append('Could not load directory: %s' % str(e))
r.append('</ul>')
return r
def run_plugin_process(name, queue, config, cmds):
registry.PluginImporter()
registry.register_global_options(config, addrspace.BaseAddressSpace)
registry.register_global_options(config, commands.Command)
config.parse_options()
command = cmds[name](config)
print 'running: ' + name
errstr = ''
try:
calc = command.calculate()
command.render_sqlite(config.OUTPUT_FILE, calc)
#AddColumn(config.OUTPUT_FILE, name, 'profile', config.PROFILE)
except Exception as err:
print name + ': ' + err.message
errstr = err.message
finally:
result = {name:errstr}
queue.put(result)
#queue.put(name)
return
def AddColumn(db, table, column, value):
con = sqlite3.connect(db)
cur = con.cursor()
try:
cur.execute('ALTER TABLE ' + table + ' ADD COLUMN ' + column + ' TEXT default NULL;')
cur.close()
con.close()
con2 = sqlite3.connect(db)
cur2 = con2.cursor()
query = "update {0} set {1} = '{2}' --where {1} is NULL;".format(table, column, value)
#cur.execute('update ' + table + ' set ' + column + ' = \'' + value + '\' where ' + column + ' is null;')
cur2.execute(query)
except:
pass # handle the error
cur2.close()
con2.close()
if __name__ == '__main__':
if args.run:
runlist = args.run.split(',')
for runplug in runlist:
for plug in Plugins['plugins']:
if plug['name'] == runplug and plug['data'] == 0:
plug['data'] = 2 # running
p = multiprocessing.Process(target=run_plugin_process, kwargs=dict(name=runplug, queue=results,))
p.daemon = True
p.start()
app = Bottle()
hostip = '0.0.0.0'
if args.local:
hostip = '127.0.0.1'
run(host=hostip, port=args.webport)