爬取MalwareBazaar实现恶意样本数据自由

最近在做恶意软件的研究时,发现一个主要问题就是缺少样本,
在网上搜索后发现各个开源的数据集都有各种各样的问题,如
这个DikeDataSet:
https://github.com/iosifache/DikeDataset
优点是有白样本,缺点是黑样本分布不均且主要集中在一个家族里

发现有一个比较好用的开源数据平台MalwareBazaar:
https://bazaar.abuse.ch/browse/
可以自由下载所需要的恶意数据,而且可以批量查询报告
因此根据官方的api介绍(https://bazaar.abuse.ch/api/
自己做了个爬取脚本:

#!/usr/bin/env python3
import requests
import os
import pyzipper

__author__ = "Corsin Camichel"
__copyright__ = "Copyright 2020, Corsin Camichel"
__license__ = "Creative Commons Attribution-ShareAlike 4.0 International License."
__version__ = "1.0"
__email__ = "cocaman@gmail.com"


def pe_downloader(sample_sha: str, save_folder='./', unzip=False):
    """
    根据sha256下载样本,默认zip格式不解压
    :param sample_sha:文件sha256
    :param save_folder:保存的路径
    :param unzip:是否解压
    :return: True/False 表示下载是否成功
    """
    if len(sample_sha) != 64:
        print(sample_sha, "不是sha256")
        return False

    unzip_password = b'infected'
    headers = {'API-KEY': ''}

    if not save_folder.endswith('/'):
        save_folder += '/'

    if not os.path.exists(save_folder):
        # 如果保存目录不存在则创建
        os.makedirs(save_folder)
    data = {
        'query': 'get_file',
        'sha256_hash': sample_sha,
    }
    if os.path.exists(save_folder + sample_sha + '.zip') or os.path.exists(save_folder+sample_sha):
        print("该样本已存在")
        return False

    response = requests.post('https://mb-api.abuse.ch/api/v1/', data=data, timeout=15, headers=headers,
                             allow_redirects=True)
    if 'file_not_found' in response.text:
        print("Error: 未找到样本")
        return False

    open(save_folder + sample_sha + '.zip', 'wb').write(response.content)
    if unzip:
        with pyzipper.AESZipFile(save_folder + sample_sha + ".zip") as zf:
            zf.pwd = unzip_password
            zf.extractall(save_folder)
            print("样本 \"" + sample_sha + "\" 下载解压成功.")
        os.remove(save_folder + sample_sha + '.zip')
    else:
        print("样本 \"" + sample_sha + "\" 下载成功.")

    return True


if __name__ == "__main__":
    pe_downloader("adffd52446d0d94c4f726205482a0c062248d6eb35948df937336957cf747db8",
                  save_folder='testdownload/', unzip=False)

完整的代码在github:
https://github.com/CaLlMeErIC/BazaarCrawler/

相关推荐

  1. MalwareBazaar实现恶意样本数据自由

    2024-03-25 19:00:08       49 阅读
  2. 用Python实现对Ajax数据

    2024-03-25 19:00:08       46 阅读
  3. 数据】Jsoup数据的使用

    2024-03-25 19:00:08       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-25 19:00:08       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-25 19:00:08       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-25 19:00:08       87 阅读
  4. Python语言-面向对象

    2024-03-25 19:00:08       96 阅读

热门阅读

  1. C++多态

    C++多态

    2024-03-25 19:00:08      41 阅读
  2. Python从入门到精通秘籍十九

    2024-03-25 19:00:08       51 阅读
  3. 【软考】蠕虫病毒

    2024-03-25 19:00:08       49 阅读
  4. 用Python做一个植物大战僵尸

    2024-03-25 19:00:08       51 阅读
  5. 工作中常用的git命令

    2024-03-25 19:00:08       34 阅读
  6. 在树莓派4B上安装Ubuntu Server 20

    2024-03-25 19:00:08       44 阅读
  7. 动态规划——零钱兑换

    2024-03-25 19:00:08       38 阅读
  8. 第十五节 JDBC Statement对象执行批量处理实例

    2024-03-25 19:00:08       42 阅读
  9. sqllabs1-7sql注入

    2024-03-25 19:00:08       35 阅读