python - 如何使用 request 和 bs4 模块而不是使用 Virustotal 的 PublicAPI 来获得 Virustotal 上 filehashes 的声誉?

标签 python beautifulsoup

我的要求是使用 python 检查 Virustotal 上多个文件哈希的声誉。我不想使用 Virustotal 的公共(public) API,因为有 4 个请求/分钟的上限。我想到使用 requests 模块和 beautiful soup 来完成此任务。

请检查以下链接: 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)

最佳答案

这是一种使用 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)

输出:

54 malicious out of 69

关于python - 如何使用 request 和 bs4 模块而不是使用 Virustotal 的 PublicAPI 来获得 Virustotal 上 filehashes 的声誉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56561140/

相关文章:

python - 从 HTML 中提取脚本标签内的字符串

python - strptime 默认为 1900

python - python 中的 xml 解析 : how to capture child's text when it is placed after grandchildren in the xml tree

Python:搬到新电脑

python - 如何从 "class"内的 html "span"中获取/抓取所有元素?

python - urllib2 一次又一次地检索带有 Â 和 & 符号/字母的 html,不确定如何删除它们

Python Anagrams 递归

python flask : query an item using GET

Python BeautifulSoup 解析

python - BeautifulSoup4 在 Python 3.x 中抛出错误