diff options
| author | Mathieu Deous | 2016-07-28 17:53:15 +0200 |
|---|---|---|
| committer | Mathieu Deous | 2016-07-28 17:56:19 +0200 |
| commit | 15358c9055df9e87fc587065a8876ba2088c425d (patch) | |
| tree | c962f82299730dbef4e4394718a27428035cc7c5 | |
| parent | 5f062f8a589fbe3b7e6f88e24e6a19b48f64b064 (diff) | |
add generation date to metadata in generated whitelists
| -rwxr-xr-x | php-malware-finder/utils/mass_whitelist.py | 29 |
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 | ||
| 4 | import re | ||
| 5 | import sys | 4 | import sys |
| 6 | import tarfile | 5 | import tarfile |
| 7 | from copy import copy | 6 | from copy import copy |
| 7 | from datetime import datetime | ||
| 8 | from collections import OrderedDict | 8 | from collections import OrderedDict |
| 9 | from hashlib import sha1 | 9 | from hashlib import sha1 |
| 10 | from urllib2 import urlopen, HTTPError | 10 | from urllib2 import urlopen, HTTPError |
| @@ -25,7 +25,12 @@ Options: | |||
| 25 | Examples: | 25 | Examples: |
| 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()): | |||
| 172 | final_rule = """ | 178 | final_rule = """ |
| 173 | import "hash" | 179 | import "hash" |
| 174 | 180 | ||
| 175 | rule %(name)s | 181 | private 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 | """ % { |
| 181 | print final_rule | 190 | 'name': Opts.CMS_NAME.title(), |
| 191 | 'gendate': datetime.now().isoformat(), | ||
| 192 | 'conditions': '\n'.join(conditions) | ||
| 193 | } | ||
| 194 | print final_rule | ||
