python实现上传样本到virustotal并查询扫描信息的方法
作者:shichen2014 时间:2023-06-30 19:59:45
本文实例讲述了python实现上传样本到virustotal并查询扫描信息的方法。分享给大家供大家参考。具体方法如下:
import simplejson
import urllib
import urllib2
import os
MD5 = "5248f774d2ee0a10936d0b1dc89107f1"
MD5 = "12fa5fb74201d9b6a14f63fbf9a81ff6" #do not have report on virustotal.com
########################################################################
APIKEY = "e0a50a50e77fxxxxxxxxxxxxxx4f17e31 这里用你自己在virustotal上申请的账号的KEY"
class VirusTotal:
""""""
def __init__(self, md5):
"""Constructor"""
self._virus_dict = {}
self._md5 = md5
def repr(self):
return str(self._virus_dict)
def submit_md5(self, file_path):
import postfile
#submit the file
FILE_NAME = os.path.basename(file_path)
host = "www.virustotal.com"
selector = "https://www.virustotal.com/vtapi/v2/file/scan"
fields = [("apikey", APIKEY)]
file_to_send = open(file_path, "rb").read()
files = [("file", FILE_NAME, file_to_send)]
json = postfile.post_multipart(host, selector, fields, files)
print json
pass
def get_report_dict(self):
result_dict = {}
url = "https://www.virustotal.com/vtapi/v2/file/report"
parameters = {"resource": self._md5,
"apikey": APIKEY}
data = urllib.urlencode(parameters)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json = response.read()
response_dict = simplejson.loads(json)
if response_dict["response_code"]: #has result
scans_dict = response_dict.get("scans", {})
for anti_virus_comany, virus_name in scans_dict.iteritems():
if virus_name["detected"]:
self._virus_dict.setdefault(anti_virus_comany, virus_name["result"])
return self._virus_dict
返回的结果为:{u'Sophos': u'Sus/Behav-1010'},如果有扫描出的结果的话..
调用的方法如下:
MD5 = "12fa5fb74201d9b6a14f63fbf9a81ff6" #do not have report on virustotal.com
MD5 = "5248f774d2ee0a10936d0b1dc89107f1"
FILE_PATH = r"D:\backSample\10\9af41bc012d66c98ca2f9c68ba38e98f_ICQLiteShell.dll"
from getVirusTotalInfo import VirusTotal
#得到扫描结果并打印出来
virus_total = VirusTotal(MD5)
print virus_total.get_report_dict()
#提交文件到扫描,以后就可以根据这个MD5取扫描结果了
virus_total.submit_md5(FILE_PATH)
希望本文所述对大家的Python程序设计有所帮助。
标签:python,上传,查询
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 多核并行计算的示例代码
2022-08-18 11:20:36
![](https://img.aspxhome.com/file/2023/2/80492_0s.jpg)
Python2与python3中 for 循环语句基础与实例分析
2022-08-12 05:05:01
![](https://img.aspxhome.com/file/2023/8/127308_0s.jpg)
python 遍历可迭代对象的实现方法
2021-03-02 07:13:07
基于python实现自动化办公学习笔记(CSV、word、Excel、PPT)
2022-09-21 05:14:57
Django中select_related和prefetch_related的用法与区别详解
2023-10-08 12:38:08
![](https://img.aspxhome.com/file/2023/9/99409_0s.jpg)
SQL中的三种去重方法小结
2024-01-23 20:19:15
Python中的np.random.seed()随机数种子问题及解决方法
2023-01-15 20:14:02
![](https://img.aspxhome.com/file/2023/8/92378_0s.jpg)
多次执行mysql_fetch_array()的指针归位问题探讨
2024-01-16 00:16:16
VSCode远程连接服务器报错:Could not establish connection to
2023-10-03 03:02:17
![](https://img.aspxhome.com/file/2023/9/114709_0s.png)
Oracle如何获取数据库系统的当前时间
2024-01-21 22:20:55
Python中bisect的使用方法
2021-12-03 05:56:12
Python GUI自动化实现绕过验证码登录
2023-06-25 05:18:25
python实现隐马尔科夫模型HMM
2023-05-05 13:33:57
JavaScript数字和字符串转换示例
2024-05-02 16:27:07
如何使用Python 抓取和优化所有网站图像
2022-05-18 12:36:00
![](https://img.aspxhome.com/file/2023/0/77660_0s.png)
vue和iview实现Scroll 数据无限滚动功能
2024-04-28 09:22:23
![](https://img.aspxhome.com/file/2023/4/133104_0s.jpg)
详解Python小数据池和代码块缓存机制
2023-02-07 06:54:28
Git的基础文件操作初始化查看添加提交示例教程
2023-12-25 19:43:21
python list语法学习(带例子)
2023-08-20 05:36:40
python自定义封装带颜色的logging模块
2022-06-17 04:23:48
![](https://img.aspxhome.com/file/2023/9/95669_0s.jpg)