This file is indexed.

/usr/lib/python2.7/dist-packages/rekall/plugins/windows/filescan.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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#!/usr/bin/env python
#
#       fileobjscan.py
#       Copyright 2009 Andreas Schuster <a.schuster@yendor.net>
#       Copyright (C) 2009-2011 Volatile Systems
#
#       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., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

# pylint: disable=protected-access

"""
@author:       Andreas Schuster
@license:      GNU General Public License 2.0 or later
@contact:      a.schuster@forensikblog.de
@organization: http://computer.forensikblog.de/en/
"""
from rekall.plugins.windows import common


class PoolScanFile(common.PoolScanner):
    """PoolScanner for File objects"""
    def __init__(self, **kwargs):
        super(PoolScanFile, self).__init__(**kwargs)
        self.checks = [
            ('PoolTagCheck', dict(
                tag=self.profile.get_constant("FILE_POOLTAG"))),

            ('CheckPoolSize', dict(
                min_size=self.profile.get_obj_size("_FILE_OBJECT"))),

            ('CheckPoolType', dict(
                paged=True, non_paged=True, free=True)),

            ('CheckPoolIndex', dict(value=0)),
            ]


class FileScan(common.PoolScannerPlugin):
    """ Scan Physical memory for _FILE_OBJECT pool allocations
    """
    __name = "filescan"

    table_header = [
        dict(name='a', width=1),
        dict(name="offset", style="address"),
        dict(name="ptr_no", width=6, align="r"),
        dict(name="hnd_no", width=3, align="r"),
        dict(name="access", width=6),
        dict(name='Owner', type="_EPROCESS"),
        dict(name="path")
    ]

    scanner_defaults = dict(
        scan_kernel_nonpaged_pool=True
    )

    def collect(self):
        """Generate possible hits."""
        for run in self.generate_memory_ranges():
            scanner = PoolScanFile(profile=self.profile, session=self.session,
                                   address_space=run.address_space)

            for pool_obj in scanner.scan(run.start, run.length):
                for object_obj in pool_obj.IterObject("File", freed=True):
                    ## If the string is not reachable we skip it
                    file_obj = self.session.profile._FILE_OBJECT(
                        offset=object_obj.obj_end, vm=run.address_space)

                    if not file_obj.FileName.v(vm=self.kernel_address_space):
                        continue

                    # Real file objects have valid DeviceObject types.
                    device_obj = file_obj.DeviceObject.deref(
                        vm=self.session.kernel_address_space)

                    if not device_obj.DeviceType.is_valid():
                        continue

                    # The Process member in the HandleInfo sometimes points at
                    # the _EPROCESS owning the handle.
                    owner_process = (
                        object_obj.HandleInfo.SingleEntry.Process.deref(
                            vm=self.kernel_address_space))

                    filename = file_obj.file_name_with_drive(
                        vm=self.kernel_address_space)

                    yield dict(a='F' if pool_obj.FreePool else "",
                               offset=file_obj.obj_offset,
                               ptr_no=object_obj.PointerCount,
                               hnd_no=object_obj.HandleCount,
                               access=file_obj.AccessString,
                               Owner=owner_process,
                               path=filename)


class PoolScanDriver(common.PoolScanner):
    """ Scanner for _DRIVER_OBJECT """

    def __init__(self, **kwargs):
        super(PoolScanDriver, self).__init__(**kwargs)
        self.checks = [
            ('PoolTagCheck', dict(
                tag=self.profile.get_constant("DRIVER_POOLTAG"))),

            # Must be large enough to hold the driver object.
            ('CheckPoolSize', dict(
                condition=lambda x: x > self.profile.get_obj_size(
                    "_DRIVER_OBJECT"))),

            ('CheckPoolType', dict(
                paged=True, non_paged=True, free=True)),

            ('CheckPoolIndex', dict(value=0)),
            ]


class DriverScan(common.PoolScannerPlugin):
    "Scan for driver objects _DRIVER_OBJECT "

    __name = "driverscan"

    table_header = [
        dict(name='a', width=1),
        dict(name="offset", style="address"),
        dict(name="ptr_no", width=6, align="r"),
        dict(name="hnd_no", width=3, align="r"),
        dict(name="start", style="address"),
        dict(name="size", style="address"),
        dict(name="servicekey", width=20),
        dict(name="name", width=12),
        dict(name="path")
    ]

    scanner_defaults = dict(
        scan_kernel_nonpaged_pool=True
    )

    def collect(self):
        """Generate possible hits."""
        for run in self.generate_memory_ranges():
            scanner = PoolScanDriver(session=self.session,
                                     profile=self.profile,
                                     address_space=run.address_space)

            for pool_obj in scanner.scan(run.start, run.length):
                for object_obj in pool_obj.IterObject("Driver", freed=True):
                    object_name = object_obj.NameInfo.Name.v(
                        vm=self.kernel_address_space)

                    driver_obj = self.profile._DRIVER_OBJECT(
                        object_obj.obj_end, vm=run.address_space)

                    extension_obj = self.profile._DRIVER_EXTENSION(
                        driver_obj.obj_end, vm=run.address_space)

                    yield dict(a='F' if pool_obj.FreePool else "",
                               offset=driver_obj.obj_offset,
                               ptr_no=object_obj.PointerCount,
                               hnd_no=object_obj.HandleCount,
                               start=driver_obj.DriverStart,
                               size=driver_obj.DriverSize,
                               servicekey=extension_obj.ServiceKeyName.v(
                                   vm=self.kernel_address_space),
                               name=object_name,
                               path=driver_obj.DriverName.v(
                                   vm=self.kernel_address_space)
                    )


