爬取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/

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值