Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
工具/GitHubGitHub/gadiluna/safe
逆向工程二进制分析机器学习论文与研究
GitHubgadiluna/safe

SAFE

SAFE: 面向二进制相似性的自注意力函数嵌入

查看仓库
1764143年前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

SAFE:自注意力函数嵌入

论文

本软件是我们学术研究的成果。请参阅我们的arXiv论文:arxiv

如果您使用此代码,请引用我们的学术论文如下:

root@kitploit:~
@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}
}

你需要什么

你需要在系统中安装 radare2。

快速开始

要创建函数的嵌入:

root@kitploit:~
git clone https://github.com/gadiluna/SAFE.git
pip install -r requirements
chmod +x download_model.sh
./download_model.sh
python safe.py -m data/safe.pb -i helloworld.o -a 100000F30

得到嵌入后做什么?

一旦你有了两个嵌入 embedding_x 和 embedding_y,你可以计算对应函数的相似度,方法如下:

root@kitploit:~
from sklearn.metrics.pairwise import cosine_similarity

sim=cosine_similarity(embedding_x, embedding_y)
 

所需数据

SAFE 需要少量信息即可工作。其中两个是必需的:一个模型告诉 SAFE 如何将汇编指令转换为向量(i2v 模型),以及一个模型告诉 SAFE 如何将二进制函数转换为向量。 这两个模型可以通过以下命令下载:

root@kitploit:~
./download_model.sh

下载器会将模型下载并放置在 data 目录中。 下载后的目录树应如下所示:

root@kitploit:~
safe/-- githubcode
     \
      \--data/-----safe.pb
               \
                \---i2v/
            

safe.pb 文件包含用于将二进制函数转换为向量的 safe 模型。 i2v 文件夹包含 i2v 模型。

硬核细节

此部分包含重现我们实验所需的细节,如果你是 SAFE 的用户,可以跳过。

Safe.pb

这是针对 AMD64 架构的冻结 TensorFlow 训练模型。你可以通过以下方式将其导入到你的项目中:

root@kitploit:~
 import tensorflow as tf
 
 with tf.gfile.GFile("safe.pb", "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

 with tf.Graph().as_default() as graph:
    tf.import_graph_def(graph_def)
    
 sess = tf.Session(graph=graph)

参见文件:neural_network/SAFEEmbedder.py

i2v

i2v 文件夹包含两个文件: 一个矩阵,其中每一行是一条 asm 指令的嵌入。 一个 JSON 文件,包含将 asm 指令映射到上述矩阵行号的字典。 参见文件:asm_embedding/InstructionsConverter.py

训练模型

如果你想使用我们的数据集训练模型,首先需要运行:

root@kitploit:~
 python3 downloader.py -td

这将把数据集下载到 data 文件夹中。注意数据集是压缩的,所以你需要自行解压。这些数据将是 SQLite 数据库。 要开始训练,请使用 neural_network/train.sh。 可以通过更改 train.sh 中的参数来选择数据库。 如果想了解数据集的详细信息,请参阅我们的论文。

创建你自己的数据集

如果你想创建自己的数据集,可以使用 dataset creation 文件夹中的脚本 ExperimentUtil。

创建函数知识库

如果你想使用 SAFE 二进制代码搜索引擎,可以使用脚本 ExperimentUtil 创建知识库。 然后可以通过 function_search 中的脚本在其中搜索。

相关项目

  • YARASAFE:使用 Yara 进行自动二进制函数相似性检查 (https://github.com/lucamassarelli/yarasafe)
  • SAFEtorch:SAFE 神经网络的 PyTorch 实现 (https://github.com/facebookresearch/SAFEtorch)

致谢

在我们的代码中,我们使用 godown 从 Google Drive 下载数据。感谢 godown 的创建者 circulosmeos。

感谢 Davide Italiano 的有益讨论。

下载工具