百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Y

yarasafe

> 编程语言
开源

SAFE 嵌入,用于匹配 yara 中的函数

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

SAFE 嵌入,用于匹配 yara 中的函数

YARASAFE - Automatic Binary Function Similarity Checks with Yara

SAFE is a tool developed to create Binary Functions Embedding developed by Massarelli L., Di Luna G.A., Petroni F., Querzoni L. and Baldoni R. You can use SAFE to create your function embedding to use inside yara rules.

If you are interested take a look at our research paper: https://arxiv.org/abs/1811.05296

If you are using this for your research please cite:

latex
@inproceedings{massarelli2018safe,
  title={SAFE: Self-Attentive Function Embeddings for Binary Similarity},
  author={Massarelli, Luca and Di Luna, Giuseppe Antonio and Petroni, Fabio and Querzoni, Leonardo and Baldoni, Roberto},
  booktitle={Proceedings of 16th Conference on Detection of Intrusions and Malware & Vulnerability Assessment (DIMVA)},
  year={2019}
}

This is not the code for reproducing the experiments in the paper. If you are interested on it take a look at: https://github.com/gadiluna/SAFE

If you prefere to use PyTorch take a look at SAFEtorch: https://github.com/facebookresearch/SAFEtorch

Introduction

Using yarasafe you can easily create signature for binary functions without lookng at the assembly code at all! You just need to install the IDA Pro Plugins that you find the IDA Pro Plugin folder of this repository.

Once you have installed the plugin you can start creating embeddings for the function you want to match. These embeddings can be inserted into yara rules to match function using yara. To create powerful rule, you can combine multiple functions embeddings with standard yara rules.

In this repository you will find the plugin for IDA Pro, and the yarasafe module.

Yarasafe can match functions with more than 50 instructions and less than 150.

Requirements

  • python3
  • radare2
  • jansson

Quickstart

First of all install the IDA Pro plugin. You can find the instruction for doing it in the ida-pro-plugin folder of this repository. Then you can use our docker container or you can build yara with yarasafe module.

Docker

The fastest way to use yarasafe is to use our docker container.

Pull the images:

  • docker pull massarelli/yarasafe

Start the docker mounting the folder that contains the rule and the file to analyze:

  • docker run -v {FOLDER_TO_MOUNT}:/home/yarasafe/test -it massarelli/yarasafe bash

Launch yara inside the docker with your rule!

Ubuntu

  • Clone the repository:
bash
git clone https://github.com/lucamassarelli/yarasafe.git
  • Install yara dependencies:
bash
sudo apt-get install automake libtool make gcc flex bison 
sudo apt-get install libjansson-dev
  • Install radare2 on your system:
bash
git clone https://github.com/radare/radare2.git
cd radare2
./sys/install.sh
  • Install yarasafe dependencies:
bash
cd yarasafe/python_script
pip3 install -r requirements.txt
  • Compile:
bash
./bootstrap.sh
./configure
make
  • Export environment variable:
bash
export YARAPYSCRIPT={PATH_TO_YARASAFE_REPO}/python_script

MacOS

  • Clone the repository:
bash
git clone https://github.com/lucamassarelli/yarasafe.git
  • Install yara dependencies:
bash
brew install automake libtool flex bison 
brew install jansson
  • Install radare2 on your system:
bash
git clone https://github.com/radare/radare2.git
cd radare2
./sys/install.sh

Install yarasafe dependencies:

bash
cd yarasafe/python_script
pip3 install -r requirements.txt
  • Compile:
bash
./bootstrap.sh
./configure.sh
make
  • Export environment variable:
bash
export YARAPYSCRIPT={PATH_TO_YARASAFE_REPO}/python_script

Testing

Inside the folder rules you can find the rule sample_safe_rule.yar. This rule should trigger with any PE file:

bash
yara {PATH_TO_YARASAFE_REPO}/rules/sample_safe_rule.yar {FILES}

How to write your rule

To create your safe-yara-rule, you first need to create the embeddings for your function. In order to accomplish this, you can use the IDA Pro plugin shipped within this repository. Inside the folder ida-pro-plugin you can find all the information on how to run the plugin!

Once you get the embeddings for your functions, you just need to create the rule. An example of safe-yara-rule is:

…

The rule will be satisfied if inside the sample there is at least one function whose similarity with target is more then 0.95.

Adding safe to your version of yara

If you want to add safe to your yara repository:

  • Install all dependencies

  • Copy the file libyara/modules/safe.c into your_rep/libyara/modules/safe.c

  • Copy the folder libyara/include/python into your_rep/libyara/include

  • At the end of libyara/modules/module_list add ``` MODULE(safe)

  • Modify libyara/Makefile.am:

    • after the line:
    bash
    libyara_la_LDFLAGS = -version-number 3:8:1
    • add:
    bash
    libyara_la_LDFLAGS += -LPATH_TO_PYTHON3.*_LIB -lpython3.*m -ljansson 
  • Compile! `

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言