首页 > 解决方案 > 使用 Virustotal 和 Python 提取应用程序哈希的分数

问题描述

我正在尝试使用 VirusTotal API 获取应用程序哈希和 IP 地址的分数。

该代码适用于 IP 地址。请看下面的代码:

###### Code starts 
import json
import urllib.request
from urllib.request import urlopen
url = 'https://www.virustotal.com/vtapi/v2/ip-address/report'
parameters = {'ip': '90.156.201.27', 'apikey': 'apikey'}

response = urllib.request.urlopen('%s?%s' % (url, urllib.parse.urlencode(parameters))).read()
response_dict = json.loads(response)
#### Code ends

但同样不适用于应用程序哈希。以前有没有人研究过这个:

例如,应用程序哈希“f67ce4cdea7425cfcb0f4f4a309b0adc9e9b28e0b63ce51cc346771efa34c1e3”的得分为 29/67。请参阅此处的图像。有没有人在这个 API 上工作来获得分数。

标签: pythonjsonsha

解决方案


您可以尝试与python 库中的请求模块相同

import requests
params = {'apikey': '<your api key>', 'resource':<your hash>}
headers = {"Accept-Encoding": "gzip, deflate","User-Agent" : "gzip,  My Python 
requests library example client or username"}
response_dict={}
try:
    response_dict = requests.get('https://www.virustotal.com/vtapi/v2/file/report', 
     params=params).json()

except Exception as e:
        print(e)

您可以使用它来获取数据:

if response_dict.get("response_code") != None and response_dict.get("response_code") > 0:
        # Hashes
        sample_info["md5"] = response_dict.get("md5")
        # AV matches
        sample_info["positives"] = response_dict.get("positives")
        sample_info["total"] = response_dict.get("total")
        print(sample_info["md5"]+" Positives: "+str(sample_info["positives"])+"Total "+str(sample_info["total"]))
    else:
        print("Not Found in VT")

作为参考检查virustotalapi,它允许您同时使用多个 api 密钥。


推荐阅读