diff options
| -rwxr-xr-x[-rw-r--r--] | php-malware-finder/generate_whitelist.py | 13 |
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 | ||
| 14 | print("/!\\ THIS SCRIPT IS BROKEN AND SHOULD NOT BE USED /!\\") | ||
| 15 | print("IF YOU WANT ANYWAY, EDIT IT TO REMOVE THIS WARNING") | ||
| 16 | sys.exit(0) | ||
| 17 | |||
| 18 | |||
| 14 | if len(sys.argv) != 3: | 19 | if 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 | ||
| 36 | output_rule = 'private rule %s\n{\n\tcondition:\n\t\t/* %s */\n\t\t' % (sys.argv[1].split(' ')[0], sys.argv[1]) | 43 | output_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]) |
| 37 | output_list.append(output_list.pop().replace(' or ', ' ')) | 44 | output_list.append(output_list.pop().replace(' or ', ' ')) |
| 38 | output_rule += '\n\t\t'.join(output_list) | 45 | output_rule += '\n\t\t'.join(output_list) |
| 39 | output_rule += '\n}' | 46 | output_rule += '\n}' |
