Repository navigation
Expand file tree
/
Copy pathMark.py
More file actions
77 lines (72 loc) · 2.43 KB
/
Copy pathMark.py
File metadata and controls
77 lines (72 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import json
import urllib
import urllib2
import os
import sys
import time
import datetime
TXTADDRESS="HashAndPath.txt"
apikey="c0589a92e5297b5f0247c7e82ce147eab690b612c5705748d77dc754c371693a" #vt账号的key
url = "https://www.virustotal.com/vtapi/v2/file/report"
def readTheTxt(address):
file = open(address)
searchCount=0
while 1:
searchCount=searchCount+1
line = file.readline()#暂时没有用
line2 = file.readline()#路径
line3 = file.readline()#哈希值
if not line:
break #end
#strmd5=line[line.rfind("\\")+1:line.rfind(".")]
line2 = line2.strip('\n')#去回车
line2=line2[1:]#去首部的路径
line3 = line3.strip('\n')#去回车
line3=line3[1:]#去首部的哈希值
print("第 "+str(searchCount)+" 哈希值")
#print(line2)
#print(line3) # do something
VTextrect(line3,line2)#进行API分析
if searchCount%4 == 0: #1分钟查4次
print("-------------------Now it is waiting----------------------")
time.sleep(60)#睡眠时间
def VTextrect(md5,src):
param = {'resource':md5, 'apikey':apikey, 'allinfo': '1'}
data = urllib.urlencode(param)
result = urllib2.urlopen(url, data)
q=result.read()
if(q==""):
print("The Api is request over")
file_io.write("4"+src+'\n')
return #这里的有的文件不在VT库中,所以不会反悔任何东西
jsondata = json.loads(q)
response_code=jsondata['response_code']
if(response_code==0):
print("Not exist in VT")
file_io.write("3"+src+'\n')
if(response_code==1):
#nameofsha256=jsondata['sha256']
#print(nameofsha256)
positives=jsondata['positives']
if(positives==0):
print("It'is Benign")
file_io.write("1"+src+'\n')
else:
print("It'is Malware")
file_io.write("2"+src+'\n')
return
def spendHour(time1,time2):
print("\n========Time Message================")
print("The start time %s" % time1)
print("The end time %s" % time2)
spend=(time2-time1).seconds
m,s=divmod(spend,60)
h,m=divmod(m,60)
print("Total time [%d:%02d:%02d]" % (h, m, s))#时间差
start=datetime.datetime.now()#开始时间
file_io=open('Report.txt',mode='a+')
readTheTxt(TXTADDRESS)
file_io.close()
end=datetime.datetime.now()#结束时间
spendHour(start,end)#调用时间输出函数
print("\n========All File has finished================")