This file is indexed.

/usr/lib/python2.7/dist-packages/rekall/plugins/addrspaces/crash.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
# Rekall Memory Forensics
# Copyright (C) 2012
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Authors:
# Michael Cohen <scudette@gmail.com> based on code by
# {npetroni,awalters}@4tphi.net (Nick Petroni and AAron Walters)
#
# 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
#

"""An Address Space for processing crash dump files."""

from rekall import addrspace
from rekall.plugins.overlays.windows import crashdump

# pylint: disable=protected-access


class WindowsCrashDumpSpace32(addrspace.RunBasedAddressSpace):
    """ This Address Space supports windows Crash Dump format """
    order = 30

    PAGE_SIZE = 0x1000

    # Participate in Address Space voting.
    __image = True

    def __init__(self, **kwargs):
        super(WindowsCrashDumpSpace32, self).__init__(**kwargs)

        self.as_assert(self.base != None, "No base address space provided")

        self.offset = 0
        self.fname = ''

        # Check the file for sanity.
        self.check_file()

        file_offset = self.header.obj_size

        for run in self.header.PhysicalMemoryBlockBuffer.Run:
            self.add_run(int(run.BasePage) * self.PAGE_SIZE,
                         file_offset,
                         int(run.PageCount) * self.PAGE_SIZE)

            file_offset += run.PageCount * self.PAGE_SIZE

        self.session.SetCache(
            "dtb", int(self.header.DirectoryTableBase))

    def check_file(self):
        """Checks the base file handle for sanity."""

        self.as_assert(self.base,
                       "Must stack on another address space")

        # Must start with the magic PAGEDUMP
        self.as_assert((self.base.read(0, 8) == 'PAGEDUMP'),
                       "Header signature invalid")

        self.profile = crashdump.CrashDump32Profile(
            session=self.session)

        self.header = self.profile.Object(
            "_DMP_HEADER", offset=self.offset, vm=self.base)

        if self.header.DumpType != "Full Dump":
            # Here we rely on the WindowsCrashBMP AS to run before us. Therefore
            # we fail hard if this is not a valid legacy crash format.
            raise IOError("This is not a full memory crash dump. "
                          "Kernel crash dumps are not supported.")


class WindowsCrashDumpSpace64(WindowsCrashDumpSpace32):
    """This AS supports windows Crash Dump format."""
    order = 30

    # Participate in Address Space voting.
    __image = True

    def check_file(self):
        """Check specifically for 64 bit crash dumps."""

        # Must start with the magic PAGEDU64
        self.as_assert((self.base.read(0, 8) == 'PAGEDU64'),
                       "Header signature invalid")

        self.profile = crashdump.CrashDump64Profile(
            session=self.session)

        self.as_assert(self.profile.has_type("_DMP_HEADER64"),
                       "_DMP_HEADER64 not available in profile")
        self.header = self.profile.Object("_DMP_HEADER64",
                                          offset=self.offset, vm=self.base)

        # The following error is fatal - abort the voting mechanism.

        # Unfortunately Volatility does not set this field correctly, so we do
        # not make it a fatal error. It can lead to problems if we try to parse
        # other crash dump formats, (Especially Win8 ones - see below) so we
        # might consider making this a fatal error in future.
        if self.header.DumpType != "Full Dump":
            self.session.logging.warning(
                "This is not a full memory crash dump. Kernel crash dumps are "
                "not supported.")

        # Catch this error early or we will hog all memory trying to parse a
        # huge number of Runs. On Windows 8 we have observed the DumpType to be
        # == 5 and these fields are padded with "PAGE" (i.e. 0x45474150).
        if self.header.PhysicalMemoryBlockBuffer.NumberOfRuns > 100:
            raise RuntimeError(
                "This crashdump file format is not supported. Rekall does not "
                "currently support crashdumps using the Win8 format.")


class WindowsCrashBMP(addrspace.RunBasedAddressSpace):
    """This Address Space supports the new windows Crash Dump format.

    This format first appeared in Windows 8 x64 versions. We reversed this
    format by examining the Crash dump file from a Windows 8 system.

    Alternative implementations:
      Volatility 2.4: crashbmp.py (not working at time of writing.).
    """
    # Must try this before the old Crashdump format.
    order = 25

    PAGE_SIZE = 0x1000

    # Participate in Address Space voting.
    __image = True

    def __init__(self, **kwargs):
        super(WindowsCrashBMP, self).__init__(**kwargs)

        self.as_assert(self.base, "Must stack on another address space")

        # Must start with the magic PAGEDU64
        self.as_assert((self.base.read(0, 8) == 'PAGEDU64'),
                       "Header signature invalid")

        self.profile = crashdump.CrashDump64Profile(
            session=self.session)

        self.header = self.profile.Object("_DMP_HEADER64", vm=self.base)
        self.as_assert(
            self.header.DumpType == "BMP Dump", "Only BMP dumps supported.")

        self.bmp_header = self.header.BMPHeader
        PAGE_SIZE = 0x1000

        # First run [Physical Offset, File Offset, Run length]
        first_page = self.bmp_header.FirstPage.v()
        last_run = [0, first_page, 0]

        for pfn, present in enumerate(self._generate_bitmap()):
            if present:
                if pfn * PAGE_SIZE == last_run[0] + last_run[2]:
                    last_run[2] += PAGE_SIZE

                else:
                    # Dump the last run only if it has non zero length.
                    if last_run[2] > 0:
                        self.add_run(*last_run)

                    # The next run starts here.
                    last_run = [
                        pfn * PAGE_SIZE, last_run[1] + last_run[2], PAGE_SIZE]

        # Flush the last run if needed.
        if last_run[2] > 0:
            self.add_run(*last_run)

        # Set the DTB from the crash dump header.
        self.session.SetCache("dtb", self.header.DirectoryTableBase.v(),
                         volatile=False)


    def _generate_bitmap(self):
        """Generate Present/Not Present for each page in the dump."""
        # The bitmap is an array of 32 bit integers. Each bit in each int
        # represents a single memory page.
        for value in self.bmp_header.Bitmap:
            # This is kind of lame but in python it is way faster than bit
            # manipulations.
            for bit in reversed("{0:032b}".format((value.v()))):
                yield bit == "1"