Questions tagged [yara]

YARA is a tool aimed at (but not limited to) helping malware researchers to identify and classify malware samples.

yara-python

With this library you can use YARA from your Python programs. It covers all YARA's features, from compiling, saving and loading rules to scanning files, strings and processes.

Here it goes a little example:

>>> import yara
>>> rule = yara.compile(source='rule foo: bar {strings: $a = "lmn" condition: $a}')
>>> matches = rule.match(data='abcdefgjiklmnoprstuvwxyz')
>>> print(matches)
[foo]
>>> print(matches[0].rule)
foo
>>> print(matches[0].tags)
['bar']
>>> print(matches[0].strings)
[(10L, '$a', 'lmn')]

Installation

The easiest way of installing YARA is by using pip:

 $ pip install yara-python

But you can also get the source from GitHub and compile it yourself:

  $ git clone --recursive https://github.com/plusvic/yara-python
  $ cd yara-python
  $ python setup.py build
  $ sudo python setup.py install

Notice the --recursive option used with git. This is important because we need to download the yara subproject containing the source code for libyara (the core YARA library). It's also important to note that the two methods above link libyara statically into yara-python. If you want to link dynamically against a shared libyara library use:

$ sudo python setup.py install --dynamic-linking

For this option to work you must build and install YARA separately before installing yara-python.

Documentation

Find more information about how to use yara-python at https://yara.readthedocs.io/en/latest/yarapython.html.

63 questions
0
votes
1 answer

Yara Rule - Regex - syntax error: unexpected ')'

This answer here - https://stackoverflow.com/posts/58483988/revisions (definitely worth reading to understand the ostensible regex rules for yara) - appears to work for about 20 of the given binaries I'm looking for, such as the…
dipl0
  • 1,017
  • 2
  • 13
  • 36
0
votes
1 answer

Yara Rule - Regex - Matching Wildcard

Regex has always been somewhat of a black box for me. I believe I need to use some regex to write some of the following yara rules. Yara rules use regex in order to match execution of particular binaries within malware. Knowledge of this is not…
dipl0
  • 1,017
  • 2
  • 13
  • 36
0
votes
0 answers

Disassembling a .NET manually

I would like to statically sign a malware, specifically MSIL Crypter, with a YARA rule. I want to sign specific functions (Assembly.Load for example) but I couldn't find an informative documentation about how to disassemble a .NET binary into CIL…
user218182
0
votes
1 answer

Call terminal input at start of bash script

I downloaded Yara from Git. When I run yara from terminal, it works as I would expect. I want to know if it's possible to create a bash script that would let me call yara and then execute my command. Any help would be greatly appreciated! yara -w…
0
votes
1 answer

Yara rule for searching in an eml file

Just starting out with yara and running into some issues. When I run yara to test a rule that I am working on (this rule will look at .eml files), I write the results to a file. When I look at the file I wrote to, nothing is there. Here is my rule.…
0
votes
2 answers

Merge all Yara rules from a Yara github repository in one .yar file

There is an index file in the official Yara rules repository git hub. This one : https://github.com/Yara-Rules/rules/blob/master/index.yar I want to create a script in bash or other language able to merge all yara files in a .yar (like the…
Toms lns
  • 39
  • 8
0
votes
2 answers

Go strings.Contains() 2x slower than Python3?

Am converting a text pattern scanner from Python3 to Go1.10, but am surprised it is actually 2 times slower. Upon profiling, the culprit is in strings.Contains(). See the simple benchmarks below. Did I miss anything? Could you recommend a faster…
Willem
  • 3,043
  • 2
  • 25
  • 37
0
votes
1 answer

Unable to open/include a YARA file

I created a script that analyzes files based on yara rules ( the yara are the ones from this repository https://github.com/Yara-Rules/rules). My script import a yara file that include all other rules.When i try to compile it, i receive a syntax…
Bonfel
  • 11
  • 4
0
votes
0 answers

Regex to look for cyber squatting or spoofing?

I am trying to create a bit of regex that matches any deviation of the domain “example.com”. Finding characters before or after “example” is easy enough. Finding deviations of “example” is where it gets challenging for me. I could do something like…
Brandon Force
  • 73
  • 1
  • 8
0
votes
1 answer

Why does it seem to be that several different hexadecimal numbers represented as the dot (".") symbol?

I noticed that the symbol . doesn't represent the same hexadecimal number when I tried to tune my YARA rules that I run on VirusTotal. When I tried to exclude the false positive-generating text string .sample., it would not get excluded because .…
skooog
  • 89
  • 2
  • 12
0
votes
1 answer

"Main" YARA rule matches files that seem to not satisfy the private rule from the same ruleset

I run several rulesets using the VirusTotal "hunting" feature and I use private YARA rules to filter out false positives. For example: private rule isDex { meta: description = "To filter out DEX files that fire many FPs" strings: …
skooog
  • 89
  • 2
  • 12
0
votes
1 answer

Merge clamAV with YARA and Python3

I want to merge clamAV python and YARA rules. The target is to, on demand, scan with YARA rules that i have made. I wrote this simple script and work just fine import…
Anagnostou John
  • 498
  • 5
  • 14
0
votes
2 answers

How can I use pe.entry_point to write YARA rules?

I wrote condition in YARA rule like this pe.entry_point == {12 A5 26} but I am getting unexpected _HEX_STRING_ error. What is the problem? How can I get address of entry_point? What is the type of output of pe.entry_point?
Pasazade
  • 1
  • 2
0
votes
0 answers

Searching for strings in office documents using YARA

Is it possible to create PCRE based Yara rules to identify matching office documents, like .docx, .xls, .ppt, .pdf, etc.? I am quite new to Yara, and so fascinated to see such a huge buzz around it. Will be most grateful for all comments, and any…
mdk
  • 6,225
  • 1
  • 25
  • 30
0
votes
0 answers

Executing yara with powershell on domain computers

I'm having issues with running executing Yara with Powershell on domain computers. Transfer Yara to computer: PS> copy yara.exe \\PC1-PC.mydomain.com\C$\TEMP\yara.exe Transfer rules: PS> copy rules.yara \\PC1-PC\C$\TEMP\rules.yara Execute scan…
Ray
  • 33
  • 4