class PoolScanSymlink(common.PoolScanner):
    """ Scanner for symbolic link objects """
    def __init__(self, **kwargs):
        super(PoolScanSymlink, self).__init__(**kwargs)
        self.checks = [
            ('PoolTagCheck', dict(
                tag=self.profile.get_constant("SYMLINK_POOLTAG"))),

            ('CheckPoolSize', dict(
                min_size=self.profile.get_obj_size(
                    "_OBJECT_SYMBOLIC_LINK"))),

            ('CheckPoolType', dict(paged=True, non_paged=True, free=True)),
            ]


class SymLinkScan(common.PoolScannerPlugin):
    "Scan for symbolic link objects "

    __name = "symlinkscan"

    table_header = [
        dict(name='a', width=1),
        dict(name="offset", style="address"),
        dict(name="ptr_no", width=6, align="r"),
        dict(name="hnd_no", width=3, align="r"),
        dict(name="creation_time", width=24),
        dict(name="from_link"),
        dict(name="to_link", width=60),
    ]

    scanner_defaults = dict(
        # According to pool_tracker plugin this always comes from paged pool.
        scan_kernel_paged_pool=True
    )

    def collect(self):
        """Generate possible hits."""
        for run in self.generate_memory_ranges():
            scanner = PoolScanSymlink(profile=self.profile,
                                      session=self.session,
                                      address_space=run.address_space)
            for pool_obj in scanner.scan(run.start, run.length):
                for object_obj in pool_obj.IterObject(
                        "SymbolicLink", freed=True):
                    object_name = object_obj.NameInfo.Name.v(
                        vm=self.kernel_address_space)

                    link_obj = self.profile._OBJECT_SYMBOLIC_LINK(
                        object_obj.obj_end, vm=run.address_space)

                    yield dict(a='F' if pool_obj.FreePool else "",
                               offset=link_obj.obj_offset,
                               ptr_no=object_obj.PointerCount,
                               hnd_no=object_obj.HandleCount,
                               creation_time=link_obj.CreationTime or '',
                               from_link=object_name,
                               to_link=link_obj.LinkTarget.v(
                                   vm=self.kernel_address_space))


class PoolScanMutant(PoolScanDriver):
    """ Scanner for Mutants _KMUTANT """
    def __init__(self, **kwargs):
        super(PoolScanMutant, self).__init__(**kwargs)
        self.checks = [
            ('PoolTagCheck', dict(tag=self.profile.get_constant(
                "MUTANT_POOLTAG"))),

            ('CheckPoolSize', dict(
                min_size=self.profile.get_obj_size("_KMUTANT"))),

            ('CheckPoolType', dict(
                paged=True, non_paged=True, free=True)),

            ('CheckPoolIndex', dict(value=0)),
            ]


class MutantScan(common.PoolScannerPlugin):
    "Scan for mutant objects _KMUTANT "

    __name = "mutantscan"

    table_header = [
        dict(name='a', width=1),
        dict(name="offset", style="address"),
        dict(name="ptr_no", width=6, align="r"),
        dict(name="hnd_no", width=3, align="r"),
        dict(name="signal", width=6),
        dict(name="thread", style="address"),
        dict(name="cid", width=9, align="r"),
        dict(name="name")
    ]

    scanner_defaults = dict(
        scan_kernel_nonpaged_pool=True,
    )

    def collect(self):
        for run in self.generate_memory_ranges():
            scanner = PoolScanMutant(profile=self.profile, session=self.session,
                                     address_space=run.address_space)

            for pool_obj in scanner.scan(run.start, run.length):
                for object_obj in pool_obj.IterObject("Mutant", freed=True):
                    object_name = object_obj.NameInfo.Name.v(
                        vm=self.kernel_address_space)

                    # By default we suppress non-named mutants because they are
                    # not very interesting.
                    if self.plugin_args.verbosity < 5 and not object_name:
                        continue

                    mutant = self.profile._KMUTANT(
                        object_obj.obj_end, vm=run.address_space)

                    if mutant.OwnerThread > 0x80000000:
                        thread = self.profile._ETHREAD(
                            offset=mutant.OwnerThread,
                            vm=self.kernel_address_space)

                        CID = "{0}:{1}".format(thread.Cid.UniqueProcess,
                                               thread.Cid.UniqueThread)
                    else:
                        CID = ""

                    yield dict(a='F' if pool_obj.FreePool else "",
                               offset=mutant.obj_offset,
                               ptr_no=object_obj.PointerCount,
                               hnd_no=object_obj.HandleCount,
                               signal=mutant.Header.SignalState,
                               thread=mutant.OwnerThread,
                               cid=CID,
                               name=object_obj.NameInfo.Name.v(
                                   vm=self.kernel_address_space))


