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

YARA reports incorrect errors in rules when a single rule is badly formatted #1294

Closed
tlansec opened this issue Jun 2, 2020 · 6 comments
Closed

Comments

@tlansec
Copy link
Contributor

tlansec commented Jun 2, 2020

Hi,

I've noticed that in YARA 4.0 an error early on in a rules file means erroneous errors are reported later in the rules file.

Here's an example rules file to illustrate the issue:

rule bad_condition
{
strings:
	$foo = "foo"
	$bar = "bar"
condition:
	all of them 
	filesize < 30KB
}

rule perfectlygood_rule
{
strings:
	$foo = "foo"
	$bar = "bar"
condition:
	$foo and 
        $bar and
	filesize < 30KB
}

Running this with YARA 4.0 yields:

tmp.yar(8): error in rule "bad_condition": syntax error, unexpected <filesize>, expecting '}'
tmp.yar(19): error in rule "bad_condition": unreferenced string "$foo"

Running with 3.11 yields the correct error message:

tmp.yar(8): error: syntax error, unexpected <filesize>, expecting '}'

In large rules files this problem is exacerbated.

Hope this is enough information to triage.

Cheers,
Tom

@r0ny123
Copy link

r0ny123 commented Jun 2, 2020

I think you have missed the "and" in the bad_condition rule.

@tlansec
Copy link
Contributor Author

tlansec commented Jun 2, 2020

Yes, that is deliberate to illustrate the issue.

YARA 4.0 reports a bug in the second (non bugged) rule, when the first rule contains a bug.

YARA 3.11 did not do this.

@r0ny123
Copy link

r0ny123 commented Jun 2, 2020

Ah, just checked. nice catch!

@wxsBSD
Copy link
Collaborator

wxsBSD commented Jun 2, 2020

We ran into this at work, I’m hoping to debug it this week.

plusvic added a commit that referenced this issue Jun 3, 2020
@plusvic
Copy link
Member

plusvic commented Jun 3, 2020

Fixed in 02e7c97

@plusvic plusvic closed this as completed Jun 3, 2020
@wxsBSD
Copy link
Collaborator

wxsBSD commented Jun 3, 2020

Thank you for the fix @plusvic - I woke up this morning expecting to dig into this and am happy I don't have to. :)

tarterp pushed a commit to mandiant/yara that referenced this issue Mar 31, 2022
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

4 participants