Skip to content

Commit 987ecaf

Browse files
authored
Merge pull request #1193 from volatilityfoundation/issues/issue1155
Initial draft of complete-vad vadyarascan
2 parents 1d4a27e + ac15840 commit 987ecaf

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

volatility3/framework/plugins/windows/vadyarascan.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class VadYaraScan(interfaces.plugins.PluginInterface):
1818
"""Scans all the Virtual Address Descriptor memory maps using yara."""
1919

2020
_required_framework_version = (2, 4, 0)
21-
_version = (1, 0, 1)
21+
_version = (1, 1, 0)
2222

2323
@classmethod
2424
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]:
@@ -32,11 +32,8 @@ def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]
3232
requirements.PluginRequirement(
3333
name="pslist", plugin=pslist.PsList, version=(2, 0, 0)
3434
),
35-
requirements.VersionRequirement(
36-
name="yarascanner", component=yarascan.YaraScanner, version=(2, 0, 0)
37-
),
3835
requirements.PluginRequirement(
39-
name="yarascan", plugin=yarascan.YaraScan, version=(1, 2, 0)
36+
name="yarascan", plugin=yarascan.YaraScan, version=(1, 3, 0)
4037
),
4138
requirements.ListRequirement(
4239
name="pid",
@@ -59,6 +56,8 @@ def _generator(self):
5956

6057
filter_func = pslist.PsList.create_pid_filter(self.config.get("pid", None))
6158

59+
sanity_check = 0x1000 * 0x1000 * 0x1000
60+
6261
for task in pslist.PsList.list_processes(
6362
context=self.context,
6463
layer_name=kernel.layer_name,
@@ -67,18 +66,34 @@ def _generator(self):
6766
):
6867
layer_name = task.add_process_layer()
6968
layer = self.context.layers[layer_name]
70-
for offset, rule_name, name, value in layer.scan(
71-
context=self.context,
72-
scanner=yarascan.YaraScanner(rules=rules),
73-
sections=self.get_vad_maps(task),
74-
):
75-
yield 0, (
76-
format_hints.Hex(offset),
77-
task.UniqueProcessId,
78-
rule_name,
79-
name,
80-
value,
81-
)
69+
for start, end in self.get_vad_maps(task):
70+
size = end - start
71+
if size > sanity_check:
72+
vollog.warn(
73+
f"VAD at 0x{start:x} over sanity-check size, not scanning"
74+
)
75+
continue
76+
77+
for match in rules.match(data=layer.read(start, end - start, True)):
78+
if yarascan.YaraScan.yara_returns_instances():
79+
for match_string in match.strings:
80+
for instance in match_string.instances:
81+
yield 0, (
82+
format_hints.Hex(instance.offset + start),
83+
task.UniqueProcessId,
84+
match.rule,
85+
match_string.identifier,
86+
instance.matched_data,
87+
)
88+
else:
89+
for offset, name, value in match.strings:
90+
yield 0, (
91+
format_hints.Hex(offset + start),
92+
task.UniqueProcessId,
93+
match.rule,
94+
name,
95+
value,
96+
)
8297

8398
@staticmethod
8499
def get_vad_maps(

volatility3/framework/plugins/yarascan.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __call__(
4343
self, data: bytes, data_offset: int
4444
) -> Iterable[Tuple[int, str, str, bytes]]:
4545
for match in self._rules.match(data=data):
46-
if self.st_object:
46+
if YaraScan.yara_returns_instances():
4747
for match_string in match.strings:
4848
for instance in match_string.instances:
4949
yield (
@@ -61,7 +61,7 @@ class YaraScan(plugins.PluginInterface):
6161
"""Scans kernel memory using yara rules (string or file)."""
6262

6363
_required_framework_version = (2, 0, 0)
64-
_version = (1, 2, 0)
64+
_version = (1, 3, 0)
6565

6666
# TODO: When the major version is bumped, take the opportunity to rename the yara_rules config to yara_string
6767
# or something that makes more sense
@@ -119,6 +119,14 @@ def get_yarascan_option_requirements(
119119
),
120120
]
121121

122+
@classmethod
123+
def yara_returns_instances(cls) -> bool:
124+
st_object = not tuple([int(x) for x in yara.__version__.split(".")]) < (
125+
4,
126+
3,
127+
)
128+
return st_object
129+
122130
@classmethod
123131
def process_yara_options(cls, config: Dict[str, Any]):
124132
rules = None

0 commit comments

Comments
 (0)