454 Commits
Author SHA1 Message Date
Hilko Bengen 6a9088ad05 Fix build failure for test programs on gcc-10 (#1464)
Previously, gcc (Debian 10.2.1-6) 10.2.1 20210110 gave the following
error message:

/usr/bin/ld: tests/util.o:(.data+0x0): multiple definition of `matches_blob_uses_default_iterator'; tests/test-arena.o:(.bss+0x0): first defined here
2021-03-11 09:33:28 +01:00
Victor M. Alvarez e4819f6b98 Fix issue #1443. (#1445)
* Fix issue #1443.

As pointed out in the bug report the way of aligning the win_cert pointer to the next 8-bytes boundary is not correct. If the previous certificates ends at 0x1234000A, the next one should start at 0x12340010, not at 0x1234000c which is not aligned to 8 bytes.
2021-02-08 22:04:52 +01:00
Victor M. Alvarez e293b8929e Fix broken test. 2021-02-04 16:15:50 +01:00
Victor M. Alvarez a07ec0812d Fix regression introduced in 94299eee38. 2021-01-29 12:15:59 +01:00
Victor M. Alvarez a1290f7b72 Fix dependencies for test_aligment in Bazel file. 2021-01-12 21:43:46 +01:00
Victor M. Alvarez b22283d30b Define "bool" as _Bool like stdbool.h does.
This tries to avoid nasty bugs caused by a different bool sizes. For example, the library is built with HAVE_STDBOOL_H defined, and some binary linking to the library is built without HAVE_STDBOOL_H, the library thinks that sizeof(bool) == sizeof(_Bool) == 1, while the binary thinks that sizeof(bool) == sizeof(int) == 4. This discrepancy in sizes can lead to data corruption.
2021-01-12 21:35:47 +01:00
Victor M. Alvarez ac5eae7137 Simplify test-rules by putting running the all the passes in a single binary.
This makes easier to build the tests with Bazel. Also fix some issues with Bazel configuration.
2021-01-12 20:52:55 +01:00
Victor M. Alvarez 5a9efc4716 Revert changes introduced in b7da5d2835.
See #1385 for a discussion about why this has been reverted back.
2021-01-07 15:18:19 +01:00
Victor M. Alvarez 1491f1a562 Fix issue #1435. 2021-01-07 11:26:03 +01:00
Victor M. Alvarez 0ffcba00a6 Set pe.overlay.offset to 0 for PE files that don't have an overlaid.
Until now pe.overlay.offset was undefined in such cases. For non-PE files this fields keep being undefined.
2021-01-07 10:17:37 +01:00
Victor M. Alvarez 4782d10257 Fix buffer overrun in dotnet module. 2021-01-05 10:52:15 +01:00
T3LS 398359bd0c Add dynsym objects to ELF module (#1427) 2020-12-24 13:31:34 +01:00
Victor M. AlvarezandSimon Hardy-Francis cba6932759 Implement non-blocking API (#1428)
With this change the yr_scanner_scan_mem_blocks function can return ERROR_BLOCK_NOT_READY when the YR_MEMORY_BLOCK_ITERATOR that provides memory blocks to the function is not ready to return the next block. After this error the caller can retry the call to yr_scanner_scan_mem_blocks multiple times until the function succeeds or fails with some other error code.

Co-authored-by: Simon Hardy-Francis <[email protected]>
2020-12-24 10:46:09 +01:00
Victor M. Alvarez 09116e8b79 Fix buffer overrun in dotnet module found by OSS-Fuzz. (#1425)
The strncpy function was being invoked with a source buffer that was shorter than MAX_TYPELIB_SIZE and the string was not null-terminated, which means that strncpy read past the end of the buffer. Now the limit pass to strncpy is the length of the string as indicated in the byte before the string itself. This length, being a byte, is equal to or less than MAX_TYPELIB_SIZE whose value is 255.
2020-12-22 16:52:01 +01:00
Hilko Bengen 79105efd07 tests: Disable process scanning test on Windows (#1420)
* tests: Disable process scanning test on Windows

There's no sys/wait.h and no fork, so let's just #ifdef it out.

* tests: Open sample files in binary mode

Relevant on Windows.
2020-12-21 12:15:27 +01:00
Wesley Shields 95b43693dc Switch maximum string limit to warning. (#1350)
When we hit the maximum match limit on a string we currently abort all scanning,
which can be problematic since it isn't a good reason to stop all scanning, and
is better off as a warning to the user.

This commit makes it so that when the string match limit is hit a warning is
printed and scanning will continue. The warning message indicates that the
results may be invalid. It is hard to know for certain if they are invalid
because it depends entirely upon the condition. If you use the # or @ operator
then your condition _MAY_ be invalid since the total number of matches and
locations is not known anymore. Just checking that the string exists won't be an
invalid state since we have confirmed the existence of _AT LEAST_ the maximum
number of occurrences, which clearly satisfies the existence of a single
instance of your string.

I decided to implement this as a callback so the user of libyara has some choice
on the default behavior. If they want to consider this a "stop all scanning"
error they are free to return CALLBACK_ERROR in their callback.
2020-12-17 10:10:27 +01:00
Wesley ShieldsandVictor M. Alvarez 77328011a3 Implement pe.entry_point_raw. (#1410)
* Implement pe.entry_point_raw.

Add pe.entry_point_raw which is the raw value of the entry point field from the
optional header. This value is NOT converted to a file offset or a virtual
address, and is just the raw bytes taken straight from the header.

This allows you to use the entry point as it is specified in the file without
having to jump through hoops to parse it by hand in your condition.

* Specify the version in which entry_point_raw was added.

Co-authored-by: Victor M. Alvarez <[email protected]>
2020-12-02 10:16:26 +01:00
Victor M. Alvarez 95ed87ce75 Raise warning not only with .* and .+, but with .{x,} as well. (#1398)
Closes #1386.
2020-11-26 21:00:01 +01:00
Victor M. Alvarez 05b520b7b4 Add file that triggered the memory exhaustion issue fixed in #1400 to oss-fuzz corpus. 2020-11-26 20:56:59 +01:00
Wesley Shields b71d4fed48 Add helper methods to dex module. (#1021)
Add the following helper methods to the dex module:

dex.has_method("foo") - Returns true if any method has the literal name "foo".

dex.has_method(/foo/") - Returns true if any method name matches the regex.

dex.has_class("foo") - Returns true if any class has the literal name "foo".

dex.has_class(/foo/) - Returns true if any class name matches the regex.

dex.has_method("foo", "bar") - Returns true if any class has the literal name
"foo" and any method has the literal name "bar".

dex.has_method(/foo/, /bar/) - Returns true if any class name matches the regex
/foo/ and any method name matches the regex /bar/.
2020-11-26 10:17:35 +01:00
Wesley Shields a8d52ea40f Add number_of_imported_functions. (#1348)
Add the number of imported functions which were parsed. This is the TOTAL number
of functions across ALL imported libraries.
2020-11-23 10:18:27 +01:00
Dominika Regéciová d9c1b68ec5 test-rules: fixed indent (#1382) 2020-10-22 17:18:20 +02:00
Victor M. Alvarez 7517bbdf87 Start using clang-format for automatic source formatting. 2020-10-19 12:11:28 +02:00
Simon Hardy-Francis 242f9b43db Code coverage build (#1374)
* Add gcov code coverage configure option
2020-10-08 11:52:55 +02:00
Victor M. Alvarez 0bce4bd74d Start using clang-format for formatting the code automatically. 2020-10-07 16:27:30 +02:00
Simon Hardy-Francis 0975ea7d30 Fix linux compiler warnings and refactor common test code (#1366) 2020-10-05 09:47:25 +02:00
Simon Hardy-Francis 8d039c7dd9 Add multi block tests and instrumentation for hash module (#1367) 2020-10-05 09:44:26 +02:00
Victor M. Alvarez e4187f3587 Review all calls to YR_DEBUG_FPRINTF and make the following changes: (#1363)
* Review all calls to YR_DEBUG_FPRINTF and make the following changes:

* Use PRIx64 and PRIi64 for printing 64-bits values, which is more portable.
* Use %zu for printing size_t types.
* Remove the empty {} at the end of printed messages, as they don't provide that much information and clutter the format string
* Don't use ' in format strings for thousand separators as this is not very portable (https://stackoverflow.com/questions/10234766/warning-using-icc-and-printf-with-thousands-grouping-format-apostrophe)

* Re-introduce the curly braces in YR_DEBUG_FPRINTF messages.
2020-10-02 17:13:44 +02:00
Simon Hardy-Francis f7948f64a4 Attempt #2 to fix clang duplicate symbol error 2020-10-01 09:31:18 +02:00
Simon Hardy-Francis bf324e12f6 Fix multi block bugs and test running test-rules with single & multiple blocks
See https://github.com/VirusTotal/yara/issues/1356
2020-10-01 09:31:18 +02:00
Victor M. Alvarez 41a32691d4 Implement string operators: icontains, startswith, endswith, istartswith and iendswith. 2020-09-28 09:59:13 +02:00
Victor M. Alvarez d7f3982f90 Fix test case. 2020-09-25 22:02:30 +02:00
Victor M. Alvarez fa0a880de4 Add missing data file Bazel build rule. 2020-09-25 20:43:08 +02:00
Victor M. Alvarez a1f0720970 Fix issue #1354.
scanner->file_size now is set to YR_UNDEFINED when calling yr_rules_scan_proc or yr_scanner_scan_proc.
2020-09-25 20:03:13 +02:00
Wesley Shields 0e536cbd4f Add test for invalid rsrc rva. 2020-08-22 19:07:33 +02:00
Victor M. Alvarez 65904503c9 Change packing of SIZED_STRING from 4 bytes to 1.
This removes 3 unused bytes at the end of each SIZED_STRING. Those 3 bytes are not initialized by alloc_sized_string and cause MemorySanitizer to fail with use-of-uninitialized-value.
2020-07-16 23:22:06 +02:00
Victor M. Alvarez 510f366099 Fix issue #1317. 2020-07-08 11:45:20 +02:00
Victor M. Alvarez 7a5b3a29cc Accept escape sequence \t (carriage return) in text strings. 2020-06-26 16:41:58 +02:00
Victor M. Alvarez 2d5f600ccb Simplify atom quality calculation. 2020-06-26 09:17:35 +02:00
Victor M. Alvarez 33ec9bbd67 Enable some tests that were disabled. 2020-06-15 10:19:43 +02:00
Victor M. Alvarez bb42569d90 Fix issue #1295 2020-06-05 13:17:53 +02:00
Victor M. Alvarez 59817591c4 Add missing data files to Bazel tests. 2020-05-12 15:58:09 +02:00
Scott Knight 793fc55358 Create test case for uninitialized number_of_segments
The current Mach-O parsing code attempts to call macho_rva_to_offset
while parsing load commands and before it has set number_of_segments.
Since macho_rva_to_offset uses number_of_segments this can result
in it using a number_of_segments that is uninitialized and is just a random
large number. In turn yara runs a really long time.

This adds a test binary based on this post

https://codegolf.stackexchange.com/questions/102471/smallest-possible-runnable-mach-o-executable/154685#154685

It has two load commands. The first is a LC_UNIXTHREAD command and
the second is a LC_SEGMENT command. It's a valid 386 Mach-O binary.
It reproduces this error.
2020-05-11 09:02:06 +02:00
Wesley Shields 2bf67e6ae8 Fix regression in export parsing.
UPX packed files will cause export parsing to stop parsing because the function
address is not a valid RVA, and I was refusing to parse that export in that
case.

This is a regression from how we used to do parsing (we were never checking the
export RVA so it was never considered in prior releases). This is causing rules
which used to work to no longer work on packed samples. Specifically, checking
for a DLL which is UPX packed using pe.exports("foo") is likely to not work in
4.0.0 when it used to work in 3.11.0.

Apologies for missing this, but to make sure it doesn't happen again in the
future I've added a test case for this (just packed an existing DLL that is in
the repo).
2020-05-01 09:45:26 +02:00
malvidin 6c1a8add6e Document and test for known base64 false positives and false negatives 2020-04-23 12:46:35 +02:00
malvidin f02a242350 Consistent use of Base64 and base64 in writingrules.rst
Add test for invalid use of base64 and fullword together
Skip second base64 encoding of single ascii byte
Add test for correct base64 encoding of single ascii byte
2020-04-23 12:46:35 +02:00
malvidin 454173ba57 Consistent use of Base64 and base64 in writingrules.rst
Strip base64 bytes from second generated string last
Add test for invalid use of base64 and fullword together
2020-04-23 12:46:35 +02:00
Victor M. Alvarez 3c8f14db3e Fix issue with tests when compiled with -DNDEBUG.
Tests where failing becausd expressions in assert()s don't produce any code when compiled with NDEBUG.
2020-04-20 15:32:02 +02:00
Hilko Bengen 6c91c5dbcf pe: Make rich_signature.key return correct value on big-endian 2020-04-07 09:24:53 +02:00
Victor M. Alvarez b7da5d2835 Fix issue #1180.
This changes the way in which comparison operators, and also the "contains" and "matches" operators handle undefined operands. Before this change the result of such operations was undefined, after this change the result is false.
2020-03-26 13:50:49 +01:00