-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeliner.py
342 lines (313 loc) · 14.3 KB
/
timeliner.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
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
# Volatility
# Copyright (C) 2008-2011 Volatile Systems
# Copyright (C) 2011 Jamie Levy (Gleeda) <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
@author: Jamie Levy (gleeda)
@license: GNU General Public License 2.0 or later
@contact: [email protected]
@organization: Volatile Systems
"""
import volatility.plugins.taskmods as taskmods
import volatility.plugins.filescan as filescan
import volatility.plugins.sockets as sockets
import volatility.plugins.sockscan as sockscan
import volatility.plugins.modscan as modscan
import volatility.plugins.procdump as procdump
import volatility.plugins.dlldump as dlldump
import volatility.plugins.moddump as moddump
import volatility.plugins.netscan as netscan
import volatility.plugins.evtlogs as evtlogs
import volatility.plugins.registryapi as registryapi
import volatility.plugins.userassist as userassist
import volatility.plugins.imageinfo as imageinfo
import volatility.win32.rawreg as rawreg
import volatility.win32.tasks as tasks
import volatility.addrspace as addrspace
import volatility.plugins.overlays.windows.windows as windows
import volatility.utils as utils
import volatility.protos as protos
import os, sys
import struct
import volatility.debug as debug
import volatility.obj as obj
import datetime
class TimeLiner(filescan.PSScan, sockets.Sockets,
sockscan.SockScan,
modscan.ThrdScan,
dlldump.DLLDump,
moddump.ModDump,
procdump.ProcExeDump,
modscan.ModScan,
netscan.Netscan,
evtlogs.EvtLogs,
userassist.UserAssist,
registryapi.RegistryAPI,
imageinfo.ImageInfo):
""" Creates a timeline from various artifacts in memory """
def __init__(self, config, *args):
config.remove_option("HIVE-OFFSET")
userassist.UserAssist.__init__(self, config, *args)
config.remove_option("HIVE-OFFSET")
registryapi.RegistryAPI.__init__(self, config, *args)
config.remove_option("HIVE-OFFSET")
filescan.PSScan.__init__(self, config, *args)
sockscan.SockScan.__init__(self, config, *args)
sockets.Sockets.__init__(self, config, *args)
modscan.ThrdScan.__init__(self, config, *args)
dlldump.DLLDump.__init__(self, config, *args)
procdump.ProcExeDump.__init__(self, config, *args)
modscan.ModScan.__init__(self, config, *args)
moddump.ModDump.__init__(self, config, *args)
netscan.Netscan.__init__(self, config, *args)
evtlogs.EvtLogs.__init__(self, config, *args)
imageinfo.ImageInfo.__init__(self, config, *args)
config.add_option("UNSAFE", short_option = "u", default = False, action = 'store_true',
help = 'Bypasses certain sanity checks when creating image')
config.remove_option("KEY")
config.remove_option("START")
config.remove_option("END")
config.remove_option("VALUE")
def render_text(self, outfd, data):
for line in data:
if line != None:
outfd.write(line)
def calculate(self):
addr_space = utils.load_as(self._config)
self._config.update('TIMELINE', -1)
pids = {} #dictionary of process IDs/ImageFileName
offsets = [] #process offsets
im = self.get_image_time(addr_space)
event = "{0}|[END LIVE RESPONSE]\n".format(im['ImageDatetime'])
yield event
# Get EPROCESS
psscan = filescan.PSScan.calculate(self)
for eprocess in psscan:
if eprocess.obj_offset not in offsets:
offsets.append(eprocess.obj_offset)
ts = eprocess.CreateTime or '-1'
line = "{0}|{1}|{2}|{3}|{4}|{5}|0x{6:08x}||\n".format(
eprocess.CreateTime or '-1',
"[PROCESS]",
eprocess.ImageFileName,
eprocess.UniqueProcessId,
eprocess.InheritedFromUniqueProcessId,
eprocess.ExitTime or '',
eprocess.obj_offset)
pids[eprocess.UniqueProcessId.v()] = eprocess.ImageFileName
yield line
# Get Sockets and Evtlogs XP/2k3 only
if addr_space.profile.metadata.get('major', 0) == 5:
#socks = sockets.Sockets.calculate(self)
socks = sockscan.SockScan.calculate(self)
for sock in socks:
la = "{0}:{1}".format(sock.LocalIpAddress, sock.LocalPort)
line = "{0}|[SOCKET]|{1}|{2}|Protocol: {3} ({4})|{5:#010x}|||\n".format(
sock.CreateTime,
sock.Pid,
la,
sock.Protocol,
protos.protos.get(sock.Protocol.v(), "-"),
sock.obj_offset)
yield line
stuff = evtlogs.EvtLogs.calculate(self)
for name, buf in stuff:
lines = self.parse_evt_info(name, buf)
for l in lines:
l = l.replace("\n","")
t = l.split("|")
line = '{0} |[EVT LOG]|{1}|{2}|{3}|{4}|{5}|{6}|{7}\n'.format(
t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7])
yield line
else:
# Vista+
nets = netscan.Netscan.calculate(self)
for offset, proto, laddr, lport, raddr, rport, state, p, ctime in nets:
conn = "{0}:{1} -> {2}:{3}".format(laddr, lport, raddr, rport)
line = "{0}|[NETWORK CONNECTION]|{1}|{2}|{3}|{4}|{5:<#10x}||\n".format(
ctime,
p.UniqueProcessId,
conn,
proto,
state,
offset)
yield line
# Get threads
threads = modscan.ThrdScan.calculate(self)
for thread in threads:
try:
image = pids[thread.Cid.UniqueProcess.v()]
except:
image = ""
line = "{0}|{1}|{2}|{3}|{4}|{5}|||\n".format(
thread.CreateTime or '-1',
"[THREAD]",
image,
thread.Cid.UniqueProcess,
thread.Cid.UniqueThread,
thread.ExitTime or '',
)
yield line
# now we get to the PE part. All PE's are dumped in case you want to inspect them later
# Get module offsets by scanning
mod_offsets = []
data = modscan.ModScan.calculate(self)
for module in data:
base = "{0:#010x}".format(module.DllBase)
mod_offsets.append(base)
# and get PE timestamps for those modules
for base in mod_offsets:
self._config.update('OFFSET', int(base, 16))
data = moddump.ModDump.calculate(self)
for addr_space, procs, mod_base, mod_name in data:
space = tasks.find_space(addr_space, procs, mod_base)
if space != None:
try:
header = self.get_nt_header(space, mod_base)
except ValueError, ve:
continue
try:
line = "{0}|{1}|{2}|{3}|{4:#010x}|||||\n".format(
self.time_stamp(header.FileHeader.TimeDateStamp) or '-1',
"[PE Timestamp (module)]",
mod_name,
"",
mod_base)
except:
line = "{0}|{1}|{2}|{3}|{4}|||||\n".format(
'-1',
"[PE Timestamp (module)]",
mod_name,
"",
mod_base)
yield line
# get EPROCESS PE timestamps
for o in offsets:
self._config.update('OFFSET', o)
data = self.filter_tasks(procdump.ProcExeDump.calculate(self))
dllskip = False
for task in data:
if task.Peb == None or task.Peb.ImageBaseAddress == None:
dllskip = True
continue
try:
header = self.get_nt_header(task.get_process_address_space(), task.Peb.ImageBaseAddress)
except ValueError, ve:
dllskip = True
continue
try:
line = "{0}|{1}|{2}|{3}|{4}|{5}|0x{6:08x}|||\n".format(
self.time_stamp(header.FileHeader.TimeDateStamp) or "-1",
"[PE Timestamp (exe)]",
task.ImageFileName,
task.UniqueProcessId,
task.InheritedFromUniqueProcessId,
task.Peb.ProcessParameters.CommandLine,
o)
except:
line = "{0}|{1}|{2}|{3}|{4}|{5}|0x{6:08x}|||\n".format(
"-1",
"[PE Timestamp (exe)]",
task.ImageFileName,
task.UniqueProcessId,
task.InheritedFromUniqueProcessId,
task.Peb.ProcessParameters.CommandLine,
o)
yield line
# Get DLL PE timestamps
if not dllskip:
dlls = self.filter_tasks(dlldump.DLLDump.calculate(self))
else:
dllskip = False
dlls = []
for proc, ps_ad, mod_base, mod_name in dlls:
if ps_ad.is_valid_address(mod_base):
if mod_name == task.ImageFileName:
continue
try:
header = self.get_nt_header(ps_ad, mod_base)
except ValueError, ve:
continue
try:
line = "{0}|{1}|{2}|{3}|{4}|{5}|EPROCESS Offset: 0x{6:08x}|DLL Base: {7:8x}||\n".format(
self.time_stamp(header.FileHeader.TimeDateStamp) or '-1',
"[PE Timestamp (dll)]",
task.ImageFileName,
task.UniqueProcessId,
task.InheritedFromUniqueProcessId,
mod_name,
o,
mod_base)
except:
line = "{0}|{1}|{2}|{3}|{4}|{5}|EPROCESS Offset: 0x{6:08x}|DLL Base: {7:8x}||\n".format(
"-1",
"[PE Timestamp (dll)]",
task.ImageFileName,
task.UniqueProcessId,
task.InheritedFromUniqueProcessId,
mod_name,
o,
mod_base)
yield line
self.reset_current()
uastuff = userassist.UserAssist.calculate(self)
for win7, reg, key in uastuff:
ts = "{0}".format(key.LastWriteTime)
for v in rawreg.values(key):
tp, dat = rawreg.value_data(v)
subname = v.Name
if tp == 'REG_BINARY':
dat_raw = dat
try:
subname = subname.encode('rot_13')
except:
pass
if win7:
guid = subname.split("\\")[0]
if guid in userassist.folder_guids:
subname = subname.replace(guid, userassist.folder_guids[guid])
bufferas = addrspace.BufferAddressSpace(self._config, data = dat_raw)
uadata = obj.Object("_VOLUSER_ASSIST_TYPES", offset = 0, vm = bufferas)
ID = "N/A"
count = "N/A"
fc = "N/A"
tf = "N/A"
lw = "N/A"
if len(dat_raw) < bufferas.profile.get_obj_size('_VOLUSER_ASSIST_TYPES') or uadata == None:
pass
else:
if hasattr(uadata, "ID"):
ID = "{0}".format(uadata.ID)
if hasattr(uadata, "Count"):
count = "{0}".format(uadata.Count)
else:
count = "{0}".format(uadata.CountStartingAtFive if uadata.CountStartingAtFive < 5 else uadata.CountStartingAtFive - 5)
if hasattr(uadata, "FocusCount"):
seconds = (uadata.FocusTime + 500) / 1000.0
time = datetime.timedelta(seconds = seconds) if seconds > 0 else uadata.FocusTime
fc = "{0}".format(uadata.FocusCount)
tf = "{0}".format(time)
lw = "{0}".format(uadata.LastUpdated)
subname = subname.replace("|", "%7c")
line = "{0}|[USER ASSIST]|{1}|{2}|{3}|{4}|{5}|{6}\n".format(lw, reg, subname, ID, count, fc, tf)
yield line
#self._config.update("HIVE", "system") #you could use this if you wanted to only look at one particular registry
regs = registryapi.RegistryAPI.calculate(self)
for item, reg, remark in regs:
item = item.replace("|", "%7c")
line = "{0}|[REGISTRY]|{1}|{2}|||||\n".format(remark, reg, item)
yield line