如何使用请求和bs4模块而不使用Virustotal的PublicAPI在Virustotal上获得文件哈希的声誉?

时间:2019-06-12 11:28:40

标签: python beautifulsoup

我的要求是使用python检查Virustotal上多个文件哈希的信誉。我不想使用Virustotal的Public API,因为每分钟最多只能有4个请求。我想到了使用请求模块和精美的汤来完成此任务。

请检查以下链接: https://www.virustotal.com/gui/file/f8ee4c00a3a53206d8d37abe5ed9f4bfc210a188cd5b819d3e1f77b34504061e/summary

我需要为此文件捕获54/69。我在excel中有一个文件哈希列表,一旦可以完成一次哈希处理,就可以循环获取检测状态。

但是我无法获得特定数量的引擎将文件哈希检测为恶意。计数的CSS选择器仅给我一个空白列表。请帮忙。请检查我在下面编写的代码:

import requests
from bs4 import BeautifulSoup

filehash='F8EE4C00A3A53206D8D37ABE5ED9F4BFC210A188CD5B819D3E1F77B34504061E'
filehash_lower = filehash.lower()
URL = 'https://www.virustotal.com/gui/file/' +filehash+'/detection'

response = requests.get(URL)
print(response)

soup = BeautifulSoup(response.content,'html.parser')
detection_details = soup.select('div.detections')
print(detection_details)

1 个答案:

答案 0 :(得分:0)

这是使用ajax调用的一种方法:

import requests
import json

headers = {
    'pragma': 'no-cache',
    'x-app-hostname': 'https://www.virustotal.com/gui/',
    'dnt': '1',
    'x-app-version': '20190611t171116',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6,mt;q=0.5',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
    'accept': 'application/json',
    'cache-control': 'no-cache',
    'authority': 'www.virustotal.com',
    'referer': 'https://www.virustotal.com/',
}

response = requests.get('https://www.virustotal.com/ui/files/f8ee4c00a3a53206d8d37abe5ed9f4bfc210a188cd5b819d3e1f77b34504061e', headers=headers)
data = json.loads(response.content)
malicious = data['data']['attributes']['last_analysis_stats']['malicious']
undetected = data['data']['attributes']['last_analysis_stats']['undetected']

print(malicious, 'malicious out of', malicious + undetected)

输出:

  在69个恶意软件中,有

54个恶意软件