Virustotal——md5转sha256

来源:互联网 发布:java 工程师 简历 编辑:程序博客网 时间:2024/05/18 22:51

使用场景:有一些恶意文件的md5值要转换成sha256,用Virustotal来做中转
语言:Python
准备:md5值的文件source.txt
      Virustotal的API KEY(申请一个账户,账户里面有【My API Key】)
注意:Virustotol.com的访问需要翻墙,我的Chrome浏览器安装了代理,所以headers参数的User-Agent是Chrome的版本。
Chrome浏览器版本的查看方式:输入chrome://version查看,用户代理即User-Agent

#coding : utf-8import requestsimport jsonimport timedef main():    headers = {          "Accept-Encoding" : "gzip, deflate",          "User-Agent" : "gzip,  your browser's User-Agent"      }    f = open('source.txt', 'r') #md5值的文件    f_result = open('result.txt', 'w') #保存sha256结果    f_no = open('no.txt', 'w') #保存VT没有样本的md5    searchCount = 0    try:        while True:            line = f.readline().strip()            params = {                'apikey' : 'your API Key here',                 'resource' : line            }            if line:                searchCount = searchCount + 1                response = requests.get('https://www.virustotal.com/vtapi/v2/file/report', params=params, headers=headers)                if response.text != '':                    data = json.loads(response.text)                    if data['response_code']==0:                        print "nothing",line                        f_result.write("nothing" + '\n')                        f_no.write(line+'\n')                    else:                        print data['sha256'], data['md5']                        f_result.write(data['sha256'] + '\n')            else:                    break            if searchCount % 4 == 0: #1分钟查4次                time.sleep(60)    except IOError, error:        print "Caught error : "     finally:        f.close()        f_result.close()        f_no.close()if __name__ == '__main__':    main()

参考:
https://www.virustotal.com/en/documentation/public-api/
http://wangzhixian.org/PythonSpider/在VirusTotal上利用文件哈希批量搜索/article.html

原创粉丝点击