summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xphp-malware-finder/utils/mass_whitelist.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/php-malware-finder/utils/mass_whitelist.py b/php-malware-finder/utils/mass_whitelist.py
index 3dd4769..82733fa 100755
--- a/php-malware-finder/utils/mass_whitelist.py
+++ b/php-malware-finder/utils/mass_whitelist.py
@@ -1,10 +1,10 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4import re
5import sys 4import sys
6import tarfile 5import tarfile
7from copy import copy 6from copy import copy
7from datetime import datetime
8from collections import OrderedDict 8from collections import OrderedDict
9from hashlib import sha1 9from hashlib import sha1
10from urllib2 import urlopen, HTTPError 10from urllib2 import urlopen, HTTPError
@@ -25,7 +25,12 @@ Options:
25Examples: 25Examples:
26 %(prog)s drupal https://ftp.drupal.org/files/projects/drupal-__version__.tar.gz 9 50 26 %(prog)s drupal https://ftp.drupal.org/files/projects/drupal-__version__.tar.gz 9 50
27 %(prog)s drupal https://ftp.drupal.org/files/projects/drupal-__version__.tar.gz 4-9 1-50 27 %(prog)s drupal https://ftp.drupal.org/files/projects/drupal-__version__.tar.gz 4-9 1-50
28
28 %(prog)s wordpress https://wordpress.org/wordpress-__version__.tar.gz 4 15 29 %(prog)s wordpress https://wordpress.org/wordpress-__version__.tar.gz 4 15
30
31 %(prog)s symphony https://github.com/symfony/symfony/archive/v__version__.tar.gz 3 9
32
33 %(prog)s phpmyadmin https://files.phpmyadmin.net/phpMyAdmin/__version__/phpMyAdmin-__version__-all-languages.tar.gz 4 9
29""" % {'prog': sys.argv[0]} 34""" % {'prog': sys.argv[0]}
30 35
31 36
@@ -110,19 +115,19 @@ for vmajor in range(Opts.MIN_MAJOR, Opts.MAX_MAJOR + 1):
110 rules = generate_whitelist(version) 115 rules = generate_whitelist(version)
111 if (rules is not None) and rules: 116 if (rules is not None) and rules:
112 whitelists[version] = rules 117 whitelists[version] = rules
113 118
114 has_mversion = False 119 has_mversion = False
115 first_mloop = True 120 first_mloop = True
116 for vminor in range(Opts.MIN_MINOR, Opts.MAX_MINOR + 1): 121 for vminor in range(Opts.MIN_MINOR, Opts.MAX_MINOR + 1):
117 # download without vpatch (but ignore if it doesn't exist) 122 # download without vpatch (but ignore if it doesn't exist)
118 version = "%d.%d" % (vmajor, vminor) 123 version = "%d.%d" % (vmajor, vminor)
119 rules = generate_whitelist(version) 124 rules = generate_whitelist(version)
120 if rules is not None: 125 if rules is not None:
121 has_mversion = True 126 has_mversion = True
122 if rules: 127 if rules:
123 whitelists[version] = rules 128 whitelists[version] = rules
124 if (rules is None) and (has_mversion or not first_mloop): 129 if (rules is None) and (has_mversion or not first_mloop):
125 break 130 break
126 first_mloop = False 131 first_mloop = False
127 132
128 has_pversion = False 133 has_pversion = False
@@ -136,7 +141,8 @@ for vmajor in range(Opts.MIN_MAJOR, Opts.MAX_MAJOR + 1):
136 whitelists[version] = rules 141 whitelists[version] = rules
137 # break loop if download failed and: 142 # break loop if download failed and:
138 # - a version has already been found during this loop 143 # - a version has already been found during this loop
139 # - this is the 2nd iteration (if a version wasn't found, it means download failed twice) 144 # - this is the 2nd iteration (if a version wasn't found,
145 # it means download failed twice)
140 if (rules is None) and (has_pversion or not first_ploop): 146 if (rules is None) and (has_pversion or not first_ploop):
141 break 147 break
142 first_ploop = False 148 first_ploop = False
@@ -172,10 +178,17 @@ for index, (version, rules) in enumerate(whitelists.items()):
172final_rule = """ 178final_rule = """
173import "hash" 179import "hash"
174 180
175rule %(name)s 181private rule %(name)s
176{ 182{
183 meta:
184 generated = "%(gendate)s"
185
177 condition: 186 condition:
178%(conditions)s 187%(conditions)s
179} 188}
180""" % {'name': Opts.CMS_NAME, 'conditions': '\n'.join(conditions)} 189""" % {
181print final_rule 190 'name': Opts.CMS_NAME.title(),
191 'gendate': datetime.now().isoformat(),
192 'conditions': '\n'.join(conditions)
193}
194print final_rule