2015-01-10 18:19:23 +00:00
|
|
|
import argparse
|
|
|
|
import sys
|
2015-01-10 18:20:31 +00:00
|
|
|
import redis
|
2015-01-10 18:32:24 +00:00
|
|
|
import hashlib
|
2015-01-10 18:19:23 +00:00
|
|
|
|
|
|
|
argParser = argparse.ArgumentParser(description='Malware classifier')
|
|
|
|
argParser.add_argument('-f', action='append', help='Filename')
|
|
|
|
args = argParser.parse_args()
|
|
|
|
|
2015-01-10 18:20:31 +00:00
|
|
|
r = redis.StrictRedis(host='localhost', port=6379, db=0)
|
|
|
|
|
2015-01-10 18:19:23 +00:00
|
|
|
if args.f is not None:
|
2015-01-10 18:20:31 +00:00
|
|
|
md5 = args.f[0].split(".")[0]
|
|
|
|
r.sadd('processed', md5)
|
2015-01-10 18:25:07 +00:00
|
|
|
lnumber = 0
|
2015-01-10 18:30:18 +00:00
|
|
|
fields = None
|
2015-01-10 18:19:23 +00:00
|
|
|
for line in sys.stdin:
|
2015-01-10 18:25:07 +00:00
|
|
|
if lnumber == 0:
|
2015-01-10 18:30:18 +00:00
|
|
|
fields = line.rstrip().split(",")
|
|
|
|
for field in fields:
|
2015-01-10 18:25:07 +00:00
|
|
|
r.sadd('type', field)
|
2015-01-10 18:30:18 +00:00
|
|
|
else:
|
|
|
|
elements = line.rstrip().split(",")
|
|
|
|
i = 0
|
|
|
|
for element in elements:
|
|
|
|
try:
|
|
|
|
r.sadd('e:'+fields[i], element)
|
2016-01-23 11:13:54 +00:00
|
|
|
r.zincrby('t:'+fields[i], element)
|
2015-01-10 18:32:24 +00:00
|
|
|
#
|
|
|
|
ehash = hashlib.md5()
|
|
|
|
ehash.update(element.encode('utf-8'))
|
|
|
|
ehhex = ehash.hexdigest()
|
|
|
|
if element is not "":
|
|
|
|
r.sadd('v:'+ehhex, md5)
|
2015-01-10 18:30:18 +00:00
|
|
|
except IndexError:
|
|
|
|
print("Empty fields")
|
|
|
|
i = i+1
|
|
|
|
|
2015-01-10 18:25:07 +00:00
|
|
|
lnumber = lnumber + 1
|
2015-01-10 18:19:23 +00:00
|
|
|
else:
|
|
|
|
argParser.print_help()
|