python實現上傳樣本到virustotal並查詢掃描資訊的方法_python

來源:互聯網
上載者:User

本文執行個體講述了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程式設計有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.