Skip to content
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

feat: OLE CF and VBA modules implemented #274

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

davidmagnotti
Copy link

OLE CF (Object Linking and Embedding Compound File) format is a file format used for legacy Microsoft Office files, such as documents, workbooks, presentations, and others. It's also used with Visual Basic for Applications (VBA) which is known more commonly as Office macros.

I've implemented two modules for parsing OLE CF files and VBA. I've also expanded the dump command to allow dumping of file metadata such as stream metadata (OLE CF) and macros (VBA).

An example of how you could use this to identify the use of auto-execute macro method names like "Document_New":

import "vba"

rule detect_document_new
{
    condition:
        for any module in vba.module_code : (
            module matches /document_new/i
        )
}

- Added support for parsing OLE CF and VBA (macro-enabled Office) files.
Copy link
Member

@plusvic plusvic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. This goes in the right direction, but I think it requires a bit of rewrite to make it more similar to other existing modules that use the nom crate for parsing binary files. The nom crate makes parsing complex data strucuture easier, and removes boilerplate code like the read_u32 and read_u16 functions.

lib/src/modules/vba/mod.rs Outdated Show resolved Hide resolved
lib/src/modules/olecf/parser.rs Outdated Show resolved Hide resolved
lib/src/modules/olecf/mod.rs Show resolved Hide resolved
repeated string module_names = 2;

// Type of each module (standard, class, form)
repeated string module_types = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using constant strings use enums.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually consistent with existing modules like Lnk. We're not using an enum because it's just integer typing for metadata.

repeated string module_types = 3;

// The actual VBA code for each module
repeated string module_code = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually repeated? If so, the name is a bit misleading considering that module_names and module_types are in plural form and this is singular.

@davidmagnotti
Copy link
Author

Thank you. While I can address most of the comments in another revision soon, I've been experimenting with using nom and realistically I won't have bandwidth to refactor the code from the current read_u16/read_u32 approach used in each module to use nom any time soon. Any chance we may be able to merge and address in a refactor later?

@plusvic
Copy link
Member

plusvic commented Dec 30, 2024

I prefer to maintain a separate development branch until the nom rewrite is done and not merging the code until it gets a bit more stable. I think I can the nom part in a few weeks.

- Adjusted modules to use `nom`.
- Added links to specifications.
- Fixed issue with copying entire input data in the VBA module.
@davidmagnotti
Copy link
Author

I prefer to maintain a separate development branch until the nom rewrite is done and not merging the code until it gets a bit more stable. I think I can the nom part in a few weeks.

I (unexpectedly) found some more time to put into this :-) does the re-work match your expectations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants