从virustotal上下载病毒样本

 

#!/usr/bin/env python

import os
import csv
#import Queue
import zipfile
import requests
import argparse
import multiprocessing

# TODO: Don't hardcode the relative path?
samples_path = "gym_malware/envs/utils/samples/"
hashes_path = "gym_malware/envs/utils/sample_hashes.csv"
vturl = "https://www.virustotal.com/intelligence/download"


def get_sample_hashes():
    hash_rows = []
    with open(hashes_path) as csvfile:
        for row in csv.DictReader(csvfile):
            hash_rows.append(row)
    return hash_rows


def vt_download_sample(sha256, sample_path, vtapikey):
    tries = 0
    success = False
    while not success and tries < 10:
        resp = requests.get(vturl, params={"hash": sha256, "apikey": vtapikey})

        if not resp.ok:
            tries += 1
            continue

        else:
            success = True

    if not success:
        return False

    with open(sample_path, "wb") as ofile:
        ofile.write(resp.content)

    return True


def download_worker_function(download_queue, vtapikey):
    while True:
        try:
            sha256 = download_queue.get()
        except queue.Empty:
            continue

        if sha256 == "STOP":
            download_queue.task_done()
 
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
加入这些API可以增强你的搜索和安全分析能力。以下是每个API的简要介绍和如何使用它们: 1. fofa API:可以使用 Fofa API 来搜索互联网上的设备和服务。在使用之前,你需要注册并获取 API 密钥。然后,你可以使用 API 来执行各种查询,例如根据 IP 地址、端口、协议、地理位置等来搜索设备。示例代码如下: ```python import requests api_email = 'your_email' api_key = 'your_api_key' query = 'title="admin" && country="CN"' res = requests.get(f"https://fofa.so/api/v1/search/all?email={api_email}&key={api_key}&qbase64={query}") print(res.json()) ``` 2. Shodan API:与 Fofa API 类似,Shodan API 也可以用来搜索互联网上的设备和服务。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种查询。例如,根据 IP 地址、端口、协议、服务等搜索设备。示例代码如下: ```python import shodan api_key = 'your_api_key' api = shodan.Shodan(api_key) query = 'apache' results = api.search(query) for result in results['matches']: print(result['ip_str']) ``` 3. GitHub API:GitHub API 可以用来搜索代码库、获取代码库信息、获取提交历史记录等。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种查询。例如,搜索代码仓库、获取仓库信息、获取提交历史记录等。示例代码如下: ```python import requests api_key = 'your_api_key' headers = {'Authorization': f'token {api_key}'} # Search repositories query = 'language:python' res = requests.get(f'https://api.github.com/search/repositories?q={query}', headers=headers) print(res.json()) # Get repository information repo_name = 'torvalds/linux' res = requests.get(f'https://api.github.com/repos/{repo_name}', headers=headers) print(res.json()) # Get commit history res = requests.get(f'https://api.github.com/repos/{repo_name}/commits', headers=headers) print(res.json()) ``` 4. VirusTotal API:VirusTotal API 可以用来分析文件、URL 和 IP 地址的恶意程度。你需要注册并获取 API 密钥,然后可以使用 API 来执行各种分析。例如,分析文件、URL 和 IP 地址的恶意程度,获取恶意软件样本等。示例代码如下: ```python import requests api_key = 'your_api_key' headers = {'x-apikey': api_key} # Analyze file file_hash = 'e8f91b8e4b9f0dbd382bfe6c9f776b2c' res = requests.get(f'https://www.virustotal.com/api/v3/files/{file_hash}', headers=headers) print(res.json()) # Analyze URL url = 'https://www.google.com' res = requests.post(f'https://www.virustotal.com/api/v3/urls', headers=headers, json={'url': url}) print(res.json()) # Analyze IP address ip_address = '8.8.8.8' res = requests.get(f'https://www.virustotal.com/api/v3/ip_addresses/{ip_address}', headers=headers) print(res.json()) ``` 以上是如何使用 fofa、shodan、github 和 virustotal 的 API 进行搜索和分析的示例代码。注意,在使用这些 API 时需要遵守相应的使用条款和政策。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值