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 missing algorithm_oid from PE module #197

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion modules/module_pe.json
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,13 @@
{
"kind": "value",
"name": "algorithm",
"documentation": "Algorithm used for this signature. Usually \"sha1WithRSAEncryption\".",
"documentation": "String representation of the algorithm used for this signature. Usually \"sha1WithRSAEncryption\". It depends on the X.509 and PKCS#7 implementationss and possibly their versions, consider using algorithm_oid instead.",
"type": "s"
},
{
"kind": "value",
"name": "algorithm_oid",
"documentation": "Object ID of the algorithm used for this signature, expressed in numeric ASN.1 dot notation. The name contained in algorithm is derived from this value. The object id is expected to be stable across X.509 and PKCS#7 implementations and their versions.",
"type": "s"
},
{
Expand Down
18 changes: 18 additions & 0 deletions tests/cpp/parser_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7336,5 +7336,23 @@ rule iequals_expr
EXPECT_EQ(input_text, driver.getParsedFile().getTextFormatted());
}

TEST_F(ParserTests,
ParsePeSignaturesXAlgorithmOID) {
prepareInput(
R"(import "pe"

rule test_rule
{
condition:
pe.signatures[0].algorithm_oid == "1.2.840.113549.1.1.11"
}
)");

EXPECT_TRUE(driver.parse(input));
ASSERT_EQ(1u, driver.getParsedFile().getRules().size());

EXPECT_EQ(input_text, driver.getParsedFile().getTextFormatted());
}

}
}
21 changes: 21 additions & 0 deletions tests/python/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,3 +1986,24 @@ def test_include_file_and_import_in_regular_mode(self):
}
'''
self.assertEqual(expected, yara_file.text_formatted)


def test_parse_pe_signatures_x_algorithm_oid(self):
yara_file = yaramod.Yaramod().parse_string(parser_mode=yaramod.ParserMode.Regular, str=r'''import "pe"

rule test_rule {
condition:
pe.signatures[0].algorithm_oid == "1.2.840.113549.1.1.11"
}
''')

expected = r'''import "pe"

rule test_rule
{
condition:
pe.signatures[0].algorithm_oid == "1.2.840.113549.1.1.11"
}
'''

self.assertEqual(expected, yara_file.text_formatted)