-
Notifications
You must be signed in to change notification settings - Fork 60
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
Trouble Accessing Bytes Member in Custom Module #306
Comments
Both 1 and 4 should work. YARA treats I've added some test cases in e3e2ba5 to make sure that string operations are working fine with arbitrary raw bytes, and it everything seems fine. |
@LloydLabs did you manage to find out why it wasn't working for you? Can I close this issue? |
Hey @plusvic, thanks for getting back to me. OK, I'll take a look back at the first case and debug it - because it certainly wasn't working as expected before. Should have a response in a few hours. |
The first one doesn't appear to work, I've added some debug statements to see what is going on: if let Some(body) = value.get("banner").and_then(Value::as_str) {
let engine = base64::engine::general_purpose::STANDARD;
match engine.decode(body) {
Ok(decoded_body) => {
// NOTE: temporarily for debugging purposes
for byte in &decoded_body {
print!("{:02X} ", byte);
}
println!();
tcp.body = Some(decoded_body);
}
Err(e) => {
eprintln!("Failed to decode base64 body: {}", e);
}
}
} I'm using this short script within import yara_x
rules = yara_x.compile(
"""
import "custom_module"
rule match_body_start {
condition:
custom_module.tcp.body startswith "\x01\x02\x03\x04"
}
"""
)
with open("input.json", "rb") as f:
results = rules.scan(f.read())
print(results.matching_rules[0].identifier) This outputs:
As can be seen, those bytes are there. However the rule is not matching on it with the escaped hex-string. Any help would be appreciated. I'm really unsure exactly what is going on here. |
For some reason the hex-string Module output from the debug print above confirms the bytes that it is populating the field with are correct: |
I'm not sure if that was a typo, but you said:
However notice the 9th in the string(after 0x33 0x5D), it's 0x88 instead of 0x8B. |
@LloydLabs any update on this? |
Hi folks,
I'm having trouble accessing a
bytes
member of a custom module that I have created within my rule. However, I can't seem to compare the value to any sort of byte array. The custom module parses the data, and populates the corresponding definition:Here is my protobuf definition for the field:
I have confirmed it is populating this fine, and I can match against normal strings. I seem to have trouble comparing this field to any sort of binary data. The
body
field data is transformed within the module (frombase64
), so in my tests, it isn't a simple$bytes
:Is there a way I can compare the
body
byte content against an arbitrary set of actual bytes? And if so, how can I use keywords such asstartswith
or evenin
for byte arrays to compare this field?Thank you all for the continued hard work on
yara-x
and the porting from the previous version,Best,
Lloyd.
The text was updated successfully, but these errors were encountered: