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

Add ability to use a dictionary when specifying Externals in yara-python #134

Open
tlansec opened this issue Apr 3, 2020 · 4 comments
Open

Comments

@tlansec
Copy link

tlansec commented Apr 3, 2020

Hello,

TLDR; Would it be possible to add Lists & Dictionaries as allowed types for Yara-python externals?

--

I've recently been looking at various ways to use the rich pattern matching and conditions from YARA to non-file use cases (e.g. where you just have metadata about a file, or an event, or anything really).

One thing that would be useful in my work is that sometimes I'm taking output from a tool which is by default a dictionary.

Since other native modules to YARA (such as PE) appear to effectively have dictionary structures available, would it be possible to allow use of dictionaries/lists in externals?

Then I could have say:

custom_externals = {"Events" : []}

yara.compile(source="some_rules.dat", externals=custom_externals)

Where each entry in Events is a dictionary, and then rules that look like this:

for any event in Events:
      event.event_id == 1 and 

Or a simpler case:

custom_externals = {"EventData" : {
                                       "defined_key": ""
                                        }
                                 }

And then rules like:

EventData.defined_key matches /foo/i or 
EventData.undefined_key matches /bar/i

--

Im not sure how plausible these suggestions are, or if they would be easier to implement in yara 4?

Cheers,
Tom

@tlansec
Copy link
Author

tlansec commented Apr 3, 2020

Apologies if I should have submitted this to the base YARA repo instead - please migrate it if necessary, or I can recreate there.

@tlansec
Copy link
Author

tlansec commented Nov 19, 2020

This has come up again in a discussion at $dayjob, I was wondering if this feature is possible/desirable or if there's some aspect of it that means its unlikely to ever be done (e.g. it is in conflict with the core way that the externals work).

@plusvic
Copy link
Member

plusvic commented Nov 20, 2020

This is doable but not easy. The reason is that external variables and variables defined by modules are not implemented in the same way, and they have different requirements. I'm leaving this issue open because it would be a nice addition, but I don't think I'm implementing it soon.

@tlansec
Copy link
Author

tlansec commented Nov 20, 2020

OK - thanks for the heads up 👍

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

No branches or pull requests

2 participants