Commit Graph
2214 Commits
Author SHA1 Message Date
Ԝеѕ 4df40fca36 Note that hash matching requires lowercase hash (#1106)
* Note that hash matching requires lowercase hash

https://github.com/VirusTotal/yara/issues/1004

* Clarify why hash cond needs to be lowercase
2019-09-23 13:02:44 +02:00
Griffin Downs aad709ed37 Add vcpkg installation instructions (#1130)
* Add vcpkg installation instructions

* Fix formatting

* Fix formatting; Add end-to-end instructions

* Re-word issue and pr message; Correct bootstrap script name

* Properly reflect maintainers of YARA port in vcpkg
2019-09-23 12:58:01 +02:00
Victor M. Alvarez 677e878d99 Minor re-styling in PE module. 2019-09-23 12:57:17 +02:00
Marc-Etienne M.Léveillé e68eff9868 PE rich signature improvements (#1135)
* rich_internal function now returns the sum of counts
of the matching rich entries instead of a boolean

It remains backwards compatible thanks to non-null values being
considered as true and when not found it returns 0 (false).

* Update documentation of the `toolid` and `version` in PE module
to reflect changes of behavior: it now returns the sum of counts matching
to given `toolid` and `version`.

* Added test for the updated rich_signature function
2019-09-23 12:49:22 +02:00
Wesley Shields ce470b7bd4 Improved xor modifier. (#1132)
* Implement improved xor modifier.

* Fix breakage when xor(...) came before another modifier.

* Add documentation for xor improvements.

* Fixes from review by Victor.

- No more changes to lexer.
- Duplicate modifiers are now errors.
- Do not rely on undocumented behavior in bison.

* Apply fix to deal with undocumented bison feature we shouldn't rely on.

* Make xor work properly with other modifiers.

This commit now makes it so that "xor(1-255) wide" will no longer search for the
plaintext wide version of the string, but "xor wide" will because it implies
xor(0-255).

* Add support for xor(X) and tests.
2019-09-18 17:12:46 +02:00
Victor M. Alvarez b513aea1d8 Fix version number in LDFLAGS.
Closes #1134
2019-09-18 10:54:30 +02:00
Mario Suvajac ac65f22ac7 Fix undefined line numbers in yr_lex_parse_rules_fd. (#1133) 2019-09-18 10:47:37 +02:00
Victor M. Alvarez be3b77b633 Prevent yr_stopwatch_elapsed_us from being called without a matching call to yr_stopwatch_start.
Closes #1030.
2019-09-11 09:19:51 +02:00
Victor M. Alvarez 8034b84fb1 Make YR_STOPWATCH to have the same size, independently of HAVE_CLOCK_GETTIME being true or not. (#1125)
* Make YR_STOPWATCH to have the same size in Linux, independently of HAVE_CLOCK_GETTIME being true or not.

No matter the value for HAVE_CLOCK_GETTIME the YR_STOPWATCH structure now have the same size, and users of the library don't  need to provide the right value for HAVE_CLOCK_GETTIME while building their programs.

* Change #elif to #else.

* Build with profiling enabled in Travis-CI.

* Try to fix issue with certificates in Travis CI.

* Fix typo.
2019-09-10 10:29:41 +02:00
Northern-Lights 8e2783035a Fix #1128: display floating point numbers (#1129) 2019-09-10 10:29:15 +02:00
Victor M. Alvarez eae3a8c2c6 Add configuration setting for building YARA with profiling enabled using Bazel. 2019-09-06 12:14:08 +02:00
Victor M. Alvarez 2376ca49fd Automate Bazel build with Travis CI (#1124) 2019-09-04 18:42:11 +02:00
Wesley Shields 627ef691d7 Fixes for xor modifier. (#1113)
* Fixes for xor modifier.

This commit makes the xor modifier no longer include "plaintext" versions of the
strings. In particular if you have:

$a = "This program cannot" xor

Then it will no longer match on the plaintext version of the string. It will
only match on the xor versions. If you want it to match on plaintext or xor then
you can use:

$a = "This program cannot" xor ascii

The same is true for wide.

* Make 'xor nocase' a compiler error.

* Add newline between ascii and wide strings.
2019-09-03 10:59:47 +02:00
Northern-Lights 96017d8405 fix get_float() for modules (#1122)
* fix get_float() for modules

* Update writingmodules documentation with get_float
2019-09-03 10:16:02 +02:00
Michael Maltsev 505632df36 Update command line example (#1118)
I understand that it's only an example, but I think that it's clearer when it's a valid one.
2019-08-30 13:07:55 +02:00
Michael Maltsev 9b11f43fc6 Fixed incorrect constant usage in yara.c (#1119) 2019-08-30 13:06:43 +02:00
Victor M. Alvarez 191affb027 Rename type for fields in YR_AC_TABLES structure. 2019-08-30 11:09:09 +02:00
Victor M. Alvarez 6f3e22d224 Fix issue #1117
Due to an unsigned to signed conversion _yr_re_is_char_in_class was returning a wrong result for some non-ascii inputs when called in case-insensitive mode.
2019-08-30 11:07:14 +02:00
Malware Utkonos 6883100592 Fix typo in example (#1116) 2019-08-26 22:19:47 +02:00
MatejKastak 6fcef6b36b compiler:Open include files allowing other readers (#1114) 2019-08-21 15:06:16 +02:00
Victor M. Alvarez 2a2fc2337f Implement yr_rules_reset_profiling_info for resetting the profiling time counters. 2019-08-12 12:30:39 +02:00
Victor M. Alvarez 560e9af3b7 Revert "Add dependency on zlib when building with libmagic (#1084)"
This reverts commit 03f1bba109.
2019-08-12 09:50:31 +02:00
Wesley Shields 2bafaf4ec3 Add dotnet tests. (#1109)
Add some tests for the dotnet module, which uses the smallest .NET binary I had
laying around that exercises a fair bit of the code. In particular it has a
resource, guids, assembly information and a couple of other things that make for
good tests.
2019-08-12 09:07:58 +02:00
Victor M. Alvarez 5aa70a050e Fix chained strings (#1107)
* Add test case.

* Fix issue with regexps and hex strings that were not splitted correctly.

The function yr_re_ast_split_at_chaining_point was not splitting correctly regexps and hex strings that contained more than one large jump (a.k.a gap). For example, { 01 02 03 [0-1000] 04 05 06 [500-2000] 07 08 09 } was not splitted in three parts as expected, but only in two parts: { 01 02 03 } and { 04 05 06 [500-2000] 07 08 09 } . This didn't affected the correctness of the matches, but it caused ERROR_TOO_MANY_RE_FIBERS in some cases while trying to match { 04 05 06 [500-2000] 07 08 09 } because of the large jump in the pattern. The occurrence of the error depended on the data being scanned.

This commit fixes the aforementioned issue, improves the documentation of related functions and simplifies some portions of the code.

* Avoid putting the same string multiple times in matching_strings_arena.

This fixes a small issue introduced in #1096. The same string could be put more than once in the matching_strings_arena, this doesn't causes any major error nor affect the correctness of the matching, but it could have a negative impact on performance.

* Add more comments.

* Improve documentation for _yr_scan_verify_chained_string_match.
2019-08-12 09:07:33 +02:00
Victor M. Alvarez 7a5a2b6d4a Fix a heap overrun in the dotnet module. (#1108)
A heap overrun can occur in call to set_sized_string when called with blob_offset and blob_result.length values that are not validated to be within the boundaries of the buffer containing the PE file. The validation was being done before adding blob_result.length to blob_offset.

Credit to OSS-Fuzz for finding this bug.
2019-08-09 14:59:37 +02:00
Victor M. Alvarez 63f520b41f Regenerate lexer.c with flex 2.6.4. 2019-08-09 11:25:29 +02:00
Victor M. Alvarez 0f15aea928 Minor refactor of the bug fix in #1101. 2019-08-07 13:33:51 +02:00
CSZQ ed092aa4ef fix error: yara try to open wrong file (#1101)
* fix error
when yara file name is like    test:foo.yar    ,yara try to open foo.yar

* add win32
2019-08-07 13:17:26 +02:00
Wesley Shields 7b6bb5ba85 A single byte jump is equivalent to ??. (#1105)
These two strings are logically equivalent, but one throws a warning and one
does not:

$a = { 13 [1] 20 00 [1-30] 13 [1] 10 00 }
$b = { 13  ?? 20 00 [1-30] 13  ?? 10 00 }

Currently $a will throw a warning and $b will not. Fix this by treating single
byte jumps as a masked literal, so atom selection will be able to properly work.
2019-08-07 13:07:50 +02:00
Wesley Shields aef71271f2 Fix typo in hex grammar. (#1104) 2019-08-05 17:41:40 +02:00
Wesley Shields 37aae685c2 Private strings (#1096)
* Add private modifier for strings.

This commit adds a private modifier to the grammar, which can be used on any
string. When this modifier is used the string is treated as normal except it is
never reported back in match objects. It is still searched for normally and
still used normally in condition evaluation but it will never be seen in the
match callback.

This is a useful feature when you have strings that you want to use but they
match a lot of times and you don't want them polluting your log results. The
best example that demonstrates this is the technique described at [1]. In this
example the local file header magic is going to match a lot of times, and it is
only needed to look through the local file header for filenames at offsets
relative to the matches. We don't really care where the offsets of the local
file header are, just where the matching filenames are.

If you are logging where all the matches are for every string and there are
10,000 local file headers that's a lot of log data being generated which is not
helpful at all.

[1]: https://blog.korelogic.com/blog/2015/08/19/yara-ctf-2

* Optimize VM execution code for private strings.

Rather than checking the matches list and only if none are found then check for
private matches, it's better to check only the appropriate list after using
STRING_IS_PRIVATE.

* Add private strings in various tests.

This should cover all the cases of operators on strings that also need to check
for private strings.

* Add docs for private strings.

* Fixup documentation.

Private strings apply to all string types, not just text strings.

* Fix private modifier for chained strings. Add a test case for it too.
2019-08-05 08:38:57 +02:00
Dominika Regéciová 6dbb974917 Detection of regular expressions with xor option (#1090) 2019-07-17 00:35:42 +02:00
winden 0add3052ac Add Antonio Vargas Gonzalez to CONTRUIBUTORS. (#1088) 2019-07-09 12:25:00 +02:00
Christian Blichmann 092fc26833 Add a thread-safe Sandboxed API for YARA (#1087)
The library built by the Bazel target //sandbox:yara_sapi can be used
directly to perform sandboxed YARA scans.
The API is intentionally kept very simple, only three methods are
exposed by the YaraTransaction C++ class:
* YaraTransaction::Create() to create with the specified timeout and
  number of worker threads
* YaraTransaction::LoadRules() to load YARA rules from string, and
* YaraTransaction::ScanFd() to scan the contents of a file descriptor.

Internally, this creates a new sandboxed sub-process which maintains a
dispatch queue and multiple worker threads. The transaction class then
multiplexes scan tasks to the sandboxee where they will be executed in
parallel. This allows many scan threads to share the same set of YARA
rules, saving memory.

See sandbox/sandboxed_yara.cc and the unit test in
sandbox/yara_transaction_test.cc for examples on how to use this API.

Signed-off-by: Christian Blichmann <[email protected]>
2019-07-09 09:45:57 +02:00
Mike Wiacek 9ccdf431f1 Fix cc_library rule so yara builds when included via a bazel git_repository rule (#1086) 2019-07-08 08:34:35 +02:00
pwrdwnsys 305ba7afa4 fix detection of libraries for OpenBSD (#1083) 2019-06-27 15:45:31 +02:00
Marek Milkovič 03f1bba109 Add dependency on zlib when building with libmagic (#1084)
This fixes linking against static libmagic.
2019-06-27 15:44:54 +02:00
Victor M. Alvarez 02781737f0 Sort "who's using YARA" list. 2019-06-13 18:10:52 +02:00
Caleb Fenton f0058e3f99 Properly set DEX string size (#1073) 2019-06-10 16:42:10 +02:00
Wesley Shields 4f89f7f106 Add crc32 to hash module. (#1076)
Add crc32 functions to the hash module. They work in the normal "offset and
size" way and on arbitrary strings.

While here, add tests for it and also documentation.
2019-06-10 16:41:38 +02:00
Christian Blichmann d11b52befe Add Bazel build for Yara and tests (#1078)
* Add Bazel build file and workspace

This will build Yara on Linux using BoringSSL, other platforms are
currently untested.

A few of the modules are currently disabled in the build, like Cuckoo
and Magic. This is due to additional external dependencies.

Signed-off-by: Christian Blichmann <[email protected]>

* Add Bazel build file for the tests.

This omits the version test, as it is not very meaningful for Bazel.

Signed-off-by: Christian Blichmann <[email protected]>
2019-06-07 15:25:08 +02:00
Victor M. Alvarez 2b10f5c6e6 Fix memory leak when _yr_process_attach fails. (#1075)
Closes #1070.
2019-06-06 10:53:06 +02:00
Mike Wiacek ac0d090d47 Merge pull request #1074 from VirusTotal/boringssl
Add macro for leaving out features not supported by BoringSSL.
2019-06-04 09:51:23 -05:00
Victor M. Alvarez cb6be32127 Add macro for leaving out features not supported by BoringSSL. 2019-06-04 08:47:53 +02:00
Ԝеѕ 9ba33c61f9 Updating user list (#1069) 2019-05-28 19:48:14 +02:00
Victor M. Alvarez 17f98d5a7a Closes #1068. 2019-05-27 18:02:00 +02:00
Dionysis Grigoropoulos 173b5a03f3 docs: Fix typo s/thread_level/threat_level (#1067) 2019-05-20 21:36:34 +02:00
Victor M. Alvarez e83662f85c Fix buffer overflow in dotnet module. (#1063)
Credit to OSS-Fuzz.
2019-05-14 19:52:58 +02:00
Rosen Penev ee16b8cc4d libyara: Fix compilation - deprecated OpenSSL APIs (#1066) 2019-05-14 19:49:32 +02:00
Victor M. Alvarez d9c966b6d5 Bump version to 3.10 v3.10.0 v3.10.0-rc1 2019-05-02 10:06:12 +02:00