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
0 answers

Can YARA rule be implement in desktop app and how to use it?

Im currently doing a project that can detect Cryptojacking activity inside browser which is a desktop app. Instead of dealing with machine learning, i decided to use signature based detection tool which is YARA Rule. Im wondering how can i put the…
yoi
  • 1
0
votes
0 answers

Python FileNotFoundError: Could not find module 'venv\DLLs\libyara.dll' (or one of its dependencies) on Windows 11

In my Python code I use yara to compile yara rules. The documentation located at https://yara.readthedocs.io/en/stable/yarapython.html says that I can use it by importing it like this: import yara However when I run the code I…
Europa
  • 974
  • 12
  • 40
0
votes
2 answers

YARA Rule - Regex - String with at least one digit

I'm new to YARA rules and I wanted to build something really simple, a regex to match a hostname naming convention in my company. Something like: /AX[BCD][EFG](?=.*\d)[A-Z0-9]{5}/ where the last five characters HAVE TO have at least one digit. Is…
0
votes
1 answer

Matching Simple IP addresses in YARA using Hexadecimal Strings

I am trying to write YARA rules to match simple IP Addresses (eg: 127.0.0.1 or 192.168.1.1). I understand that I can do it using Regular Expressions based on this open-source Github example. However, YARA performance guidelines recommends us to…
Arka Mukherjee
  • 2,083
  • 1
  • 13
  • 27
0
votes
0 answers

Pdf string detection with yara rule not working

Hi everyone I have a pdf file word1.pdf which include hello_1234 and some other text. I want to detect all pdf file having string hello-1234. But the yara rule doesn't detect pdf with hello wird but it works for txt file. My yara rule is Rule…
0
votes
1 answer

Integrate Wazuh with Yara failed

I configured agent.conf with the following: no
doremi666
  • 121
  • 3
  • 15
0
votes
1 answer

Create yara file to return match on hex string

I'm on Mac os12.2.1 trying to run yara where it returns a match using basic hex string content. Yara rule (file name: rulehexstr) rule hex_new { strings: $hexnew = { 48 65 6c 6c 6f } condition: $hexnew } For the yara file, I used echo -n "HELLO"…
chocalaca
  • 330
  • 2
  • 17
0
votes
1 answer

Issues looping through .yar files for malware analysis

I cloned some yara rules from a repo to my /home/student/Downloads/yara-forensics/file directory. There are multiple .yar files shown below. I also have a fake malware file called sample.file located in /home/student/Downloads. I want to loop…
Nina G
  • 269
  • 5
  • 17
0
votes
1 answer

YARA: Match string without a specific substring

I'm trying to create a YARA rule which matches a URL plus one arbitrary directory, while excluding a specific directory. For example, it needs to match any of…
jdgregson
  • 1,457
  • 17
  • 39
0
votes
1 answer

How to write Yara script that creates a rule to match/detect strings contained within a file to another directory which contains a lot of such files?

The malware is of PE type. Use the magic bytes for this file type. To create a rule with a lot of strings it may be useful to write a script that creates the rule for you. The strings found through intelligence may be present in other files in…
0
votes
0 answers

Yara Strings without New Line

Do Yara strings need to be on different lines? For example, a typical Yara rule would be made like this rule DoSomething { strings: $hello = "hello" $world = "world" ascii nocase wide condition: any of…
0
votes
2 answers

result.append([1,matches['main'][0]['rule']]) and got messages TypeError: list indices must be integers, not str

im using this code below but it doesnt work.. content of filepath available here peid.yara. full code here integrated_feature_extraction.py def __init__(self,source,output,label): self.source = source self.output = output …
0
votes
2 answers

Yara regex for detecting port numbers not working

So I have been trying to build a regex that would detect port numbers(0-65535). I have tried the one given in the post below: Regex to validate port number this one…
0
votes
1 answer

Go bindings for YARA Doesn't return any matches

I've recently been testing the Go bindings for YARA for local yara scans (https://github.com/hillu/go-yara). I am using yara v4.0.0. I have only one .go file which has 2 routines: CompileAllRules and main. I don't get any matches whenever I try to…
0
votes
1 answer

Concatenating YARA rules in different format

I need to be able to match URLs in a dump file, surrounded by a certain byte pattern. I wrote the following YARA rule for that: rule yara_rule { strings: $beg = { 00 00 01 } $domain =…
trollpidor
  • 447
  • 5
  • 11