Commit Graph
2925 Commits
Author SHA1 Message Date
HoundThe 125e404934 Fix ELF module compiler uninitialized free warning (#1751) 2022-07-21 12:22:24 +02:00
Wesley Shields 8c24aec5f5 Improve docs for -d. (#1750)
As mentioned in #1749, this commit brings the docs up to date with the man page
and usage statement.

Fixes #1749.
2022-07-19 10:23:11 +02:00
Kevin Waldock 32386642e3 Correct function signature in docs (#1743) 2022-07-14 15:09:14 +02:00
Vincent Thiberville a406568bf9 fix: reset index of import_details functions in pe module (#1747)
The function index was not reset between subsequent DLL imports,
leading to this module data for example:

This is fixed by simply pushing the counter inside the DLL loop.
2022-07-14 10:28:52 +02:00
Adhokshaj Mishra ed413a35e1 Added Uptycs Inc in "who is using yara" list. (#1744) 2022-07-12 10:54:44 +02:00
HoundThe 86b0e3f7c7 Fix unaligned read and missing length check in read_blob_*. (#1742)
Add depth limit in namespace recursion due to the possible loops.
2022-07-12 10:23:07 +02:00
Jose Toro fd8921c2cd Missing version bump (#1741) 2022-06-29 09:36:58 +02:00
HoundThe 2c1457bef4 Explain is_signed and verified of the authenticode signatures (#1738) 2022-06-28 10:13:27 +02:00
Victor M. Alvarez 94b99857e7 Apply clang-format to authenticode-parser. 2022-06-28 10:07:27 +02:00
Victor M. Alvarez 0d2e9c9c5e Prevent undefined return value. 2022-06-28 09:57:41 +02:00
Victor M. Alvarez cfcc631ba9 Re-organize code in _yr_parser_write_string.
This fixes a warning raised by Coverity which is actually a false positive.
2022-06-24 13:20:19 +02:00
Victor M. Alvarez eca89998a1 Fix memory leaks. 2022-06-24 12:59:45 +02:00
Victor M. Alvarez f31c91a65c Don't return from functions that receive va_list arguments without calling va_end. 2022-06-24 12:52:48 +02:00
Victor M. Alvarez 514d67599f Specify project in coverity.yml. 2022-06-24 11:09:18 +02:00
Victor M. Alvarez 2df4e6550b Install dependencies and prepare for building before running coverity. 2022-06-24 11:06:52 +02:00
Victor M. Alvarez 81ba918554 Fix branch name in Coverity workflow. 2022-06-24 10:54:04 +02:00
Victor M. Alvarez a2b2448372 Add ending new-line and rename workflow. 2022-06-24 10:51:28 +02:00
Victor M. Alvarez 55a8447886 Merge remote-tracking branch 'origin/master' 2022-06-24 10:48:15 +02:00
Victor M. Alvarez 97c81fdb10 Add GitHub workflow for running Coverity scans. 2022-06-24 10:47:59 +02:00
HoundTheandVictor M. Alvarez 15ec337e04 Add parsing of .NET user types from .NET metadata stream (#1605)
* Add simple_str string implementation

* Add ability to parse .NET user defined types to 'dotnet' module

* Add copyright information

* Unify comment style, define iter variable within for loop

* Fix invalid handling of corrupted parameters

* Remove duplicate test_dotnet in BUILD.bazel

* Fix unaligned memory access. (#1)

* Fix unaligned memory access.

* Add missing comma in Bazel file.

Co-authored-by: Victor M. Alvarez <[email protected]>
2022-06-23 12:36:22 +02:00
Malware Utkonos 77a57a1ba3 Add more fine-tuned info for ldconfig on the latest Ubuntu. (#1733) 2022-06-23 10:16:30 +02:00
Victor M. Alvarez b2c672a904 Fix #1734. 2022-06-23 09:59:15 +02:00
HoundTheandVictor M. Alvarez b9cd46df15 Process Authenticode signatures using authenticode-parser (#1623)
* Import authenticode-parser into Yara. Rewrite PE signature processing using the authenticode-parser. Update bazel OpenSSL dependency to 1.1.1 from 1.1.0

* Forgot to include structs.c

* Add Avast to authors and myself to contributors

* Set forgotten algorithm_oid

* Fix incorrect indentation

* Fix race condition when initializing openssl objects

* Don't malloc ByteArray with length 0

* Auth. parser update - bug fixes, openssl3.0 support

* Update authenticode parser

Co-authored-by: Victor M. Alvarez <[email protected]>
2022-06-20 12:47:36 +02:00
Victor M. Alvarez 22fde83d7a Apply clang-format to tlshc and fix minor warning. 2022-06-20 12:31:39 +02:00
HoundThe 19ac2efeb8 Integrate tlshc library, calculate telfhash and import hash in ELF module (#1624)
* Add simple_str string implementation

* Integrate tlshc library, calculate telfhash and import hash in the ELF module.

* Hide usage of MD5 into #ifdef crypto
2022-06-20 12:25:33 +02:00
Wesley Shields 15b8de578e Fix negative indexing in dex module. (#1730)
* Fix negative indexing in dex module.

When attempting to call dex_get_integer() or dex_get_string() with a negative
index we would eventually land in the assert() at
https://github.com/VirusTotal/yara/blob/master/libyara/object.c#L497 failing.
Instead of doing that let's check for negative values before going any further,
which will at least allow the module to continue processing.

* YR_UNDEFINED is < 0 already. Simplify the logic when checking for negative index.

* Revert "YR_UNDEFINED is < 0 already. Simplify the logic when checking for negative index."

This reverts commit 38af38fb8d.
2022-06-16 17:41:18 +02:00
Victor M. Alvarez 811c20f2bf Fix issue #1729. 2022-06-15 13:51:52 +02:00
Wesley Shields 599481b949 Dex fixes (#1728)
* Fix compiler warnings with dex debug mode.

* Fix crashes in dex module.

This commit fixes a few crashes in the dex module. There are actually three of
them:

The first is incorrect usage of "struct_fits_in_dex" caused by passing
"sizeof(code_item_t)" instead of just "code_item_t" as the third argument. In
the test case the pointer for code_item started in the bounds of the dex but
only the first 8 bytes were within bounds, and since
"sizeof(sizeof(code_item_t))" is less than 8 the check was passing. The fix here
is to pass just the struct type as the third argument.

The second crash was an off-by-one error when parsing a string. The check
ensured the string fits in the dex but was not including an extra byte which was
copied in the call to set_sized_string. Just like before, this was a case of a
string falling right on the end of a dex file.

The third crash was due to a missing "struct_fits_in_dex" check. We ended up
with a pointer to a map_item_t which was off the ends of the dex bounds.

With this commit all the test cases provided in the report are now passing. I
did a quick sweep of the module to make sure there were no other cases where we
were incorrectly using "struct_fits_in_dex" and didn't find any.

These were all documented at a private report via huntr.dev
(https://huntr.dev/bounties/007a7784-c211-4847-9cc3-aec38e7d5157/)

Found by @sudhackar.

Fixes #1726.
2022-06-15 09:57:48 +02:00
Sudhakar Verma e23ac0d77b Fix null derefrences while loading compiled rules (#1727)
* Fix null derefrences while loading compiled rules

* Fix nulldereference in yr_object_create

* Fix assert to explicitly catch null identifier in yr_object_create
2022-06-14 13:46:12 +02:00
Wesley Shields 929af6ef21 Fix incorrect error message in range check. (#1725) 2022-06-13 09:33:57 +02:00
Victor M. Alvarez 479115720e Add instructions for reporting security issues. 2022-06-13 09:25:13 +02:00
Victor M. Alvarez 3484fcb60b Fix multiple memory alignment issues. (#1724)
The x86 platform is very forgiving when you access a 16-bits variable stored at a memory address that is not aligned to a 2-bytes boundary, or a 32-bits variable that is not aligned to 4-bytes boundary, and so on. Other platforms, like ARM or Sparc are not that flexible, and accessing a value by dereferencing a pointer that is not aligned to the size of the value causes a processor fault.

This fixes multiple issues caused by pointers that are not aligned to the size of the value.

Fixes: #1700
2022-06-07 09:37:27 +02:00
Wesley Shields ccbc405cc9 Fix another compiler edge case. (#1722)
* Fix another compiler edge case.

When compiling and we encounter a range that has values we can determine at
compile time we should error out if the lower bound is less than 0.

* Fix OP_COUNT_IN paranoid check.

The OP_COUNT_IN operation does not need the paranoid check on r1 as it is the
lower bound of the range, and thus a constant and not a pointer somewhere. It
should, instead, be checking r3.

Fixes #1721 (the first half of it).
2022-06-01 16:03:22 +02:00
Victor M. Alvarez 6c5fd5e9f7 Fix issue #1719. 2022-06-01 09:43:33 +02:00
Victor M. Alvarez 1cd5d47a0d Re-generate grammar.c with Bison 3.8.2. 2022-06-01 09:35:05 +02:00
Dominika Regéciová 8396306954 grammar.y - fixed format ‘%lld’ warnings (#1718) 2022-06-01 09:32:46 +02:00
dangodangodango 94a5de1903 Fix issue #1708 (#1710)
* Fix issue #1708

* Add test case for #1708

Build a dotnet pe that triggers this issue:
https://github.com/dangodangodango/BadDotnetPe
2022-05-28 22:02:21 +02:00
MatejKastak a60f47cd5c Magic tests fix (#1714)
* test: Relax pe32 condition in magic tests

Turns out different versions of libmagic return different file
identification for the PE32 sample in magic tests. Relax this condition
to the common part of the identification to make tests less reliant on
the testing platform.

* test: Relax macho condition in magic tests
2022-05-28 19:47:57 +02:00
John 93cf24449e Fix autoreconf error due to m4 CRLF issue (#1717)
Trying to run `autoreconf -fiv` on a Windows system using wsl causes the following error:
```
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
.ibtoolize:   error: AC_CONFIG_MACRO_DIRS([m4]) conflicts with ACLOCAL_AMFLAGS=-I m4
autoreconf: libtoolize failed with exit status: 1
```
This is likely due to a CRLF error in the makefile. This commit applies the following fix:
https://pete.akeo.ie/2010/12/that-darn-libtoolize-acconfigmacrodirm4.html
2022-05-28 19:47:20 +02:00
Victor M. Alvarez 68491c5d3d Merge remote-tracking branch 'origin/master' 2022-05-28 19:30:34 +02:00
Victor M. Alvarez 25f576adf3 Add test case for uppercase atoms.
Related to #1716.
2022-05-28 19:30:10 +02:00
Wesley Shields ee6b2363f7 Add docs about warnings member for python. (#1711) 2022-05-19 23:05:01 +02:00
Marek Milkovič 3bb5355836 Fixed typos in pe.delayed_import_details structure (#1712)
There were several typos across the pe.delayed_import_details which
resulted in certain delayed import information not being available at
all.
2022-05-19 23:03:44 +02:00
Victor M. Alvarez 1fe26dcf78 Fix issue in documentation.
Indicate that the `match` method in `yara-python` accepts both a `str` and `bytes`.
2022-05-19 10:42:56 +02:00
Victor M. Alvarez b8dcc0003b Merge remote-tracking branch 'origin/master' 2022-05-18 10:05:54 +02:00
Victor M. Alvarez 1fd688e56b Reduce the amount of time that processes are maintained alive in test_process_scan.
test_process_scan launches a process and tests YARA's process scanning capabilities on it. This process was maintained alive for 10 minutes, which caused `make -j32 check` to hang during all that time before returning. This change reduces the time to 5 seconds, which should be enough for running the test cases.

Closes #1667 .
2022-05-18 10:05:39 +02:00
Victor M. Alvarez f89a98b72d Reduce the amount of time that processes are maintained alive in test_process_scan.
test_process_scan launches a process and tests YARA's process scanning capabilities on it. This process was maintained alive for 10 minutes, which caused `make -j32 check` to hang during all that time before returning. This change reduces the time to 5 seconds, which should be enough for running the test cases.

Closes #1683.
2022-05-18 10:04:05 +02:00
Mario Haustein bbd70441e4 finish all processes spawned in the test suite (#1683) 2022-05-17 18:22:02 +02:00
Wesley Shields a5903e1d24 Fix some compiler edge cases. (#1709)
* Fix some compiler edge cases.

Add a warning when "0 of them" is used. Point to some new documentation that
explains why "none of them" is preferred.

Handle some edge cases, which are all now errors:

* -1 of them
* "foo" of them
* /foo/ of them

And this one is also an error if the external variable "x" is a negative integer
or a string:

* x of them

I've also made sure this works with a construct like "0 + x of them" where x is
defined as a negative integer.

Add test cases for as many of these as I can. I don't have test cases for the
external variable case, but it does work as expected. Here is the output of a
rule using external variables where the variable is defined to be 1, 0, -1 and
foo:

```
wxs@mbp yara % cat rules/test.yara
rule a {
  strings:
    $a = "FreeBSD"
  condition:
    x of them
}
wxs@mbp yara % ./yara -d x=1 rules/test.yara /bin/ls
a /bin/ls
wxs@mbp yara % ./yara -d x=0 rules/test.yara /bin/ls
warning: rule "a" in rules/test.yara(5): Consider using "none" keyword, it is less ambiguous. Please see https://yara.readthedocs.io/en/stable/writingrules.html#sets-of-strings-1 for an explanation.
wxs@mbp yara % ./yara -d x=-1 rules/test.yara /bin/ls
error: rule "a" in rules/test.yara(5): invalid value in condition: "-1"
wxs@mbp yara % ./yara -d x=foo rules/test.yara /bin/ls
error: rule "a" in rules/test.yara(5): invalid value in condition: "string in for_expression is invalid"
wxs@mbp yara %
```

* More compiler warnings and errors.

If you specify "2 of ($a)" it is now a warning because it will always evaluate
to false, and is quite possibly not what you wanted to write. This is true for
string sets, rule sets and string sets in a range like "2 of ($a) in (0..10)".

If you are using an integer range it is now an error if the lower bound is
greater than the upper bound.

To support rule sets I needed to modify yr_parser_emit_pushes_for_rules() to
use a count parameter, which it will update with the number of pushed rules.
This is identical to how yr_parser_emit_pushes_for_strings() works.

While I'm here, remove the link from the warning message for the "none" keyword.
2022-05-17 18:20:57 +02:00
Victor M. Alvarez 19363ee85e Make all warning messages lowercase. 2022-05-17 09:21:27 +02:00