1 import pytsk3
2
3 from rekall import addrspace
4 from rekall import plugin
5 from rekall import obj
6 from rekall_lib import utils
7 from rekall.plugins import guess_profile
8 from rekall.plugins.overlays import basic
9
10
11 -class FSEntry(object):
12 - def __init__(self, tsk_file):
13 self.tsk_file = tsk_file
14
15 @property
17 return str(self.tsk_file.info.meta.type)[17:]
18
19 @property
21 return self.tsk_file.info.name.name
22
23 @property
25 return self.tsk_file.info.meta.size
26
27 - def read(self, start, size):
28 if self.size > 0:
29 return self.tsk_file.read_random(start, size)
30 else:
31 return ""
32
34 if self.type == "DIR":
35 for directory_entry in self.tsk_file.as_directory():
36 if directory_entry.info.meta is None:
37 continue
38 name = directory_entry.info.name.name
39 if name in [".", ".."]:
40 continue
41 yield FSEntry(directory_entry)
42
52
55 """Wrap a TSK_VS_INFO struct."""
56
57 - def __init__(self, disk, tsk_vs, session=None):
58 self.session = session
59 self._disk = disk
60 self.tsk_vs = tsk_vs
61 self.type = str(self.tsk_vs.info.vstype)[12:]
62
63 @utils.safe_property
67
70 """Create a mapping into the partition."""
71
72 - def __init__(self, partition, **kwargs):
77
79 return "<Partition %s @ %#x>" % (self.partition.id,
80 self.partition.start)
81
85 """Wrap a TSK_VS_PART_INFO object."""
86
87 - def __init__(self, disk, partition=None, id=0, session=None,
88 filesystem=None):
102
106
107 @utils.safe_property
109 return (self.tsk_part.start * self.disk.block_size)
110
111 @utils.safe_property
113 return (self.tsk_part.len * self.disk.block_size)
114
115
116 -class Disk(object):
117 - def __init__(self, address_space, session=None):
142
143 - def read(self, offset, size):
145
151
154
155 - def read(self, offset, size):
157
159 return self._as.end()
160
164
191
196 """Baseclass for all TSK related plugins."""
197 __abstract = True
198
199 mode = "mode_tsk"
200
201
202 -class SetPartitionContext(AbstractTSKCommandPlugin):
203 name = "cc"
204 interactive = True
205
206 __args = [
207 dict(name="partition_number", type="IntParser", positional=True,
208 help="The partition to switch to.")
209 ]
210
211 table_header = [
212 dict(name="message"),
213 ]
214
215 suppress_headers = True
216
217 - def __enter__(self):
218 self.partition_context = self.session.GetParameter("partition_context")
219 return self
220
221 - def __exit__(self, unused_type, unused_value, unused_traceback):
222 self.SwitchPartition(self.partition_context)
223
224 - def SwitchPartition(self, partition=None):
225 disk = self.session.GetParameter("disk")
226 if isinstance(partition, (int, long)):
227 partition = disk.partitions[partition]
228
229 message = ("Switching to partition context: {0} "
230 "(Starts at {1:#x})").format(
231 partition.id, partition.start)
232
233 self.session.SetCache(
234 "default_address_space",
235 partition.get_partition_address_space(),
236 volatile=False)
237
238
239 self.session.SetCache("partition_context", partition,
240 volatile=False)
241 self.session.logging.debug(message)
242
243 return message
244
246 yield dict(
247 message=self.SwitchPartition(self.plugin_args.partition_number))
248
249
250 -class TskMmls(AbstractTSKCommandPlugin):
251 name = "mmls"
252
253 table_header = [
254 dict(name="Partition", hidden=True),
255 dict(name="PartId"),
256 dict(name="Type", width=20),
257 dict(name="Filesystem", width=20),
258 dict(name="Offset", style="address"),
259 dict(name="Size", style="address"),
260 ]
261
263 disk = self.session.GetParameter("disk")
264 block_size = disk.block_size
265
266 for i, partition in enumerate(disk.partitions):
267 yield dict(Partition=partition,
268 PartId=i,
269 Type=partition.tsk_part.desc,
270 Filesystem=partition.filesystem.tsk_fs.info.ftype,
271 Offset=partition.tsk_part.start * block_size,
272 Size=partition.tsk_part.len * block_size,
273 )
274
275
276 -class TSKFls(AbstractTSKCommandPlugin):
277 name = "fls"
278
279 __args = [
280 dict(name="dir_path", default="/", positional=True,
281 help="Directory path to print content of")
282 ]
283
284 table_header = [
285 dict(name="name", width=50),
286 dict(name="inode", width=20),
287 dict(name="type", width=10),
288 dict(name="size", width=10),
289 dict(name="mtime", hidden=True, width=20),
290 dict(name="atime", hidden=True, width=20),
291 dict(name="ctime"),
292 ]
293
295 dir_path = self.plugin_args.dir_path
296 partition = self.session.GetParameter("partition_context")
297 try:
298 for entry in partition.filesystem.get_fs_entry_by_path(dir_path):
299 yield dict(name=entry.name,
300 inode=entry.tsk_file.info.meta.addr,
301 type=entry.type,
302 size=entry.size,
303 ctime=basic.UnixTimeStamp(
304 session=self.session,
305 name="ctime",
306 value=entry.tsk_file.info.meta.ctime),
307 mtime=basic.UnixTimeStamp(
308 session=self.session,
309 name="mtime",
310 value=entry.tsk_file.info.meta.mtime),
311 atime=basic.UnixTimeStamp(
312 session=self.session,
313 name="atime",
314 value=entry.tsk_file.info.meta.atime),
315 )
316 except IOError as e:
317 raise plugin.PluginError(e)
318