class PoolScanProcess(common.PoolScanner):
    """PoolScanner for File objects"""

    # Kernel addresses are above this value.
    kernel = 0x80000000

    def __init__(self, **kwargs):
        super(PoolScanProcess, self).__init__(**kwargs)
        self.kernel = self.profile.get_constant_object(
            "MmSystemRangeStart", "Pointer").v() or 0x80000000

        self.checks = [
            # Must have the right pool tag.
            ('PoolTagCheck', dict(
                tag=self.profile.get_constant("EPROCESS_POOLTAG"))),

            # Must be large enough for an _EPROCESS.
            ('CheckPoolSize', dict(min_size=self.profile.get_obj_size(
                "_EPROCESS"))),

            # It seems that on old XP versions _EPROCESS was allocated from
            # paged pool but it's rare to see that.
            ('CheckPoolType', dict(
                paged=True, non_paged=True, free=True)),

            ('CheckPoolIndex', dict(value=0)),
        ]

        # The DTB is page aligned on AMD64 and I386 but aligned to 0x20
        # on PAE kernels.
        if self.session.kernel_address_space.metadata("pae"):
            self.dtb_alignment = 0x20
        else:
            self.dtb_alignment = 0x1000

    def scan(self, **kwargs):
        for pool_obj in super(PoolScanProcess, self).scan(**kwargs):
            # Also fetch freed objects.
            for object_header in pool_obj.IterObject("Process", freed=True):
                eprocess = object_header.Body.cast("_EPROCESS")

                if eprocess.Pcb.DirectoryTableBase == 0:
                    continue

                if eprocess.Pcb.DirectoryTableBase % self.dtb_alignment != 0:
                    continue

                # Pointers must point to the kernel part of the address space.
                list_head = eprocess.ActiveProcessLinks
                if (list_head.Flink < self.kernel or
                        list_head.Blink < self.kernel):
                    continue

                yield pool_obj, eprocess


class PSScan(common.WinScanner):
    """Scan Physical memory for _EPROCESS pool allocations.

    Status flags:
      E: A known _EPROCESS address from pslist.
      P: A known pid from pslist.
    """

    name = "psscan"

    table_header = [
        dict(name='a', width=1),
        dict(name="offset_p", type="_EPROCESS"),
        dict(name="offset_v", style="address"),
        dict(name="ppid", width=6, align="r"),
        dict(name="pdb", style="address"),
        dict(name='stat', width=4),
        dict(name="create_time", width=24),
        dict(name="exit_time", width=24),
    ]

    # Only bother to scan non paged pool by default.
    scanner_defaults = dict(
        scan_kernel_nonpaged_pool=True
    )

    def collect(self):
        """Render results in a table."""
        # Try to do a regular process listing so we can compare if the process
        # is known.
        pslist = self.session.plugins.pslist()

        # These are virtual addresses.
        known_eprocess = set()
        known_pids = set()
        for task in pslist.list_eprocess():
            known_eprocess.add(task)
            known_pids.add(task.UniqueProcessId)

        # Scan each requested run in turn.
        for run in self.generate_memory_ranges():
            # Just grab the AS and scan it using our scanner
            scanner = PoolScanProcess(session=self.session,
                                      profile=self.profile,
                                      address_space=run.address_space)

            for pool_obj, eprocess in scanner.scan(
                    offset=run.start, maxlen=run.length):
                if run.data["type"] == "PhysicalAS":
                    # Switch address space from physical to virtual.
                    virtual_eprocess = (
                        pslist.virtual_process_from_physical_offset(eprocess))
                else:
                    virtual_eprocess = eprocess

                known = ""
                if virtual_eprocess in known_eprocess:
                    known += "E"

                if eprocess.UniqueProcessId in known_pids:
                    known += "P"

                yield dict(a='F' if pool_obj.FreePool else "",
                           offset_p=eprocess,
                           offset_v=virtual_eprocess.obj_offset,
                           ppid=eprocess.InheritedFromUniqueProcessId,
                           pdb=eprocess.Pcb.DirectoryTableBase,
                           stat=known,
                           create_time=eprocess.CreateTime or '',
                           exit_time=eprocess.ExitTime or '')