Commit Graph
3165 Commits
Author SHA1 Message Date
Tom Lancaster 5f2a2213ac Attempt to fix docs adding --strict-escape to CLI help and main yara docs (#2077) 2024-05-18 12:07:23 +02:00
Tom Lancaster 7cf3d2fefa Modifying yara-python docs to reflect existence of strict_escape bool (#2079) 2024-05-18 12:04:32 +02:00
Colin Anderson dec221d7e8 Add Verisys to list of users (#2078) 2024-05-17 17:30:16 +02:00
natalie 375aa7aa8f Add UpSight Security Inc. to list of users (#2080) 2024-05-17 17:27:26 +02:00
Victor M. Alvarez f0cf225538 Fix issue introduced in 8501962.
`authenticode->verify_flags` are not really bit flags, they are more like error codes.
2024-05-07 13:06:10 +02:00
Victor M. Alvarez 8501962919 Ignore Authenticode signatures that are somehow corrupt. 2024-05-06 10:46:46 +02:00
Vincent Thiberville 2479a7104e fix several bugs in array type handling in dotnet module (#2064)
Several bugs were present in the parsing and generation of a string to
represent an array type, notably when the "lo_bound" value is set.

- The "read_blob_signed" was buggy for values outside the
  [-2**6, 2**6-1], the sign edition did not use the right bitmask,
  and the type used was unsigned.

- The display when lo_bound != 0 was buggy:

  - size=5, lobound=0 => should be `5`, this was ok
  - size=5, lobound=1 => should be `1...5`, this was buggy and displayed
    `1...6`. The "range format" is inclusive.

- 0 should still be displayed if size is 0. Only when size is unset
  should it be left out. So an array declared as `[5,0,3]` should be
  displayed the same way, and not as `[5,,3]`.
2024-05-02 10:39:50 +02:00
Vincent Thiberville 41aa1e7ccc Fix dex module inconsistencies (#2069)
* fix signature and magic strings in dex module

Several bytestring values in the dex module were not set properly,
and were cut short due to the presence of a nul byte.

This happened on:
- all the dex.DEX_FILE_MAGIC_* constants, which were cut short by one
  byte (the last one is the nul byte).
- the magic and signature field in the "header" object of the module.

For all of those, the size is fixed and known, so use the right length
and do not cut it short if a nul byte is present.

* fix declared fields in the dex module

There was some mismatch between the declared fields and the ones filled
by the module:

- `dex.field[*].static` and `dex.field[*].instance` were defined, but
  not declared, making their use impossible. They are now properly
  declared.

- several fields in `dex.method[*].code_item` were declared but never
  defined: `padding`, `tries` and `handlers`. Those are removed since
  they couldn't have been used.
2024-05-02 10:38:16 +02:00
Victor M. Alvarez 3c93989a5d Try using a specific MacOS version for fixing issue in CI (#2073)
For some reason the jansson library is not being found in the latest MacOS version, even though brew seems to be installing it.
2024-04-30 19:16:22 +02:00
Victor M. Alvarez 4b9b4c0bdb Add sanity check that prevents OOM errors.
The `pe_parse_delayed_imports` function didn't take into account that `pe_rva_to_offset` could return -1 when the RVA can't be translated into a file offset.
2024-04-30 11:41:56 +02:00
Vojtěch Dvořák adf3ddeaee Updated writingmodules.rst - replaced fetch_data by the new func (#2071) 2024-04-30 08:50:06 +02:00
Victor M. Alvarez 1be9811ad9 Add sanity check that prevents to much memory consumption with corrupted files
With this change ordinal numbers in imports are limited to 65535, larger ordinal numbers are ignored because they are sign of file corruption.
2024-04-23 09:19:54 +02:00
Victor M. Alvarez 1242223b04 Ignore resource directory entries that with offset == 0. 2024-04-19 17:21:44 +02:00
Victor M. Alvarez b68003853c Restrict DLL names to the printable ASCII range. 2024-04-19 17:20:35 +02:00
Victor M. Alvarez 5317a2b349 Fix endianness issue. 2024-04-08 15:49:07 +02:00
Victor M. Alvarez 620963092c Better sanitation while parsing corrupted resources. 2024-04-08 15:33:35 +02:00
Victor M. Alvarez 80972f0b4c Populate dotnet.resources[x].offset and dotnet.resources[x].length even if falling outside of the file
Until now, these two fields were populated only when the offset and offset + length were within the file boundaries. This meant that the fields were undefined for some files that were truncated. For instance, 3323480fc4e35f73a8e93c4a0658c818d7e517df7ba15ba4cbb5cd2b6058cb0f.
2024-04-08 12:04:17 +02:00
Victor M. Alvarez 9c26038171 Fix alignment check in 32-bits. 2024-04-08 11:57:00 +02:00
Victor M. Alvarez 3395fee53c Remove assertion from test-aligment.c
`off_t` is not 64 bits in all platforms (like Win32)
2024-04-08 10:53:32 +02:00
Victor M. Alvarez 924fa58ce9 Fix issue #2065
The issue was causing false negative with certain patterns.
2024-04-08 10:28:31 +02:00
Victor M. Alvarez 833a580430 Fix issue #2050.
See also PR #2048.
2024-04-07 17:56:43 +02:00
Victor M. Alvarez 7b4dcd8cce Fix alignment tests.
They were returning OK in all cases, it was broken in cba6932759.
2024-04-07 17:56:36 +02:00
Michael Gillespie 2a9bc0d5e6 Prevent assert in MSVC debug version of isprint() (#2062) 2024-04-05 18:49:35 +02:00
Victor M. Alvarez fedee98f9d Fix syntax error in .readthedocs.yaml 2024-03-26 19:21:08 +01:00
Victor M. Alvarez 7fa7465675 Add requirements.txt for documentation. 2024-03-26 19:19:47 +01:00
Victor M. Alvarez 2570c1f931 Create .readthedocs.yaml
This file allows ReadTheDocs to build the documentation, generating the HTML for it.
2024-03-26 19:07:48 +01:00
Victor M. Alvarez 94b7da931c Add test case for math.entropy where input is an empty string. 2024-03-25 10:49:06 +01:00
tobim 07e46fa305 Add Tenzir to the list of Users (#2051)
As documented in https://docs.tenzir.com/blog/matching-yara-rules-in-byte-pipelines.
2024-03-23 21:22:40 +01:00
Michal c6d16301e4 Fix broken link (#2058) 2024-03-23 21:22:08 +01:00
Victor M. Alvarez ff959e562a Add more test cases. 2024-03-20 15:49:14 +01:00
Victor M. Alvarez c80cd9debf Fix issue with matches operator not matching empty strings
The `matches` operator was returning false if the left operand was an empty strings. So, `"" matches <some regexp>` was returning false regardless of the regexp used. However, some regexp *do* match the empty strings, like for example `/foo|/`.
2024-03-20 15:47:37 +01:00
Victor M. Alvarez 87485021cf Fix integer overflow causing issue when parsing directory table
File e64e806c6df76f245c9b1288f59198bc9478329cfdd2d7ddcb9490a57d0b3cf4 was not properly parsed because `NumberOfRvaAndSizes` overflowed and became negative.
2024-03-20 09:22:53 +01:00
Victor M. Alvarez 74c1a0c8a6 Relax check in pe_get_directory_entry.
Some PE files have a NumberOfRvaAndSizes equal to zero. Even if these files are not accepted by the Windows loader, they can be parsed, and useful information can be extracted from them. By relaxing the sanity check in pe_get_directory_entry we are no able to parse such files (like 0aa527fd26c8e7fa7f3476b6d7eb8f22c071ff4c0fd3ed3797fa90ceb80f24ce).
2024-03-19 15:45:04 +01:00
Victor M. Alvarez 5bf72f2fb0 Fix issue while parsing .NET resources
.NET resources can be found outside the current file. Before this change those resources were being ignored, but now they are included in the `resources` array. The `name` and `length` fields are kept undefined though. So, external resources have only the `name` field set.
2024-03-18 20:21:12 +01:00
Victor M. Alvarez c009195c1e Apply stricter sanity checks while parsing PE resources.
Corrupted file `c10a733e4899dbd03d537d7832efa71016f618e9fd1bffa35b8265df359a91f8` was producing tons of invalid resource entries.
2024-03-08 12:28:57 +01:00
Victor M. Alvarez a0241546df Remove check in dotnet_is_dotnet that doesn't seem necessary.
This function was checking the first two bytes at the entrypoint of .NET files, if the bytes were not `FF 25` the file was not considered a .NET file. This check was overly restrictive, as some files like `8fa7fe73a65296e9ca8301734a0deaa298cda0b7a65f6b7d2ef6d1c8bbb8cd7a` don't have such files at the entrypoint.
2024-03-07 10:39:43 +01:00
Victor M. Alvarez 8242721801 Fix issue in pe_rva_to_offset for some files.
This function was returning a wrong RVA for files like `67508ec9cbd9f82c6aea8a93ca27fd3684d368664470397755f8d70934d481fb`, when a section's virtual size is smaller than its physical size.
2024-03-07 10:33:33 +01:00
Victor M. Alvarez 9490a0c00c Do not abort resource iteration too early when some entry is truncated.
Failing to parse some resource directory does not mean that we can't keep parsing other directories. For instance, with file `0a65e22cdff348be11739122906355af728f6247fb849f98d69a6f6d51103071` YARA was aborting the parsing too early and extracted a single resource, while the file has more resources that could be parsed correctly.
2024-03-06 12:00:27 +01:00
Victor M. Alvarez 4793b49dd7 Fix issue while parsing PE rich header.
YARA was making the assumption that the 12 bytes following the `DanS` header contained 3 copies of the 32-bits XOR key, but these bytes are actually padding. As these bytes were usually filled with zeroes before applying the XOR key, they appear to contain the key itself after the XOR operation. However, files like `043066108b68b30fc2c475eae8edfafc080be7d451600eaa283d2c750bddbceb` don't contain zeroes in those bytes, and therefore were not satisfying YARA's assumption.

YARA-X was right: https://github.com/VirusTotal/yara-x/blob/6ada059b9e4b328e2341b42304765c5614fc89af/lib/src/modules/pe/parser.rs#L687-L693
2024-03-04 18:26:19 +01:00
Marek Milkovič f51b9d7f6a Updated authenticode parser to latest version (2024-03-02) (#2049)
Upon fixing the latest issue regarding parsing CMS, we figured out we
are not properly extracting all certificates from Microsoft
countersignatures. This should now properly expose them.

Also fixes one memory leak for countersignature parsing.
2024-03-04 09:32:58 +01:00
Victor M. Alvarez a1883addcb Update example in yara-python's documentation.
As discussed in https://github.com/VirusTotal/yara-python/issues/247, the example using `StringIO` worked fine in Python 2, but ti doesn't work in Python 3. Now that Python 2 is mostly dead, update the example.
2024-02-29 13:08:03 +01:00
orbea 2e2cd20551 countersignature: remove TS_VERIFY_CTX_init() call (#2044)
This is redundant and already handled by TS_VERIFY_CTX_new().
Additionally it causes build failures with LibreSSL >= 3.8.0 which
removed this function since it serves no purpose with opaque
TS_VERIFY_CTX where it will zero out an already zero'd out ctx or cause
a leak.

See: https://github.com/libressl/portable/issues/1006
2024-02-26 10:05:06 +01:00
Victor M. Alvarez 8fa55cde4c Bump version number to 4.5.0 v4.5.0 2024-02-13 12:33:22 +01:00
Victor M. Alvarez 4369ca6a1b Fix endianness issues in macho module (#2041)
This is backward compatible change that affects the `magic` field. After this change the value in the `magic` field looks exactly as it looks in the file regardless of the endianness of the current platform, if the file starts with `CA FE BA BE` the value in magic is `0xCAFEBABE`, not `0xBEBAFECA` as it used to be in little-endian architectures.
2024-02-12 15:23:09 +01:00
Victor M. Alvarez f3b3027154 Allow quantifiers {0} and {0,0}.
Regexps with quantifiers `{0}` and `{0,0}` were considered syntactically invalid. These quantifiers are not  actually useful, but they are now allowed for compatibility with other regexp engines.

Closes #2037.
2024-02-12 11:47:17 +01:00
Victor M. Alvarez c1c5d89052 pe.is_signed is now defined for all PE files.
Until now, `pe.is_signed` was undefined for every PE file that was not signed, making impossible to use it in negated conditions, like `pe.is_pe and not pe.is_signed`. With this change, `pe.is_signed` is false for every PE file that is not signed.

Closes #2040
2024-02-12 11:10:49 +01:00
Victor M. Alvarez 9ff9c4c6ca Temporary fix for SIGSEGV caused by authenticode parser.
See: https://github.com/avast/authenticode-parser/issues/19 for details.
2024-02-09 10:47:12 +01:00
Victor M. Alvarez 3342aa06f6 Fix bug in magic module when libmagic returns null pointer.
The pointer returned from `libmagic` was passed directly to `yr_strdup` (a wrapper of `strdup`), but this function has undefined behavior when the argument is null.
2024-02-08 11:28:17 +01:00
Tom Lancaster e4372d3a54 typo fix (#2039) 2024-02-07 16:56:48 +01:00
Victor M. Alvarez 3a2b4d16c5 Upgrade magic library to version 5.45. 2024-02-06 13:53:11 +01:00