MalwareClassifier/bin/import.py
Alexandre Dulaunoy 56a42333fa Workshop - 5th step added
Mapping between malware MD5 and element MD5 added in Redis
2015-01-10 19:32:24 +01:00

40 lines
1.2 KiB
Python

import argparse
import sys
import redis
import hashlib
argParser = argparse.ArgumentParser(description='Malware classifier')
argParser.add_argument('-f', action='append', help='Filename')
args = argParser.parse_args()
r = redis.StrictRedis(host='localhost', port=6379, db=0)
if args.f is not None:
md5 = args.f[0].split(".")[0]
r.sadd('processed', md5)
lnumber = 0
fields = None
for line in sys.stdin:
if lnumber == 0:
fields = line.rstrip().split(",")
for field in fields:
r.sadd('type', field)
else:
elements = line.rstrip().split(",")
i = 0
for element in elements:
try:
r.sadd('e:'+fields[i], element)
#
ehash = hashlib.md5()
ehash.update(element.encode('utf-8'))
ehhex = ehash.hexdigest()
if element is not "":
r.sadd('v:'+ehhex, md5)
except IndexError:
print("Empty fields")
i = i+1
lnumber = lnumber + 1
else:
argParser.print_help()