/usr/lib/python2.7/dist-packages/rekall/plugins/windows/pool.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 | # Rekall Memory Forensics
#
# Copyright 2016 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
"""Plugins to inspect the windows pools."""
__author__ = "Michael Cohen <scudette@google.com>"
# pylint: disable=protected-access
from rekall import obj
from rekall import utils
from rekall.plugins.windows import common
# Some pool related utility functions.
def find_pool_alloc_before(session, offset, pool_tag):
"""Searches address_space for a pool allocation containing offset."""
# This method is only effective for small allocations right now because we
# need to find a pool tag (so allocation size is limited to one page).
# TODO: Extend this to big page pools.
base_offset = offset & ~0xFFF
data = session.kernel_address_space.read(base_offset, offset & 0xFFF)
buffer_offset = offset % 0x1000
pool_header_prototype = session.profile._POOL_HEADER()
while 1:
buffer_offset = data.rfind(pool_tag, 0, buffer_offset)
if buffer_offset == -1:
break
result = session.profile._POOL_HEADER(
(base_offset + buffer_offset -
pool_header_prototype.PoolTag.obj_offset),
vm=session.kernel_address_space)
end_of_allocation = result.obj_offset + result.size
# Allocation encompasses the required offset.
if end_of_allocation > offset:
yield result.obj_end
# After searching in small allocation, assume this is an allocation from
# Big Pool and go back several pages.
while base_offset > offset - 0x10000:
yield base_offset
base_offset -= 0x1000
class Pools(common.WindowsCommandPlugin):
"""Prints information about system pools.
Ref:
http://illmatics.com/Windows%208%20Heap%20Internals.pdf
https://media.blackhat.com/bh-dc-11/Mandt/BlackHat_DC_2011_Mandt_kernelpool-wp.pdf
https://immunityinc.com/infiltrate/archives/kernelpool_infiltrate2011.pdf
http://gate.upm.ro/os/LABs/Windows_OS_Internals_Curriculum_Resource_Kit-ACADEMIC/WindowsResearchKernel-WRK/WRK-v1.2/base/ntos/ex/pool.c
"""
name = "pools"
_pool_lookup = None
table_header = [
dict(name="descriptor", width=20, style="address"),
dict(name="type", width=20),
dict(name="index", width=5),
dict(name="size", width=10, align="r"),
dict(name="start", style="address"),
dict(name="end", style="address"),
dict(name="comment")
]
def find_non_paged_pool(self):
vector_pool = self.profile.get_constant_object(
"PoolVector",
target="Array",
target_args=dict(
count=2,
target="Pointer",
)
)
resolver = self.session.address_resolver
for desc in vector_pool[0].dereference_as(
"Array",
target_args=dict(
count=self.profile.get_constant_object(
"ExpNumberOfNonPagedPools", "unsigned int").v(),
target="_POOL_DESCRIPTOR",
)
):
# Windows XP uses these globals.
start_va = resolver.get_constant_object(
"nt!MmNonPagedPoolStart", "Pointer").v()
end_va = resolver.get_constant_object(
"nt!MmNonPagedPoolEnd", "Pointer").v()
# Windows 7.
if start_va == None:
# First determine the addresses of non paged pool:
# dis 'nt!MiReturnNonPagedPoolVa'
start_va = resolver.get_constant_object(
"nt!MiNonPagedPoolStartAligned", "Pointer").v()
end_va = resolver.get_constant_object(
"nt!MiNonPagedPoolEnd", "Pointer").v()
if end_va == None:
bitmap = resolver.get_constant_object(
"nt!MiNonPagedPoolBitMap", "_RTL_BITMAP")
# ? MiNonPagedPoolVaBitMap
# We dont bother to check the bitmap itself, just consider the
# maximum size of the pool as the maximum allocated bitmap
# currently. This will overestimate the actual size somewhat.
end_va = start_va + bitmap.SizeOfBitMap * 8 * 0x1000
# In windows 10 the start va moved to the MiState global.
if start_va == None:
mistate = resolver.get_constant_object(
"nt!MiState", "_MI_SYSTEM_INFORMATION")
for node_index, node_info in enumerate(mistate.multi_m(
"Hardware.SystemNodeInformation", # Win10 2016
"SystemNodeInformation" # Win10 2015
)):
start_va = node_info.NonPagedPoolFirstVa.v()
end_va = start_va
# Just go to the last bitmap
for bitmap in node_info.NonPagedBitMap:
end_va = max(end_va, start_va + bitmap.SizeOfBitMap * 8)
desc.PoolStart = start_va
desc.PoolEnd = end_va
desc.Comment = "Node %i" % node_index
yield desc
else:
desc.PoolStart = start_va
desc.PoolEnd = end_va
desc.Comment = ""
yield desc
def find_paged_pool(self):
vector_pool = self.profile.get_constant_object(
"PoolVector",
target="Array",
target_args=dict(
count=2,
target="Pointer",
)
)
# Paged pool.
paged_pool_start = self.profile.get_constant_object(
"MmPagedPoolStart", "Pointer").v()
if paged_pool_start == None:
paged_pool_start = self.profile.get_constant_object(
"MiPagedPoolStart", "Pointer").v()
paged_pool_end = (
paged_pool_start + self.profile.get_constant_object(
"MmSizeOfPagedPoolInBytes", "address"))
if paged_pool_start == None:
# Windows 7 stores the end of the pool only
# (nt!MiFreePagedPoolPages).
paged_pool_end = self.profile.get_constant_object(
"MmPagedPoolEnd", "Pointer").v()
bitmap = self.profile.get_constant_object(
"MmPagedPoolInfo", "_MM_PAGED_POOL_INFO").PagedPoolAllocationMap
if bitmap:
paged_pool_start = (
paged_pool_end - bitmap.SizeOfBitMap * 8 * 0x1000)
else:
paged_pool_start = (
paged_pool_end - self.profile.get_constant_object(
"MmSizeOfPagedPoolInBytes", "unsigned long long"))
# Windows 10 build 10586.th2_release.160126-1819 uses dynamic Paged Pool
# VA.
if paged_pool_start == None:
mistate = self.session.address_resolver.get_constant_object(
"nt!MiState", "_MI_SYSTEM_INFORMATION")
dynamic_paged_pool = mistate.multi_m(
# 10586.th2_release.160126-1819
"SystemVa.DynamicBitMapPagedPool",
# 10074.fbl_impressive.150424-1350
"DynamicBitMapPagedPool"
)
paged_pool_start = dynamic_paged_pool.BaseVa.v()
paged_pool_end = (
paged_pool_start +
dynamic_paged_pool.MaximumSize * 0x1000)
comment = ""
if not paged_pool_start:
if self.profile.metadata("arch") == "I386":
# On Win7x86 the paged pool is distributed (see virt_map
# plugin).
comment = "Fragmented (See virt_map plugin)"
paged_pool_start = paged_pool_end = None
else:
# Hard coded on Windows 7.
# http://www.codemachine.com/article_x64kvas.html
# http://www.reactos.org/wiki/Techwiki:Memory_Layout
paged_pool_start = obj.Pointer.integer_to_address(
0xFFFFF8A000000000)
paged_pool_end = obj.Pointer.integer_to_address(
0xFFFFF8CFFFFFFFFF)
for desc in vector_pool[1].dereference_as(
"Array",
target_args=dict(
count=self.profile.get_constant_object(
"ExpNumberOfPagedPools", "unsigned int").v() + 1,
target="_POOL_DESCRIPTOR",
)
):
# Hard coded for 64 bit OS.
desc.PoolStart = paged_pool_start
desc.PoolEnd = paged_pool_end
desc.Comment = comment
yield desc
def find_session_pool_descriptors(self):
descriptors = {}
for task in self.session.plugins.pslist().list_eprocess():
desc = task.Session.PagedPool.cast(
vm=task.get_process_address_space())
if desc:
desc.PoolStart = task.Session.PagedPoolStart.v()
desc.PoolEnd = task.Session.PagedPoolEnd.v()
desc.Comment = "Session %s" % task.Session.SessionId
descriptors[desc.obj_offset] = desc
return descriptors.values()
def find_all_pool_descriptors(self):
"""Finds all unique pool descriptors."""
descriptors = set(self.find_non_paged_pool())
descriptors.update(self.find_paged_pool())
descriptors.update(self.find_session_pool_descriptors())
return descriptors
def is_address_in_pool(self, address):
if self._pool_lookup is None:
self._pool_lookup = utils.RangedCollection()
for descriptor in self.find_all_pool_descriptors():
self._pool_lookup.insert(descriptor.PoolStart,
descriptor.PoolEnd,
descriptor)
return self._pool_lookup.get_containing_range(address)
def collect(self):
descriptors = self.find_all_pool_descriptors()
for desc in sorted(descriptors):
yield dict(descriptor=desc,
type=desc.PoolType,
index=desc.PoolIndex,
size=desc.m("TotalBytes") or desc.TotalPages * 0x1000,
start=desc.PoolStart,
end=desc.PoolEnd,
comment=getattr(desc, "Comment", ""))
class PoolTracker(common.WindowsCommandPlugin):
"""Enumerate pool tag usage statistics."""
name = "pool_tracker"
table_header = [
dict(name="tag", width=4),
dict(name="nonpaged", width=20, align="r"),
dict(name="nonpaged_bytes", width=10, align="r"),
dict(name="paged", width=20, align="r"),
dict(name="paged_bytes", width=10, align="r"),
]
def collect(self):
table = self.profile.get_constant_object(
"PoolTrackTable",
target="Pointer",
target_args=dict(
target="Array",
target_args=dict(
count=self.profile.get_constant_object(
"PoolTrackTableSize", "unsigned int").v(),
target="_POOL_TRACKER_TABLE",
)
)
)
for item in table:
if item.Key == 0:
continue
self.session.report_progress()
yield (# Show the pool tag as ascii.
item.Key.cast("String", length=4),
"%s (%s)" % (item.NonPagedAllocs,
item.NonPagedAllocs - item.NonPagedFrees),
item.NonPagedBytes,
"%s (%s)" % (item.PagedAllocs,
item.PagedAllocs - item.PagedFrees),
item.PagedBytes,
)
|