forked from Te-k/analyst-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_hashes.py
More file actions
57 lines (46 loc) · 1.65 KB
/
Copy pathcheck_hashes.py
File metadata and controls
57 lines (46 loc) · 1.65 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
import os
import argparse
import requests
def get_virustotal_report(hashes):
apikey = "233f22e200ca5822bd91103043ccac138b910db79f29af5616a9afe8b6f215ad"
url = "https://www.virustotal.com/partners/sysinternals/file-reports?apikey={}".format(apikey)
items = []
for sha256 in hashes:
items.append({
"hash": sha256,
"image_path": "unknown",
"creation_datetime": "unknown",
})
headers = {"User-Agent": "VirusTotal", "Content-Type": "application/json"}
res = requests.post(url, headers=headers, json=items)
if res.status_code == 200:
report = res.json()
return report["data"]
return None
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some hashes')
parser.add_argument('FILE', help='File')
args = parser.parse_args()
with open(args.FILE, 'r') as infile:
data = infile.read().split()
hash_list = list(set([a.strip() for a in data]))
print("Hash,Found,Detection,Total AV,Link")
for l in chunks(hash_list, 25):
res = get_virustotal_report(l)
if res:
for r in res:
if r["found"]:
print("%s,Found,%i,%i,%s" % (
r['hash'],
r['positives'],
r['total'],
r['permalink']
))
else:
print("%s,Not found,,," % r['hash'])
else:
print("Query failed somehow!")