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
1
vote
1 answer

Scan entire network whith YARA rules

I have a task that I cannot figure out if ti is possible on how to be accomplished and if it is how can it be. First of all I am linux user. I want to scan the entire network using YARA rules from a host computer. My first thought is to use software…
Anagnostou John
  • 498
  • 5
  • 14
1
vote
2 answers

Process pool in Bash

I am trying to get a for loop that will only execute a threaded volatility yara scan module based off a list of rules. One scan per rule per core. Basically it should take the current number of vol.py processes running and check against the core…
JohnFowles
  • 13
  • 3
1
vote
1 answer

Installing YARA on OS X 10.11?

I have been trying to figure out how to install YARA on El Capitan, but even if I try disabling SIP, it just doesn't work. Does anyone know what's necessary to get it working?
T. Reed
  • 181
  • 1
  • 9
1
vote
1 answer

Writing yara rules in Python

I've been reading the documentation and I've been having a hard time trying to figure this out. A translation would help a lot. I came across this sample Perl rule online for Yara: rule BadBoy { strings: $a = "win.exe" $b =…
Kevin R.
  • 572
  • 2
  • 5
  • 15
0
votes
1 answer

How to write a REGEX search that will search through blocks of multiline patterns and only match on a block that contains a specified string?

I'm working to write a regex pattern that will search through multiple YARA rules within the same file. The pattern I've come up with already matches each YARA rule individually from beginning to end across multiple lines. Now I want to match the…
rilo
  • 1
  • 1
0
votes
0 answers

Yara command line throws non-ascii character error

I want to test Yara but when I try the following rule I get a non-ascii character error: rule basetest{ strings: $string1="pay" nocase $string2="immediately" nocase $text_sample="readers" nocase condition: any of them } the command I use is yara…
Kornuptiko
  • 17
  • 5
0
votes
0 answers

Understanding RAM address mapping in volatility

Using the volatility windows.vadyarascan plugin, I got a keyword hit at the virtual memory address 0x20600091b4a in the address space of process PID=2008. I want to check this location in the actual memory dump using WinHex. Using literal string…
user946822
  • 25
  • 3
0
votes
0 answers

Build yara static lib with a musl-gcc for rust project

I am trying to build yara static lib with a musl-gcc for my rust project. But when it is running CC="musl-gcc" \ CFLAGS="-I/usr/local/musl/include -I/usr/include/linux -I/usr/include/x86_64-linux-musl" \ LDFLAGS="-L/usr/local/musl/lib…
0
votes
0 answers

Yara Rules not matching a String - Windows Event

I need a little help: I was triggering "Registry persistence" events which can be related to a malware presence. Here is the Yara rule I tried to get triggered from Sysmon events (Event Viewer channel) rule RegistryPersistence {          strings:  …
0
votes
0 answers

Install yara-python gives "Cannot open include file: 'openssl/asn1.h'" on Windows 11

When I try to install yara-python by issuing the following command: C:\Users\admin\code\my-project\venv\Scripts\activate.bat pip install yara-python I get the following error message: "C:\Program Files (x86)\Microsoft Visual…
Europa
  • 974
  • 12
  • 40
0
votes
1 answer

Counting regex strings in Yara

I would like to know if we can count regex string in Yara? I am not sure if Yara support this? rule CountExample { strings: $a = "dummy1" $b = /dummy\d+/ condition: #a == 6 and #b > 10 } There only match condition…
Jimmy
  • 1
  • 1
  • 3
0
votes
1 answer

Specifying an unknown number of conditions

Want to write a Yara rule that fires on a range of strings hitting. E.g.: $rrr = "shell" $var1 = "cheese" $var2 = "beef" $var3 = "chicken" condition: $rrr and ($var*) > 2 Can't seem to get anything like this to compile. Tried the above, tried…
0
votes
0 answers

Yara match regex against variable from module

I've written my own module to parse a certain file format. Certain fields of this format are saved into variables with set_string https://yara.readthedocs.io/en/stable/writingmodules.html#setting-variable-s-values Now I want to write a rule, that…
0
votes
0 answers

Base64 input check for Yara rules

so I started using Yara rules, I have a mysql database with files and their base64 encodes saved in a column. Is there any way to input in Yara a base64 string without storing it in a file? if so, what is the command? If not, is there a way in…
IdanB
  • 167
  • 1
  • 3
  • 13
0
votes
0 answers

getting error while compiling yara in VC++ libyara

I want use yara library in my Visual studio C++ program. I used vcpkg to install yara 64 bit on my system. Here is a simple code to initialize yara. #include #include int main() { yr_initialize(); } I get linker errors while…
user846940
  • 29
  • 4