/usr/lib/python2.7/dist-packages/rekall/plugins/windows/registry/evtlogs.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 | # Rekall Memory Forensics
# Copyright (C) 2008-2011 Volatile Systems
# Copyright (C) 2011 Jamie Levy (Gleeda) <jamie.levy@gmail.com>
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Additional Authors:
# Michael Cohen <scudette@gmail.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
#
"""
@author: Jamie Levy (gleeda)
@license: GNU General Public License 2.0 or later
@contact: jamie.levy@gmail.com
@organization: Volatile Systems
"""
import ntpath
from rekall import obj
from rekall import scan
from rekall import utils
from rekall.plugins.windows.registry import registry
from rekall.plugins.windows.registry import getsids
# for more information on Event Log structures see WFA 2E pg 260-263 by Harlan
# Carvey
evt_log_types = {
'EVTLogHeader' : [0x30, {
'HeaderSize' : [0x0, ['unsigned int']],
'Magic' : [0x4, ['String', dict(length=4)]], # LfLe
# Offset of oldest record.
'OffsetOldest' : [0x10, ['int']],
# Offset of next record to be written.
'OffsetNextToWrite' : [0x14, ['int']],
'NextID' : [0x18, ['int']], # Next event record ID.
'OldestID' : [0x1c, ['int']], # Oldest event record ID.
# Maximum size of event record (from registry).
'MaxSize' : [0x20, ['int']],
# Retention time of records (from registry).
'RetentionTime' : [0x28, ['int']],
# Size of the record (repeat of DWORD at offset 0).
'RecordSize' : [0x2c, ['int']],
}],
'EVTRecordStruct' : [0x38, {
'RecordLength' : [0x0, ['int']],
'Magic' : [0x4, ['String', dict(length=4)]], # LfLe
'RecordNumber' : [0x8, ['int']],
'TimeGenerated' : [0xc, ['UnixTimeStamp']],
'TimeWritten' : [0x10, ['UnixTimeStamp']],
# Specific to event source and uniquely identifies the event.
'EventID' : [0x14, ['unsigned short']],
'EventType' : [0x18, ['Enumeration', dict(
target='unsigned short',
choices={0x01: "Error",
0x02: "Warning",
0x04: "Info",
0x08: "Success",
0x10: "Failure"})]],
# Number of description strings in event message.
'NumStrings' : [0x1a, ['unsigned short']],
'EventCategory' : [0x1c, ['unsigned short']],
'ReservedFlags' : [0x1e, ['unsigned short']],
'ClosingRecordNum' : [0x20, ['int']],
# Offset w/in record of description strings.
'StringOffset' : [0x24, ['int']],
# Length of SID: if 0 no SID is present.
'SidLength' : [0x28, ['int']],
# Offset w/in record to start of SID (if present).
'SidOffset' : [0x2c, ['int']],
# Length of binary data of record.
'DataLength' : [0x30, ['int']],
# Offset of data w/in record.
'DataOffset' : [0x34, ['int']],
'Source': [0x38, ['UnicodeString', dict(
length=lambda x: x.RecordLength)]],
# The computer name is right after the Source.
'Computer': [lambda x: x.Source.obj_offset + x.Source.obj_size,
['UnicodeString', dict(
length=lambda x: x.RecordLength)]],
'Sid': [lambda x: x.obj_offset + x.SidOffset.v(), ['_SID']],
'Data':[lambda x: x.obj_offset + x.StringOffset.v(), [
"ListArray", dict(
target="UnicodeString",
target_args=dict(encoding="utf16"),
maximum_size=lambda x: x.RecordLength,
count=lambda x: x.NumStrings)]],
}],
"_SID": [None, {
"IdentifierAuthority": [None, ["Enumeration", dict(
choices={
"\x00\x00\x00\x00\x00\x00": "Null Authority",
"\x00\x00\x00\x00\x00\x01": "World Authority",
"\x00\x00\x00\x00\x00\x02": "Local Authority",
"\x00\x00\x00\x00\x00\x03": "Creator Authority",
"\x00\x00\x00\x00\x00\x04": "NonUnique Authority",
"\x00\x00\x00\x00\x00\x05": "NT Authority",
},
target="String",
target_args=dict(length=6, term=None)
)]],
"NumericIdentifier": [0x4, ["unsigned be int"]],
"SubAuthority": [None, ["Array", dict(
target="unsigned long",
count=lambda x: x.SubAuthorityCount)]],
}],
}
class _SID(obj.Struct):
"""A Pretty printing implementation of sids.
Reference:
http://www.sekchek.com/downloads/white-papers/windows-about-sids.pdf
"""
def __unicode__(self):
"""Format the Sid using SDDL Notation."""
components = [self.Revision, self.NumericIdentifier]
components.extend(self.SubAuthority)
result = u"S-" + u"-".join([str(x) for x in components])
# Try to resolve a friendly name from the cache in the context.
friendly_name = self.obj_context.get("sid_cache", {}).get(result)
if friendly_name:
result = u"%s (%s)" % (result, friendly_name)
return result
class EVTObjectTypes(obj.ProfileModification):
"""An implementation for parsing event logs."""
@classmethod
def modify(cls, profile):
profile.add_overlay(evt_log_types)
profile.add_classes(dict(_SID=_SID))
class EVTScanner(scan.BaseScanner):
checks = [('StringCheck', dict(needle="LfLe"))]
def scan(self, offset, maxlen=None, context=None):
for hit in super(EVTScanner, self).scan(offset, maxlen=maxlen):
event_offset = hit - self.profile.get_obj_offset(
"EVTRecordStruct", "Magic")
event = self.profile.EVTRecordStruct(
offset=event_offset, vm=self.address_space, context=context)
# Eliminate crazy events (between 2001 and 2017):
if (1500000000 > event.TimeGenerated > 1000000000 and
1500000000 > event.TimeWritten > 1000000000):
yield event
class EvtLogs(registry.RegistryPlugin):
"""Extract Windows Event Logs (XP/2003 only)"""
name = "evtlogs"
mode = "mode_xp"
def __init__(self, **kwargs):
super(EvtLogs, self).__init__(**kwargs)
self.profile = EVTObjectTypes(self.profile)
self.context = dict(sid_cache={})
def FindEVTFiles(self):
"""Search for event log files in memory.
We search for processes called 'services.exe' with a vad to and open
file ending with '.evt'.
"""
ps_plugin = self.get_plugin("pslist", proc_regex="services.exe")
for task in ps_plugin.filter_processes():
for vad in task.RealVadRoot.traverse():
try:
filename = vad.ControlArea.FilePointer.FileName
if utils.SmartUnicode(filename).lower().endswith(".evt"):
yield task, vad
except AttributeError:
pass
def ScanEvents(self, vad, address_space):
scanner = EVTScanner(profile=self.profile, address_space=address_space,
session=self.session)
for event in scanner.scan(offset=vad.Start, maxlen=vad.Length,
context=self.context):
yield event
def PrecacheSids(self):
"""Search for known sids that we can cache."""
sid_cache = self.context["sid_cache"]
sid_cache.update(getsids.well_known_sids)
# Search for all known user sids.
for hive_offset in self.hive_offsets:
hive_address_space = registry.HiveAddressSpace(
base=self.kernel_address_space,
hive_addr=hive_offset, profile=self.profile)
reg = registry.Registry(
profile=self.profile, address_space=hive_address_space)
# We get the user names according to the name of the diretory where
# their profile is. This is not very accurate - should we check the
# SAM instead?
profiles = reg.open_key(
'Microsoft\\Windows NT\\CurrentVersion\\ProfileList')
for profile in profiles.subkeys():
path = profile.open_value("ProfileImagePath").DecodedData
if path:
sid_cache[utils.SmartUnicode(profile.Name)] = (
utils.SmartUnicode(ntpath.basename(path)))
# Search for all service sids.
getservicesids = self.get_plugin("getservicesids")
for sid, service_name in getservicesids.get_service_sids():
sid_cache[sid] = "(Service: %s)" % service_name
def render(self, renderer):
if self.plugin_args.verbosity > 5:
self.PrecacheSids()
renderer.table_header([("TimeWritten", "timestamp", ""),
("Filename", "filename", ""),
("Computer", "computer", ""),
("Sid", "sid", ""),
("Source", "source", ""),
("Event Id", "event_id", ""),
("Event Type", "event_type", ""),
("Message", "message", "")])
for task, vad in self.FindEVTFiles():
filename = ntpath.basename(
utils.SmartUnicode(vad.ControlArea.FilePointer.FileName))
for event in self.ScanEvents(vad, task.get_process_address_space()):
args = ";".join(
repr(utils.SmartStr(x)) for x in event.Data)
renderer.table_row(
event.TimeWritten,
filename,
event.Computer,
event.Sid,
event.Source,
event.EventID,
event.EventType,
args)
|