-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
LNK Module #1957
LNK Module #1957
Conversation
The documentation says `Bytes [a-zA-Z] contribute 18 points each`, but it looks like in the code that only `[a-z]` is given 18 points, whereas `[A-Z]` is given 20 points. This commit will make sure these ranges have the proper scoring as expected.
Add test entry which compares the atom quality of "ABCD" and "abcd" and asserts that they are equal.
This reverts commit bf7130f.
This reverts commit 181dbf2.
This reverts commit 8123903.
This reverts commit 1c53212.
Also fixed `DWORD` compiling error, and replaced with `uint32_t` types.
Using the sample LNK from the MS standard for LNK files for testing, and putting in an initial test: https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/%5bMS-SHLLINK%5d.pdf
Previous version always seemed to be an hour (3600 seconds) off what it should have been. This commit adds a test to make sure it's getting the right value. I don't know why its always an hour off, but this should fix it!
All the mandatory LNK header bytes add up to 76 bytes, and as such we won't parse an LNK file unless it is at least 76 bytes in length
Moving a lot of the definitions over to a separate header file to keep the main code clean. Also following the PE module's structure of having a separate `lnk_utils` file to deal with some of the convenient functions it provides.
Attempting to update this temporarily in order to test big endian issues on this branch - revert before merging
This reverts commit 2120c7e.
The following build shows that all tests now pass as expected for big endian: https://github.com/VirusTotal/yara/actions/runs/5967961527/job/16190739595?pr=1957 I have reverted the changes back from the build YAML, and expect all tests to pass as expected now. Re-requesting review from @plusvic , thank you for your patience! |
@BitsOfBinary while porting the The same occurs with offset fields, which are useful while parsing the file for locating other structures and strings, but are probably not very relevant from the standpoint of a YARA rule creator. That's the case of:
..etc Let's use Moreover, some strings that may be very useful while creating YARA rules are exposed as an array of raw bytes, which often includes the null-terminator. For example, in the snippet below you can see that the value for the
Overall, my feeling is that this module is a low-level representation of a I would like to get some feedback from people who are already using the module or are interested in creating YARA rules for .lnk files. |
The deeper I delve into this matter, the more convinced I become that postponing the release of this module and waiting for the Rust implementation in YARA-X is the wiser choice. The intricacies of the LNK format far surpass initial expectations, presenting significant challenges for proper implementation in plain C. Notably, one of the complexities arises from the fact that nearly every string field in an LNK file can be presented in either ANSI or UTF-16 format. This has led to the creation of pairs of fields such as Both
To compound matters further, the value in
If your condition is To enhance the user-friendliness of the module, we should consider concealing this complexity from the end user by presenting a single |
Thank you for the detailed comments @plusvic . I agree on all the sentiments about wanting to make this module as user-friendly as possible. From your above comments, there are several things that can be done to achieve this, which is to:
That last point is probably the most complex out of these objectives, as you highlight. But perhaps the next draft of the module that can satisfy the above points will make it still worthy of inclusion in YARA itself vs. only applying it to YARA-X. I'm really glad you're doing a Rust implentation, as I'm convinced that a LNK module in YARA will be very beneficial (threat actors continue to use the file format, and imo the sooner we have a better way of parsing these files in YARA the better) - but I equally think you're right in making sure this module is as easy to use as possible. I will follow whatever you suggest when it comes to postponing the module or not, but given the time gap in months between previous pre-releases and official releases, I think we can potentially still get this module in a good state before v4.4.0 is released if you agree. |
After carefully weighing the pros and cons, I have made the decision to revert this PR and exclude the Rework Challenges: The lnk module necessitates significant revisions, as pointed out in previous comments. However, some of these changes are not straightforward within the C codebase and may demand a substantial amount of effort, particularly with regard to handling UTF-16 strings correctly. Compatibility Concerns: Maintaining compatibility between the Rust and C versions is anticipated to be a considerable challenge. This challenge extends beyond situations where an LNK file is successfully parsed; it also applies when parsing fails due to malformed files. Ideally, we would extract as much information as possible from the LNK file while bypassing corrupted structures. Nevertheless, ensuring that both versions behave consistently in such scenarios is exceptionally difficult and may not warrant the effort, potentially introducing some level of incompatibility between the two implementations. Adoption Considerations: Unlike other existing modules, this particular module has not gained significant adoption. Therefore, by postponing its publication and releasing only the Rust version, we can prevent potential compatibility issues in the future. Parsing Complexity: Parsing binary formats, especially in C, is a complex task. Based on my experience, the initial implementation almost always contains bugs that can cause YARA to crash when parsing corrupted files. If we were to publish the C version of the lnk module, we would commit to maintaining it in the future. However, I am hesitant to make that commitment at this time, as my primary focus is on the Rust implementation. I want to express that this decision was not made lightly. I genuinely appreciate the efforts you have invested in implementing the lnk module. Your work has not gone unnoticed, and it has played a crucial role in motivating me to port the module to Rust. Also, reverting the decision of not publishing the Thank you for your understanding, and please know that your contributions are valued and you can keep contributing with the Rust version of the module if you wish. |
Reopening to fix tests from previous PR: #1732