-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix up vmayarascan and vadyarascan to use yarascan properly #1371
base: develop
Are you sure you want to change the base?
Fix up vmayarascan and vadyarascan to use yarascan properly #1371
Conversation
This also fixes issues with the previous commit where windows code from vadyarascan made its way into vmayarascan, suggesting the review process isn't all that thorough... |
Thanks GitHub for shuffling the order of the comments in the review :(. |
Ok, lemme know if that's better... 5:) |
I've tested this and it seems to fix the issue in #1367 (volatility3) eve@xps:~/Documents/volatility3$ ./vol.py -f linux-sample-1.dmp linux.vmayarascan.VmaYaraScan --pid 1 --yara-string "
ELF"
Volatility 3 Framework 2.12.0
Progress: 100.00 Stacking attempts finished
Offset PID Rule Component Value
0x7f489741c001 1 r1 $a 45 4c 46
0x7f4897620001 1 r1 $a 45 4c 46
0x7f48979ab001 1 r1 $a 45 4c 46
0x7f4897e0b001 1 r1 $a 45 4c 46
0x7f4897e108f4 1 r1 $a 45 4c 46
0x7f4897e24151 1 r1 $a 45 4c 46
0x7f4897e24161 1 r1 $a 45 4c 46
0x7f4897e24583 1 r1 $a 45 4c 46
<snip> I confirmed those results in volshell - and it all appears to be in order.:
I've also tested it an actual fules file: (volatility3) eve@xps:~/Documents/volatility3$ ./vol.py -f linux-sample-1.dmp linux.vmayarascan.VmaYaraScan --yara-file ./rules.yar
Volatility 3 Framework 2.12.0
Progress: 100.00 Stacking attempts finished
Offset PID Rule Component Value
0x7fc90a315751 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a315766 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a31577e 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a315793 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a3157ac 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a3157c8 322 RegExpExample2 $re2 62 61 72 72
0x7fc90a3157e7 322 RegExpExample2 $re2 62 61 72 72
<snip> Then on windows too yara-string:
yara-file:
For reference rules.yar:
|
Thanks @eve-mem , so does that still solve the problem that the original vadyarascan/vmayarascan changes were made to resolve? |
e.g. a yara signature that needs the context of the entire VMA to produce a hit? I haven't yet tested that actually....! |
Ok, I just know we changed it by request because the scanning worked on blocks that were too small for context (ie, the rule needed to act across the whole vad, rather than just 16Mb chunks of it). I want to make sure we're not swapping one bug for another... 5;P |
That sounds sensible - I'm just running some tests on that now. |
No it doesn't seem to be working. I created a rule that should hit a specific vma. Using some strings at the start and the end of it. Although I'm not sure 'all of them' conditions worked before? I have to head out for a while - I can do more testing later. Extracting the VMAs and running yara on it manually produces a result as expected, but trying to use the vmayarascan plugin it doesn't seem to work. :( Here's the full testing if you wanted to recreate it:
Here is the rule I used for testing:
|
Ok, yep, seems it's still getting cut into 4096 byte blocks to be scanned. I think I'll need to make a BufferedScanner that can rechunk things. I've fixed up #1370 at least to work properly with both (previously it had a mistake of thinking the response was |
Glad you reminded me to even check... Let me know if there's anything else i can help with on this one. |
Great job! It turns out there was more to address. I've created a Linux test case for the latest bug using the steps provided by @eve-mem above. Feel free to incorporate it (or a similar version) into this PR. You may also want to include more detailed output validation. diff --git a/test/test_volatility.py b/test/test_volatility.py
index 847be88d9..e94761499 100644
--- a/test/test_volatility.py
+++ b/test/test_volatility.py
@@ -14,6 +14,7 @@ import tempfile
import hashlib
import ntpath
import json
+import contextlib
#
# HELPER FUNCTIONS
@@ -379,6 +381,42 @@ def test_linux_library_list(image, volatility, python):
assert rc == 0
+def test_linux_vmayarascan_yara_rule(image, volatility, python):
+ yara_rule_01 = r"""
+ rule fullvmayarascan
+ {
+ strings:
+ $s1 = "_nss_files_parse_grent"
+ $s2 = "/lib64/ld-linux-x86-64.so.2"
+ $s3 = "(bufferend - (char *) 0) % sizeof (char *) == 0"
+ condition:
+ all of them
+ }
+ """
+
+ # FIXME: When the minimum Python version includes 3.12, replace the following with:
+ # with tempfile.NamedTemporaryFile(delete_on_close=False) as fd: ...
+ fd, filename = tempfile.mkstemp(suffix=".yar")
+ try:
+ with os.fdopen(fd, "w") as f:
+ f.write(yara_rule_01)
+
+ rc, out, _err = runvol_plugin(
+ "linux.vmayarascan.VmaYaraScan",
+ image,
+ volatility,
+ python,
+ pluginargs=["--pid", "8600", "--yara-file", filename],
+ )
+ finally:
+ with contextlib.suppress(FileNotFoundError):
+ os.remove(filename)
+
+ out = out.lower()
+ assert out.count(b"\n") > 4
+ assert rc == 0
+
+ Regarding the unit tests, I'm not sure if we should have a separate test for each plugin's functionality or combine everything into one comprehensive test case. I chose the former, but it's up to you. If we go with a combined test, we'll need to merge the above code with the test case in my other PR here. |
This gets vmayarascan and vadyarascan to use the scanning framework properly, but hands in chunks that are the size of the complete vad.
This resolves issues around plugins needing to know about the version of vad whilst keeping the fix that led to the divergence...
Supercedes #1370.
Closes #1367