1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 __author__ = "Michael Cohen <scudette@google.com>"
21
22 """A Common mixin for implementing plugins based on scanning."""
23
24 from rekall import addrspace
25
26
28 """A mixin that implements scanner memory region selectors.
29
30 Most scanners are very similar - they search for specific byte patterns over
31 some sections of memory, validate those and present the results. Depending
32 on the type of structures searched for, different regions of memory need to
33 be looked at.
34
35 This mixin attempts to present a common interface to all scanning plugins,
36 where users may select different regions using common selector options, and
37 those will be generated automatically.
38
39 The plugin may select a set of default regions to scan, which are most
40 relevant to the specific data searched for, but the user may override the
41 defaults at all times.
42
43 NOTE: This plugin must be mixed with the specific OS's ProcessFilter
44 implementation in order to bring in standard process selectors.
45 """
46
47 __args = [
48 dict(name="scan_physical", default=False, type="Boolean",
49 help="Scan the physical address space only."),
50
51 dict(name="scan_kernel", default=False, type="Boolean",
52 help="Scan the entire kernel address space."),
53
54
55 dict(name="scan_process_memory", default=False, type="Boolean",
56 help="Scan all of process memory. Uses process selectors to "
57 "narrow down selections."),
58 ]
59
60 scanner_defaults = {}
61
63 """Return True if the user requested any specific regions."""
64 for k, v in self.plugin_args.items():
65 if k.startswith("scan_") and v:
66 return True
67
68 return False
69
71 """Parse the plugin args and generate memory ranges.
72
73 Yields rekall.addrspace.Run objects.
74 """
75 if not self.scan_specification_requested():
76
77 for k in self.plugin_args:
78 if k.startswith("scan_"):
79 self.plugin_args[k] = self.scanner_defaults.get(k, False)
80
81
82 if self.plugin_args.scan_physical:
83 yield addrspace.Run(
84 start=0, end=self.session.physical_address_space.end(),
85 address_space=self.session.physical_address_space,
86 data=dict(type="PhysicalAS"))
87
88
89 if self.plugin_args.scan_kernel:
90 yield addrspace.Run(
91 start=0, end=self.session.kernel_address_space.end(),
92 address_space=self.session.kernel_address_space,
93 data=dict(type="KernelAS"))
94
95
96 if self.plugin_args.scan_process_memory:
97
98
99 for task in self.filter_processes():
100 cc = self.session.plugins.cc()
101 with cc:
102
103 cc.SwitchProcessContext(task)
104 end = self.session.GetParameter("highest_usermode_address")
105 resolver = self.session.address_resolver
106 for module in sorted(resolver.GetAllModules(),
107 key=lambda x: x.start):
108
109
110 if module.start > end:
111 break
112
113 comment = "%s (%s), %s" % (
114 task.name, task.pid, module.name)
115
116 self.session.logging.info(
117 "Scanning %s (%s) in: %s [%#x-%#x]",
118 task.name, task.pid, comment,
119 module.start, module.end)
120
121 yield addrspace.Run(
122 start=module.start, end=module.end,
123 address_space=self.session.default_address_space,
124 data=dict(type=comment, module=module, task=task))
125