This file is indexed.

/usr/lib/python2.7/dist-packages/rekall/plugins/filesystems/tsk.py is in python-rekall-core 1.6.0+dfsg-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
import pytsk3

from rekall import addrspace
from rekall import plugin
from rekall import obj
from rekall import utils
from rekall.plugins import guess_profile
from rekall.plugins.overlays import basic


class FSEntry(object):
    def __init__(self, tsk_file):
        self.tsk_file = tsk_file

    @property
    def type(self):
        return str(self.tsk_file.info.meta.type)[17:]

    @property
    def name(self):
        return self.tsk_file.info.name.name

    @property
    def size(self):
        return self.tsk_file.info.meta.size

    def read(self, start, size):
        if self.size > 0:
            return self.tsk_file.read_random(start, size)
        else:
            return ""

    def __iter__(self):
        if self.type == "DIR":
            for directory_entry in self.tsk_file.as_directory():
                if directory_entry.info.meta is None:
                    continue
                name = directory_entry.info.name.name
                if name in [".", ".."]:
                    continue
                yield FSEntry(directory_entry)


class FS(object):
    def __init__(self, tsk_fs):
        self.tsk_fs = tsk_fs

    def get_fs_entry_by_path(self, path):
        path = path.replace('\\', '/')
        tsk_file = self.tsk_fs.open(path)
        return FSEntry(tsk_file)


class VolumeSystem(object):
    """Wrap a TSK_VS_INFO struct."""

    def __init__(self, disk, tsk_vs, session=None):
        self.session = session
        self._disk = disk
        self.tsk_vs = tsk_vs
        self.type = str(self.tsk_vs.info.vstype)[12:]

    @utils.safe_property
    def partitions(self):
        return [Partition(self._disk, x, session=self.session, id=i)
                for i, x in enumerate(self.tsk_vs)]


class PartitionAddressSpace(addrspace.RunBasedAddressSpace):
    """Create a mapping into the partition."""

    def __init__(self, partition, **kwargs):
        super(PartitionAddressSpace, self).__init__(**kwargs)
        self.partition = partition
        self.add_run(0, partition.start, partition.length,
                     partition.disk.address_space)

    def __repr__(self):
        return "<Partition %s @ %#x>" % (self.partition.id,
                                         self.partition.start)



class Partition(object):
    """Wrap a TSK_VS_PART_INFO object."""

    def __init__(self, disk, partition=None, id=0, session=None,
                 filesystem=None):
        self.tsk_part = partition or obj.NoneObject()
        self.id = id
        self.disk = disk
        self.session = session
        self.filesystem = filesystem or obj.NoneObject("No filesystem")
        if (filesystem == None and
            self.tsk_part.flags == pytsk3.TSK_VS_PART_FLAG_ALLOC):
            try:
                address_space = self.get_partition_address_space()
                filesystem = pytsk3.FS_Info(AS_Img_Info(address_space))
                self.filesystem = FS(filesystem)
            except IOError:
                pass

    def get_partition_address_space(self):
        return PartitionAddressSpace(
            session=self.session, partition=self)

    @utils.safe_property
    def start(self):
        return (self.tsk_part.start * self.disk.block_size)

    @utils.safe_property
    def length(self):
        return (self.tsk_part.len * self.disk.block_size)


class Disk(object):
    def __init__(self, address_space, session=None):
        self.session = session
        self.block_size = 512

        # The address space of the entire disk.
        self.address_space = address_space
        self._img_info = AS_Img_Info(address_space)
        try:
            # open as disk image
            tsk_vs = pytsk3.Volume_Info(self._img_info)
            self.volume_system = VolumeSystem(
                self, tsk_vs, session=self.session)
            self.block_size = tsk_vs.info.block_size
            self.partitions = self.volume_system.partitions
        except IOError:
            # open as partition image
            self.volume_system = obj.NoneObject("No Volume")
            self.partitions = []
            try:
                fake_partition = Partition(
                    self, filesystem=FS(pytsk3.FS_Info(self._img_info)),
                    session=self.session)
                self.partitions.append(fake_partition)
            except IOError:
                pass

    def read(self, offset, size):
        return self._img_info.read(offset, size)


class AS_Img_Info(pytsk3.Img_Info):
    def __init__(self, address_space):
        self._as = address_space
        pytsk3.Img_Info.__init__(self, "")

    def close(self):
        self._as.close()

    def read(self, offset, size):
        return self._as.read(offset, size)

    def get_size(self):
        return self._as.end()


