/usr/lib/python2.7/dist-packages/rekall/plugins/addrspaces/vmem.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 | # Rekall Memory Forensics
#
# Copyright (C) 2012 Nir Izraeli (nirizr at gmail dot com)
# Copyright 2012 Sebastien Bourdon-Richard
# Copyright 2013 Google Inc. All Rights Reserved.
# Authors:
# Sebastien Bourdon-Richard, Nir Izraeli
# Adapted for Rekall by Michael Cohen <scudette@google.com>.
#
# 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
#
from rekall import addrspace
from rekall import obj
from rekall import utils
from rekall.plugins.addrspaces import standard
from rekall.plugins.overlays import basic
# pylint: disable=protected-access
class VMemAddressSpace(addrspace.RunBasedAddressSpace):
__image = True
def __init__(self, base=None, **kwargs):
"""Currently this AS only supports files with the .vmem extension."""
self.as_assert(base != None, "No base address space provided")
self.as_assert(
getattr(base, "fname", "").endswith("vmem"),
"Only VMEM files supported.")
super(VMemAddressSpace, self).__init__(base=base, **kwargs)
vmss_location = base.fname[:-4] + "vmss"
try:
vmss_as = standard.FileAddressSpace(
filename=vmss_location, session=self.session)
except IOError:
# If we fail to open the vmss file it is not a proper vmem file.
raise addrspace.ASAssertionError
vmss_profile = VMWareProfile(session=self.session)
self.header = vmss_profile._VMWARE_HEADER(vm=vmss_as)
self.as_assert(
self.header.Magic in [
0xbed2bed0, 0xbad1bad1, 0xbed2bed2, 0xbed3bed3],
"Invalid VMware signature: {0:#x}".format(self.header.Magic))
# Fill in the runs list from the header.
virtual_offsets = self.header.GetTags("memory", "regionPPN")
file_offsets = self.header.GetTags("memory", "regionPageNum")
lengths = self.header.GetTags("memory", "regionSize")
for v, p, l in zip(virtual_offsets, file_offsets, lengths):
self.add_run(v * 0x1000, p * 0x1000, l * 0x1000)
class VMSSAddressSpace(addrspace.RunBasedAddressSpace):
"""Support ESX .vmsn file format.
The VMSN file format contains a set of metadata in the form of tags, grouped
by groups at the header. There is a lot of metadata but the most interesting
metadata for us is the metadata in the "memory" group.
The file includes a "memory.Memory" data blob which contains the entire
memory snapshot of the running machine. The memory blob is serialized into
the file as a single large blob but contains physical memory runs stored
back to back inside it.
The following tags are used:
- memory.regionsCount: Stores the total number of regions.
- memory.regionPPN: In an array of physical addresses for each physical
memory regions in the virtual machine (in pages).
- memory.regionSize: Is the size of each physical memory region (in pages).
- memory.regionPageNum: Is the offset into the memory.Memory blob for each
region (in pages). This may be omitted if there is only one region.
"""
__image = True
def __init__(self, base=None, **kwargs):
self.as_assert(base != None, "No base address space provided")
super(VMSSAddressSpace, self).__init__(base=base, **kwargs)
vmss_profile = VMWareProfile(session=self.session)
self.header = vmss_profile._VMWARE_HEADER(vm=self.base)
self.as_assert(
self.header.Magic in [
0xbed2bed0, 0xbad1bad1, 0xbed2bed2, 0xbed3bed3],
"Invalid VMware signature: {0:#x}".format(self.header.Magic))
region_count = self.header.GetTagsData("memory", "regionsCount")[0]
# Fill in the runs list from the header.
virtual_offsets = self.header.GetTagsData("memory", "regionPPN")
lengths = self.header.GetTagsData("memory", "regionSize")
# This represents a single memory blob stored in the output file. The
# regions are marked relative to this single blob.
memory = self.header.GetTagsData("memory", "Memory")[0]
mem_regions = self.header.GetTagsData("memory", "regionPageNum") or [0]
for v, l, m in zip(virtual_offsets, lengths, mem_regions):
self.add_run(
v * 0x1000, m * 0x1000 + memory.obj_offset, l * 0x1000)
# We should have enough regions here.
if region_count != len(list(self.runs)):
self.session.logging.error(
"VMSN file has incorrect number of runs %s, "
"should be %s", region_count, len(list(self.runs)))
class _VMWARE_HEADER(obj.Struct):
"""Add convenience methods to the header."""
def __init__(self, **kwargs):
super(_VMWARE_HEADER, self).__init__(**kwargs)
self.obj_context["version"] = self.Version
def PrintAllTags(self):
for group in self.Groups:
for tag in group.Tags:
print "%s.%s: %r" % (group.Name, tag.Name, tag.Data)
def GetTags(self, group_name, tag_name):
result = []
for group in self.Groups:
if group.Name != group_name:
continue
for tag in group.Tags:
if tag.Name != tag_name:
continue
result.append(tag)
return result
def GetTagsData(self, group_name, tag_name):
return [x.Data for x in self.GetTags(group_name, tag_name)]
class _VMWARE_GROUP(obj.Struct):
@utils.safe_property
def Tags(self):
tag = self.TagsPointer.deref()
while tag.NameLength > 0:
yield tag
tag = tag.Next()
class _VMWARE_TAG(obj.Struct):
DATA_MAP = {
1: "unsigned char",
2: "unsigned short",
4: "unsigned int",
8: "unsigned long long",
}
@utils.safe_property
def Data(self):
"""The data immediately follows the TagIndices array.
The size and type of the data is specified by the DataSize member. If
the DataSize takes on the special values 62 or 63, then the data is
described by an extended data descriptor (We call it
_VMWARE_EXTENDED_DATA64).
"""
# The data immediately follows the TagIndices array.
data_offset = self.TagIndices.obj_end
data_size = self.DataSize
# The Data member is described by an extended struct.
if data_size in (62, 63):
# Depending on the version, the extended struct changes.
if self.obj_context.get("Version") == 0:
return self.obj_profile._VMWARE_EXTENDED_DATA32(
data_offset, vm=self.obj_vm).Data
else:
return self.obj_profile._VMWARE_EXTENDED_DATA64(
data_offset, vm=self.obj_vm).Data
# Is the data member a simple type?
data_type = self.DATA_MAP.get(data_size)
if data_type:
return self.obj_profile.Object(
data_type, offset=data_offset, vm=self.obj_vm)
# If the size is odd, we just return the data as a string.
return self.obj_profile.String(
offset=self.TagIndices.obj_end, term=None, length=data_size,
vm=self.obj_vm)
def Next(self):
"""The next tag is immediately after this tag."""
return self.obj_profile._VMWARE_TAG(
self.Data.obj_end, vm=self.obj_vm, context=self.obj_context)
class VMWareProfile(basic.BasicClasses):
"""A profile for parsing VMWare structures."""
@classmethod
def Initialize(cls, profile):
super(VMWareProfile, cls).Initialize(profile)
basic.ProfileLLP64.Initialize(profile)
profile.add_overlay({
'_VMWARE_HEADER': [12, {
'Magic': [0, ['unsigned int']],
'Version': [0, ["BitField", dict(
start_bit=0,
end_bit=4,
target="unsigned int")]],
'GroupCount': [8, ['unsigned int']],
'Groups': [12, ['Array', dict(
count=lambda x: x.GroupCount,
target='_VMWARE_GROUP',
)]],
}],
'_VMWARE_GROUP': [80, {
'Name': [0, ['UnicodeString', dict(
length=64,
encoding='utf8')]],
# A pointer to a back to back list of tags within this
# group. Note tags are variable length - to get the next tag use
# _VMWARE_TAG.Next(), or simply use the _VMWARE_GROUP.Tags()
# iterator as a convenience.
'TagsPointer': [64, ['Pointer', dict(
target="_VMWARE_TAG"
)]],
}],
# This struct is used to denote data objects with a length 62 bytes
# or greater.
'_VMWARE_EXTENDED_DATA64': [None, {
'DataDiskSize': [0, ['unsigned long long']],
'DataMemSize': [8, ['unsigned long long']],
# A padding string is specified as a short before the actual
# data.
'PaddingLen': [16, ['unsigned short']],
'Padding': [18, ['String', dict(
length=lambda x: x.PaddingLen,
term=None,
)]],
# The data follows the padding string. Its length is specified
# by DataDiskSize.
'Data': [lambda x: x.Padding.obj_end, ["String", dict(
term=None,
length=lambda x: x.DataDiskSize,
)]],
}],
# This is the old struct only used with Version 0. It is the same as
# _VMWARE_EXTENDED_DATA64 except uses 32 bit sizes.
'_VMWARE_EXTENDED_DATA32': [None, {
'DataDiskSize': [0, ['unsigned long']],
'DataMemSize': [4, ['unsigned long']],
'PaddingLen': [8, ['unsigned short']],
'Padding': [10, ['String', dict(
length=lambda x: x.PaddingLen,
term=None,
)]],
'Data': [lambda x: x.Padding.obj_end, ["String", dict(
term=None,
length=lambda x: x.DataDiskSize
)]],
}],
'_VMWARE_TAG': [None, {
'TagIndicesCount': [0, ['BitField', dict(
start_bit=6,
end_bit=9,
target="unsigned char")]],
'DataSize': [0, ['BitField', dict(
start_bit=0,
end_bit=6,
target="unsigned char")]],
# The name of this tag. Tags exist within the group (which also
# has a name).
'NameLength': [1, ['unsigned char']],
'Name': [2, ['UnicodeString', dict(
length=lambda x: x.NameLength,
encoding='utf8')]],
# The TagIndices immediately follow the Name field (Which has
# variable length).
'TagIndices': [lambda x: x.Name.obj_end,
['Array', dict(
count=lambda x: x.TagIndicesCount,
target='unsigned int')]],
}],
})
profile.add_classes(
_VMWARE_TAG=_VMWARE_TAG,
_VMWARE_GROUP=_VMWARE_GROUP,
_VMWARE_HEADER=_VMWARE_HEADER,
)
|