1 """Windows specific response plugins."""
2 import itertools
3 import re
4 import win32api
5 import pythoncom
6 import win32com.client
7
8 from rekall import plugin
9 from rekall import obj
10 from rekall_lib import utils
11 from rekall.plugins.common import address_resolver
12 from rekall.plugins.response import common
13 from rekall.plugins.windows import address_resolver as win_address_resolver
17 """List all the drives on this system."""
18 drives = win32api.GetLogicalDriveStrings()
19 return [x.rstrip("\\") for x in drives.split('\000') if x]
20
23 """Represent WMI result."""
24
25
26
27 IGNORE_PROPS = ["CSCreationClassName", "CreationClassName", "OSName",
28 "OSCreationClassName", "WindowsVersion", "CSName",
29 "__NAMESPACE", "__SERVER", "__PATH"]
30
32 super(WmiResult, self).__init__()
33 for prop in itertools.chain(
34 result.Properties_,
35
36 getattr(result, "SystemProperties_", [])):
37 if prop.Name not in self.IGNORE_PROPS:
38 self[prop.Name] = prop.Value
39
40
41 -class Wmi(common.AbstractIRCommandPlugin):
42 """Executes a WMI query and returns results."""
43 name = "wmi"
44
45 __args = [
46 dict(name="query", positional=True,
47 help="WMI query to execute"),
48 dict(name="baseobj", default=r"winmgmts:\root\cimv2",
49 help="The base object to query")
50 ]
51
52 table_header = [
53 dict(name="Result")
54 ]
55
57 return dict(Result=utils.AttributeDict())
58
60
61 pythoncom.CoInitialize()
62
63 wmi_obj = win32com.client.GetObject(self.plugin_args.baseobj)
64
65
66
67 wmi_obj.Security_.Privileges.AddAsString("SeDebugPrivilege")
68
69
70 try:
71 query_results = wmi_obj.ExecQuery(self.plugin_args.query)
72 except pythoncom.com_error as e:
73 raise plugin.PluginError(
74 "Failed to run WMI query \'%s\' err was %s" % (
75 self.plugin_args.query, e))
76
77
78 try:
79 for result in query_results:
80 yield dict(Result=WmiResult(result))
81
82 except pythoncom.com_error as e:
83 raise plugin.PluginError(
84 "WMI query data error on query \'%s\' err was %s" %
85 (e, self.plugin_args.query))
86
116
130
131
132
133 common.FILE_SPEC_DISPATCHER["API"] = WindowsFileInformation
134
135
136 -class LiveModule(win_address_resolver.PEModule):
137 """Address resolver modules accessed through APIs."""
138
139 - def __init__(self, vad=None, session=None):
151
152
153 -class WinAPIAddressResponse(address_resolver.AddressResolverMixin,
154 common.AbstractAPICommandPlugin):
155 """Address resolver for windows API access."""
156
157 @staticmethod
159 result = unicode(module_name)
160 result = re.split(r"[/\\]", result)[-1]
161
162
163 result = result.split(".")[0]
164
165 return result.lower()
166
186