class TSKProfile(obj.Profile):
    pass


class TSKDetector(guess_profile.DetectionMethod):
    name = "tsk"

    def Offsets(self):
        return [0]

    def DetectFromHit(self, hit, offset, address_space):
        _ = offset
        disk = Disk(address_space, session=self.session)
        if len(disk.partitions) > 0:
            # Select a partition to make the default. Users can change
            # partitions using the cc plugin.
            self.session.SetParameter("disk", disk)
            profile = TSKProfile(session=self.session)
            for partition in disk.partitions:
                if partition.filesystem.tsk_fs.info.ftype:
                    self.session.logging.debug(
                        "Switching to first partition with filesystem.")
                    cc = SetPartitionContext(session=self.session,
                                             profile=profile)
                    cc.SwitchPartition(partition)
                    break

            return profile
        return None


class AbstractTSKCommandPlugin(plugin.PhysicalASMixin,
                               plugin.TypedProfileCommand,
                               plugin.ProfileCommand):
    """Baseclass for all TSK related plugins."""
    __abstract = True

    mode = "mode_tsk"


class SetPartitionContext(AbstractTSKCommandPlugin):
    name = "cc"
    interactive = True

    __args = [
        dict(name="partition_number", type="IntParser", positional=True,
             help="The partition to switch to.")
    ]

    table_header = [
        dict(name="message"),
    ]

    suppress_headers = True

    def __enter__(self):
        self.partition_context = self.session.GetParameter("partition_context")
        return self

    def __exit__(self, unused_type, unused_value, unused_traceback):
        self.SwitchPartition(self.partition_context)

    def SwitchPartition(self, partition=None):
        disk = self.session.GetParameter("disk")
        if isinstance(partition, (int, long)):
            partition = disk.partitions[partition]

        message = ("Switching to partition context: {0} "
                   "(Starts at {1:#x})").format(
                       partition.id, partition.start)

        self.session.SetCache(
            "default_address_space",
            partition.get_partition_address_space(),
            volatile=False)

        # Reset the address resolver for the new context.
        self.session.SetCache("partition_context", partition,
                              volatile=False)
        self.session.logging.debug(message)

        return message

    def collect(self):
        yield dict(
            message=self.SwitchPartition(self.plugin_args.partition_number))


class TskMmls(AbstractTSKCommandPlugin):
    name = "mmls"

    table_header = [
        dict(name="Partition", hidden=True),
        dict(name="PartId"),
        dict(name="Type", width=20),
        dict(name="Filesystem", width=20),
        dict(name="Offset", style="address"),
        dict(name="Size", style="address"),
    ]

    def collect(self):
        disk = self.session.GetParameter("disk")
        block_size = disk.block_size

        for i, partition in enumerate(disk.partitions):
            yield dict(Partition=partition,
                       PartId=i,
                       Type=partition.tsk_part.desc,
                       Filesystem=partition.filesystem.tsk_fs.info.ftype,
                       Offset=partition.tsk_part.start * block_size,
                       Size=partition.tsk_part.len * block_size,
                   )


class TSKFls(AbstractTSKCommandPlugin):
    name = "fls"

    __args = [
        dict(name="dir_path", default="/", positional=True,
             help="Directory path to print content of")
    ]

    table_header = [
        dict(name="name", width=50),
        dict(name="inode", width=20),
        dict(name="type", width=10),
        dict(name="size", width=10),
        dict(name="mtime", hidden=True, width=20),
        dict(name="atime", hidden=True, width=20),
        dict(name="ctime"),
    ]

    def collect(self):
        dir_path = self.plugin_args.dir_path
        partition = self.session.GetParameter("partition_context")
        try:
            for entry in partition.filesystem.get_fs_entry_by_path(dir_path):
                yield dict(name=entry.name,
                           inode=entry.tsk_file.info.meta.addr,
                           type=entry.type,
                           size=entry.size,
                           ctime=basic.UnixTimeStamp(
                               session=self.session,
                               name="ctime",
                               value=entry.tsk_file.info.meta.ctime),
                           mtime=basic.UnixTimeStamp(
                               session=self.session,
                               name="mtime",
                               value=entry.tsk_file.info.meta.mtime),
                           atime=basic.UnixTimeStamp(
                               session=self.session,
                               name="atime",
                               value=entry.tsk_file.info.meta.atime),
                           )
        except IOError as e:
            raise plugin.PluginError(e)