This file is indexed.

/usr/lib/python2.7/dist-packages/rekall/plugins/common/memmap.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
# Rekall Memory Forensics
# Copyright 2015 Google Inc. All Rights Reserved.
#
# 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
#

"""This module implements core memmap/memdump plugins."""

__author__ = "Michael Cohen <scudette@gmail.com>"

from rekall import plugin
from rekall import utils
from rekall.ui import text
from rekall.plugins import core


class MemmapMixIn(object):
    """A Mixin to create the memmap plugins for all the operating systems."""

    @classmethod
    def args(cls, parser):
        """Declare the command line args we need."""
        super(MemmapMixIn, cls).args(parser)
        parser.add_argument(
            "--coalesce", default=False, type="Boolean",
            help="Merge contiguous pages into larger ranges.")

        parser.add_argument(
            "--all", default=False, type="Boolean",
            help="Use the entire range of address space.")

    def __init__(self, *pos_args, **kwargs):
        """Calculates the memory regions mapped by a process or the kernel.

        If no process filtering directives are provided, enumerates the kernel
        address space.
        """
        self.coalesce = kwargs.pop("coalesce", False)
        self.all = kwargs.pop("all", False)
        super(MemmapMixIn, self).__init__(*pos_args, **kwargs)

    def _render_map(self, task_space, renderer, highest_address):
        renderer.format(u"Dumping address space at DTB {0:#x}\n\n",
                        task_space.dtb)

        renderer.table_header([("Virtual", "offset_v", "[addrpad]"),
                               ("Physical", "offset_p", "[addrpad]"),
                               ("Size", "process_size", "[addr]")])

        if self.coalesce:
            ranges = task_space.merge_base_ranges()
        else:
            ranges = task_space.get_mappings()

        for run in ranges:
            # When dumping out processes do not dump the kernel.
            if not self.all and run.start > highest_address:
                break

            renderer.table_row(run.start, run.file_offset, run.length)

    def render(self, renderer):
        if not self.filtering_requested:
            # Dump the entire kernel address space.
            return self._render_map(self.kernel_address_space, renderer, 2**64)

        max_memory = self.session.GetParameter("highest_usermode_address")
        for task in self.filter_processes():
            renderer.section()
            renderer.RenderProgress("Dumping pid {0}".format(task.pid))

            task_space = task.get_process_address_space()
            renderer.format(u"Process: '{0}' pid: {1:6}\n\n",
                            task.name, task.pid)

            if not task_space:
                renderer.write("Unable to read pages for task.\n")
                continue

            self._render_map(task_space, renderer, max_memory)


class MemDumpMixin(core.DirectoryDumperMixin, MemmapMixIn):
    """Dump the addressable memory for a process.

    Note that because the addressable memory is sparse we do not maintain
    alignment in the output file. Instead, we also write an index file which
    describes all the sparse runs in the dump - but the dump file has all the
    data concatenated.
    """

    name = "memdump"

    def dump_process(self, eprocess, fd, index_fd):
        task_as = eprocess.get_process_address_space()
        temp_renderer = text.TextRenderer(session=self.session,
                                          fd=index_fd)
        with temp_renderer.start():
            temp_renderer.table_header([
                ("File Address", "file_addr", "[addrpad]"),
                ("Length", "length", "[addrpad]"),
                ("Virtual Addr", "virtual", "[addrpad]")])

            # Only dump the userspace portion of addressable memory.
            max_memory = self.session.GetParameter("highest_usermode_address")
            blocksize = 1024 * 1024

            for run in task_as.get_address_ranges(end=max_memory):
                for offset in utils.xrange(run.start, run.end, blocksize):
                    to_read = min(blocksize, run.end - offset)
                    if to_read == 0:
                        break

                    data = task_as.read(offset, to_read)
                    file_offset = fd.tell()
                    fd.write(data)

                    # Write the index file.
                    temp_renderer.table_row(file_offset, to_read, offset)


    def render(self, renderer):
        if self.dump_dir is None:
            raise plugin.PluginError("Dump directory not specified.")

        for task in self.filter_processes():
            renderer.section()
            filename = u"{0}_{1:d}.dmp".format(task.name, task.pid)

            renderer.format(u"Writing {0} to {1}\n",
                            task, filename)

            with renderer.open(directory=self.dump_dir,
                               filename=filename,
                               mode='wb') as fd:
                with renderer.open(directory=self.dump_dir,
                                   filename=filename + ".idx",
                                   mode='wb') as index_fd:
                    self.dump_process(task, fd, index_fd)