summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatToufoutu2016-07-09 19:50:59 +0200
committerMatToufoutu2016-07-09 19:50:59 +0200
commitb7b53ab7f517fd1f7d86cbaf7a1c7005243bef1a (patch)
tree4e195f9342587468fc768adf07e0882468b25aee
parenteb77d3ee77545e6120340b72ef61fa460a2e552c (diff)
attempt at fixing whitelist generation
-rwxr-xr-x[-rw-r--r--]php-malware-finder/generate_whitelist.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/php-malware-finder/generate_whitelist.py b/php-malware-finder/generate_whitelist.py
index 04bcc91..a8ed8f8 100644..100755
--- a/php-malware-finder/generate_whitelist.py
+++ b/php-malware-finder/generate_whitelist.py
@@ -11,6 +11,11 @@ except ImportError:
11 print('Please install python-yara') 11 print('Please install python-yara')
12 sys.exit(1) 12 sys.exit(1)
13 13
14print("/!\\ THIS SCRIPT IS BROKEN AND SHOULD NOT BE USED /!\\")
15print("IF YOU WANT ANYWAY, EDIT IT TO REMOVE THIS WARNING")
16sys.exit(0)
17
18
14if len(sys.argv) != 3: 19if len(sys.argv) != 3:
15 print('Usage: %s name_of_the_rule_and_version folder_to_scan' % sys.argv[0]) 20 print('Usage: %s name_of_the_rule_and_version folder_to_scan' % sys.argv[0])
16 sys.exit(1) 21 sys.exit(1)
@@ -29,11 +34,13 @@ for cpt, (root, dirnames, filenames) in enumerate(os.walk(sys.argv[2])):
29 if os.stat(fname).st_size: 34 if os.stat(fname).st_size:
30 matches = rules.match(os.path.join(root, filename), fast=True) 35 matches = rules.match(os.path.join(root, filename), fast=True)
31 if matches: 36 if matches:
32 matches = matches.pop() # only one match, since we're scaning files 37 hasher = hashlib.sha1()
33 output_list.append('hash.sha1(0, filename) == %s or // %s' % (hashlib.sha1(fname.encode('utf-8')).hexdigest(), fname)) 38 with open(fname, 'rb') as ifile:
39 hasher.update(ifile.read())
40 output_list.append('hash.sha1(0, filesize) == "%s" or // %s' % (hasher.hexdigest(), fname))
34 41
35 42
36output_rule = 'private rule %s\n{\n\tcondition:\n\t\t/* %s */\n\t\t' % (sys.argv[1].split(' ')[0], sys.argv[1]) 43output_rule = 'import "hash"\n\nprivate rule %s\n{\n\tcondition:\n\t\t/* %s */\n\t\t' % (sys.argv[1].split(' ')[0], sys.argv[1])
37output_list.append(output_list.pop().replace(' or ', ' ')) 44output_list.append(output_list.pop().replace(' or ', ' '))
38output_rule += '\n\t\t'.join(output_list) 45output_rule += '\n\t\t'.join(output_list)
39output_rule += '\n}' 46output_rule += '\n}'