工具学习_VirusTotal使用
VirusTotal Intelligence 允许用户在其庞大的数据集中进行搜索,以查找符合特定条件的文件,例如哈希值、杀毒引擎检测结果、元数据信息、提交时的文件名、文件结构特征、文件大小等。可以说,它几乎是恶意软件领域的“谷歌搜索引擎”。
网页使用
通过哈希值检索文件:要搜索具有特定 MD5、SHA1 或 SHA256 值的文件,只需在主搜索框中输入相应的哈希值即可。例如,若要查找 SHA256 为
142b638c6a60b60c7f9928da4fb85a5a8e1422a9ffdc9ee49e17e56ccca9cf6e
的文件,只需输入该哈希值进行搜索,搜索结果如下所示。
通过运算符搜索文件:该查询语言支持一些布尔运算符,并允许使用括号将查询中的部分内容进行分组。支持的布尔运算符包括 AND、OR 和 NOT。
# 搜索所有包含无效 XREF 表的 PDF 文件
type:pdf tag:invalid-xref
type:pdf AND tag:invalid-xref# 搜索所有 DLL 文件或可执行文件(EXE)
type:pedll OR type:peexe# 搜索至少被一个杀毒软件识别为“zbot”家族
# 但没有被标记为“corrupt”(即不是损坏文件,能够在真实系统中运行)
engines:zbot NOT tag:corrupt# 搜索所有属于 Zbot、Dyreza 或 Dridex 家族
# 且文件未损坏的可执行银行木马样本
(engines:zbot OR engines:sinowal) NOT (tag:corrupt)
API使用
通过API上传文件:实现该功能需要补充 api_key 与所上传文件对应的位置,其python实现如下所示:
import requestsurl = "https://www.virustotal.com/api/v3/files"
api_key = "" headers = {"x-apikey": api_key
}# 要上传的文件路径
file_path = "./142b638c6a60b60c7f9928da4fb85a5a8e1422a9ffdc9ee49e17e56ccca9cf6e"proxies = {"http": "http://127.0.0.1:7890","https": "http://127.0.0.1:7890"
}with open(file_path, "rb") as f:files = {"file": f}response = requests.post(url, headers=headers, files=files, proxies=proxies)print(response.status_code)
print(response.json())
通过API分析上传的文件:实现该功能需要补充 api_key 与上一步返回的样本 id,其python实现如下所示:
import requestsurl = "https://www.virustotal.com/api/v3/analyses/MTI2MDJkZTY2NTlhMzU2MTQxZTc0NGJmNTY5ZTdlNTY6MTc0NzEyMzQ1MQ=="
api_key = "" headers = {"accept": "application/json","x-apikey": api_key
}proxies = {"http": "http://127.0.0.1:7890","https": "http://127.0.0.1:7890"
}response = requests.get(url, headers=headers, proxies=proxies)print(response.status_code)
print(response.json())
通过API获取样本的报告:实现该功能需要补充 api_key 与样本的哈希,其python实现如下所示:
import pdb
import json
import requestsurl = "https://www.virustotal.com/api/v3/files/142b638c6a60b60c7f9928da4fb85a5a8e1422a9ffdc9ee49e17e56ccca9cf6e"
api_key = ""headers = {"accept": "application/json","x-apikey": api_key
}proxies = {"http": "http://127.0.0.1:7890","https": "http://127.0.0.1:7890"
}response = requests.get(url, headers=headers, proxies=proxies)print(response.status_code)
print(response.json())if response.status_code == 200:try:response_data = response.json() # 获取JSON数据# 将返回的JSON内容保存到文件with open('sample_report.json', 'w', encoding='utf-8') as json_file:json.dump(response_data, json_file, ensure_ascii=False, indent=4)print("响应内容已保存到 'virustotal_response.json'")except ValueError:print("返回的内容不是有效的 JSON 格式")
else:print(f"请求失败,状态码:{response.status_code}")