/usr/lib/python2.7/dist-packages/rekall/plugins/windows/shimcache.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 | # Rekall Memory Forensics
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Authors:
# 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
#
""" Shimcache plugin.
This code is based on work by:
# Authors:
# Volatility Plugin Development
# * Fred House - Mandiant, a FireEye Company
# Twitter: @0xF2EDCA5A
#
# Windows Shimcache Analysis
# * Andrew Davis - Mandiant, a FireEye Company
# * Claudiu Teodorescu - FireEye Inc.
# - Twitter: @cteo1
https://github.com/fireeye/Volatility-Plugins.git
and the paper:
https://www.fireeye.com/blog/threat-research/2015/10/shim_shady_live_inv/shim-shady-part-2.html
"""
import itertools
from rekall import plugin
from rekall.plugins.windows import common
# Add overlays
shimcache_win7_x64 = {
"SHIM_CACHE_ENTRY": [None, {
"ListEntry" : [0x0, ["_LIST_ENTRY"]],
"Path" : [0x10, ["_UNICODE_STRING"]],
"LastModified": [0x20, ["WinFileTime"]],
"InsertFlags": [0x28, ["unsigned int"]],
"ShimFlags": [0x2c, ["unsigned int"]],
"BlobSize": [0x30, ["unsigned long long"]],
"BlobBuffer" : [0x38, ["unsigned long"]],
}],
}
shimcache_win7_x86 = {
"SHIM_CACHE_ENTRY": [None, {
"ListEntry" :[0x0, ["_LIST_ENTRY"]],
"Path" : [0x08, ["_UNICODE_STRING"]],
"LastModified" : [0x10, ["WinFileTime"]],
"InsertFlags": [0x18, ["unsigned int"]],
"ShimFlags": [0x1c, ["unsigned int"]],
"BlobSize": [0x20, ["unsigned long long"]],
"BlobBuffer" : [0x24, ["unsigned long"]],
}],
}
shimcache_xp_x86 = {
"SHIM_CACHE_HEADER": [None, {
"Magic": [0, ["unsigned int"]],
"MaxEntries": [0x4, ["unsigned int"]],
"TotalEntries": [0x8, ["unsigned int"]],
"LRU": [0x10, ["Array", dict(
target="unsigned int",
count=lambda x: x.TotalEntries
)]],
"Entries": [0x190, ["Array", dict(
count=lambda x: x.TotalEntries,
target="SHIM_CACHE_ENTRY",
)]],
}],
"SHIM_CACHE_ENTRY" : [0x228, {
"Path" : [0x0, ["UnicodeString", dict(length=0x208)]],
"LastModified" : [0x210, ["WinFileTime"]],
"FileSize": [0x218, ["long long"]],
"LastUpdate" : [0x220, ["WinFileTime"]],
}],
}
shimcache_win8_x64 = {
"SHIM_CACHE_ENTRY_DETAIL": [None, {
"LastModified": [0x0, ["WinFileTime"]],
"InsertFlags": [0x08, ["unsigned int"]],
"ShimFlags": [0x0c, ["unsigned int"]],
"BlobSize": [0x10, ["unsigned long long"]],
"Padding": [0x18, ["unsigned long long"]],
"BlobBuffer": [0x20, ["unsigned long long"]],
}],
"SHIM_CACHE_ENTRY": [None, {
"ListEntry" : [0x0, ["_LIST_ENTRY"]],
"Path": [0x18, ["_UNICODE_STRING"]],
"ListEntryDetail": [0x38, ["Pointer", dict(
target="SHIM_CACHE_ENTRY_DETAIL"
)]],
}],
}
shimcache_win8_x86 = {
"SHIM_CACHE_ENTRY_DETAIL": [None, {
"LastModified": [0x0, ["WinFileTime"]],
"InsertFlags": [0x08, ["unsigned int"]],
"ShimFlags": [0x0c, ["unsigned int"]],
"BlobSize": [0x10, ["unsigned long"]],
"BlobBuffer": [0x14, ["unsigned long"]],
}],
"SHIM_CACHE_ENTRY": [None, {
"ListEntry": [0x0, ["_LIST_ENTRY"]],
"Path": [0x10, ["_UNICODE_STRING"]],
"ListEntryDetail": [0x20, ["Pointer", dict(
target="SHIM_CACHE_ENTRY_DETAIL"
)]],
}],
}
shimcache_win10_x64 = {
"SHIM_CACHE_ENTRY": [None, {
"ListEntry" : [0x0, ["_LIST_ENTRY"]],
"Path": [0x18, ["_UNICODE_STRING"]],
"ListEntryDetail" : [0x28, ["Pointer", dict(
target="SHIM_CACHE_ENTRY_DETAIL"
)]],
}],
"SHIM_CACHE_ENTRY_DETAIL" : [None, {
"LastModified": [0x08, ["WinFileTime"]],
"BlobSize": [0x10, ["unsigned long"]],
"BlobBuffer": [0x18, ["unsigned long long"]],
}],
"SHIM_CACHE_HANDLE": [0x10, {
"eresource": [0x0, ["Pointer", dict(target="_ERESOURCE")]],
"avl_table": [0x8, ["Pointer", dict(target="_RTL_AVL_TABLE")]],
}],
}
def AddShimProfiles(profile):
profile = profile.copy()
# Windows 7 uses this constant to store the shimcache.
if profile.get_constant("g_ShimCache"):
if profile.metadata("arch") == "AMD64":
profile.add_overlay(shimcache_win7_x64)
else:
profile.add_overlay(shimcache_win7_x86)
# Windows XP:
elif 5 < profile.metadata("version") < 6:
if profile.metadata("arch") == "I386":
profile.add_overlay(shimcache_xp_x86)
# Windows 8 uses a special driver to hold the cache.
elif profile.get_constant("AhcCacheHandle"):
if profile.metadata("arch") == "AMD64":
profile.add_overlay(shimcache_win8_x64)
else:
profile.add_overlay(shimcache_win8_x86)
# Windows 10 uses a special driver to hold the cache.
elif profile.session.address_resolver.get_address_by_name("ahcache"):
if profile.metadata("arch") == "AMD64":
profile.add_overlay(shimcache_win10_x64)
else:
raise plugin.PluginError("Unable to identify windows version.")
return profile
class ShimCacheMem(common.AbstractWindowsCommandPlugin):
"""Extract the Application Compatibility Shim Cache from kernel memory."""
name = "shimcachemem"
table_header = [
dict(name="Shim", style="address"),
dict(name="last_mod", width=30),
dict(name="last_update", hidden=True),
dict(name="size", width=10),
dict(name="Path")
]
def collect_xp(self):
"""Fetch the shimcache from XP.
According to the paper, on XP the cache is in shared memory inside the
process winlogon.exe. The cache begins with a header and a magic value
of 0xDEADBEEF.
For some reason the algorithm explained in the paper seems unnecessarily
complex. In Rekall we just search for a handle to the ShimCacheMemory
section object and use it.
"""
for row in self.session.plugins.handles(proc_regex="winlogon",
object_types="Section"):
if "ShimSharedMemory" in row["details"]:
# Found the section object.
section = row["_OBJECT_HEADER"].Object
# This is the process that created the shared object.
process_owner = section.Segment.u1.CreatingProcess.deref()
va = section.Segment.u2.FirstMappedVa.v()
if unicode(process_owner.name).lower() != u"winlogon.exe":
continue
# Switch to that process's context.
with self.session.plugins.cc() as cc:
cc.SwitchProcessContext(process_owner)
header = self.profile.SHIM_CACHE_HEADER(va)
return header.Entries
return []
def collect_from_avl_table(self, avl_table):
seen = set()
for node in avl_table.BalancedRoot.traverse_children():
entry = node.payload("SHIM_CACHE_ENTRY")
if entry.obj_offset in seen:
continue
seen.add(entry.obj_offset)
yield entry
# Sometimes there are some entries in the linked lists too.
for subentry in entry.ListEntry.list_of_type(
"SHIM_CACHE_ENTRY", "ListEntry"):
if subentry.obj_offset in seen:
continue
seen.add(subentry.obj_offset)
yield subentry
def collect_win7(self):
avl_table = self.profile.get_constant_object(
"g_ShimCache", "_RTL_AVL_TABLE")
return self.collect_from_avl_table(avl_table)
def collect_win8(self):
header_pointer = self.session.address_resolver.get_constant_object(
"nt!AhcCacheHandle", "Pointer")
avl_table = header_pointer.dereference_as("_RTL_AVL_TABLE",
profile=self.profile)
return self.collect_from_avl_table(avl_table)
def collect_win10(self):
header_pointer = self.session.address_resolver.get_constant_object(
"ahcache!AhcCacheHandle", "Pointer")
header = header_pointer.dereference_as("SHIM_CACHE_HANDLE",
profile=self.profile)
return self.collect_from_avl_table(header.avl_table)
def collect(self):
# We need this module's symbols.
self.session.address_resolver.track_modules("ahcache")
self.profile = AddShimProfiles(self.session.profile)
for entry in itertools.chain(self.collect_win10(),
self.collect_win8(),
self.collect_win7(),
self.collect_xp()):
# This field has moved around a bit between versions.
last_modified = entry.multi_m(
"LastModified",
"ListEntryDetail.LastModified"
)
if last_modified == 0 or last_modified == None:
continue
yield dict(Shim=entry,
last_mod=last_modified,
last_update=entry.m("LastUpdate"),
size=entry.m("FileSize"),
Path=entry.Path)
|