yara-python
は、PythonプログラムからYARAを使用できるようにするライブラリです。YARAのすべての機能をカバーしており、ルールのコンパイル、保存、ロードから、ファイル、文字列、プロセスのスキャンまで行うことができます。
yara-pythonのインストール
yara-python
のインストールは非常に簡単で、pipを使用するのが最も簡単な方法です。
$ pip install yara-python
しかし、GitHubからソースを取得し、自分でコンパイルすることも可能です。
$ git clone --recursive https://github.com/VirusTotal/yara-python
$ cd yara-python
$ python setup.py build
$ sudo python setup.py install
yara-pythonの使用方法
以下に、yara-python
を使用した小さな例を示します。
>>> 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) # [$a]
>>> print(matches[0].strings[0].identifier) # $a
>>> print(matches[0].strings[0].instances) # [lmn]
>>> print(matches[0].strings[0].instances[0].offset) # 10
>>> print(matches[0].strings[0].instances[0].matched_length) # 3
このように、yara-python
を使用すると、PythonプログラムからYARAの強力な機能を簡単に利用することができます。セキュリティ分析やマルウェア解析に興味がある方にとって、yara-python
は非常に有用なツールとなるでしょう。