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

Rule rebuild on plyara.utils.rebuild_yara_rule using external variable as a part of loop condition - bug #109

Open
rakovskij-stanislav opened this issue Aug 22, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rakovskij-stanislav
Copy link

rakovskij-stanislav commented Aug 22, 2020

Here is the case.

File test.txt:

test test test test test

rule:

rule sanity_check_external_variables {
    meta:
        author = "Rakovskij Stanislav / disasm.me"
        date = "22.08.2020"
    strings:
        $a = "test"
    condition:
        for count_of_test i in (1..#a) : ( @a[i] < 100 )
}

Sanity check using yara engine:

/testing_rules> yara d6.yar -d count_of_test=1 test.txt
sanity_check_external_variables test.txt
/testing_rules> yara d6.yar -d count_of_test=3 test.txt
sanity_check_external_variables test.txt
/testing_rules> yara d6.yar -d count_of_test=5 test.txt
sanity_check_external_variables test.txt
/testing_rules> yara d6.yar -d count_of_test=6 test.txt

Test case using plyara 2.1.1:

m = """rule sanity_check_external_variables {
    meta:
        author = "Rakovskij Stanislav / disasm.me"
        date = "22.08.2020"
    strings:
        $a = "test"
    condition:
        for count_of_test i in (1..#a) : ( @a[i] < 100 )
}
"""

parser = plyara.Plyara()
parser.parse_string(m)

y = plyara.utils.rebuild_yara_rule(parser.rules[0])
print(y)

Output:

rule sanity_check_external_variables
{
	meta:
		author = "Rakovskij Stanislav / disasm.me"
		date = "22.08.2020"

	strings:
		$a = "test"

	condition:
		for count_of_testi in (1..#a) : (@a[i]<100)
}

Expected condition: for count_of_test i in (1..#a) : (@a[i]<100)

I think the error is here - https://github.com/plyara/plyara/blob/master/plyara/utils.py#L470

To solve this problem you should check is this condition a part of for ... ... in block or not.

@utkonos
Copy link
Member

utkonos commented Aug 24, 2020

@rakovskij-stanislav Thanks for the report. I'll get this fixed.

@utkonos utkonos self-assigned this Aug 24, 2020
@utkonos utkonos added the bug Something isn't working label Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants