Hanno Böck commited on 2017-01-09 18:08:20
Zeige 1 geänderte Dateien mit 35 Einfügungen und 26 Löschungen.
| ... | ... |
@@ -31,7 +31,13 @@ except ImportError: # python2 |
| 31 | 31 |
# this one supports encoding='...' |
| 32 | 32 |
from codecs import open |
| 33 | 33 |
|
| 34 |
-import os, glob, pprint, re, optparse, sys, gettext |
|
| 34 |
+import os |
|
| 35 |
+import glob |
|
| 36 |
+import pprint |
|
| 37 |
+import re |
|
| 38 |
+import optparse |
|
| 39 |
+import sys |
|
| 40 |
+import gettext |
|
| 35 | 41 |
from xml.sax.saxutils import escape |
| 36 | 42 |
|
| 37 | 43 |
gettext.textdomain('freewvs')
|
| ... | ... |
@@ -47,23 +54,25 @@ def versioncompare(safe_version, find_version): |
| 47 | 54 |
return False |
| 48 | 55 |
return (len(find_version) < len(safe_version)) |
| 49 | 56 |
|
| 50 |
-def vulnprint(appname, version, safeversion, vuln, vfilename, subdir, style = None): |
|
| 57 |
+ |
|
| 58 |
+def vulnprint(appname, version, safeversion, vuln, vfilename, subdir, |
|
| 59 |
+ style=None): |
|
| 51 | 60 |
appdir = '/'.join(os.path.abspath(vfilename).split('/')[:-1-subdir])
|
| 52 | 61 |
if not style: |
| 53 |
- print ("%(appname)s %(version)s (%(safeversion)s) %(vuln)s %(appdir)s" \
|
|
| 54 |
- % vars()) |
|
| 62 |
+ print("%(appname)s %(version)s (%(safeversion)s) %(vuln)s"
|
|
| 63 |
+ "%(appdir)s" % vars()) |
|
| 55 | 64 |
elif style == 'fancy': |
| 56 | 65 |
print(_("Directory: %(appdir)s") % vars())
|
| 57 | 66 |
if safeversion != "ok": |
| 58 | 67 |
if safeversion != "": |
| 59 |
- print (_("Vulnerable %(appname)s %(version)s found, please update to " \
|
|
| 60 |
- "%(safeversion)s or above.") % vars()) |
|
| 68 |
+ print(_("Vulnerable %(appname)s %(version)s found, please "
|
|
| 69 |
+ "update to %(safeversion)s or above.") % vars()) |
|
| 61 | 70 |
else: |
| 62 |
- print (_("Vulnerable %(appname)s %(version)s found, no fixed version available." \
|
|
| 63 |
- ) % vars()) |
|
| 71 |
+ print(_("Vulnerable %(appname)s %(version)s found, no fixed "
|
|
| 72 |
+ "version available.") % vars()) |
|
| 64 | 73 |
if vuln[:3] == "CVE": |
| 65 |
- print (_("http://cve.mitre.org/cgi-bin/cvename.cgi?name=%(vuln)s") \
|
|
| 66 |
- % vars()) |
|
| 74 |
+ print(_("http://cve.mitre.org/cgi-bin/cvename.cgi?name="
|
|
| 75 |
+ "%(vuln)s") % vars()) |
|
| 67 | 76 |
else: |
| 68 | 77 |
print(vuln) |
| 69 | 78 |
else: |
| ... | ... |
@@ -86,16 +95,17 @@ def vulnprint(appname, version, safeversion, vuln, vfilename, subdir, style = No |
| 86 | 95 |
pp = pprint.PrettyPrinter(indent=4) |
| 87 | 96 |
|
| 88 | 97 |
# Command-line options |
| 89 |
-parser = optparse.OptionParser(usage="usage: %prog [options] <path> [<path2> ...]") |
|
| 98 |
+parser = optparse.OptionParser(usage="usage: %prog [options] <path>" |
|
| 99 |
+ "[<path2> ...]") |
|
| 90 | 100 |
parser.add_option("-a", "--all", action="store_true", dest="ALL",
|
| 91 | 101 |
help="Show all webapps found, not just vulnerable") |
| 92 | 102 |
parser.add_option("-d", "--debug", action="store_true", dest="DEBUG",
|
| 93 |
- help="Show lots of debugging output, mainly useful"+ \ |
|
| 103 |
+ help="Show lots of debugging output, mainly useful" |
|
| 94 | 104 |
"for development") |
| 95 |
-parser.add_option("-f", "--fancy", action="store_const", dest="OUTPUT", const="fancy",
|
|
| 96 |
- help="Show more fancy output") |
|
| 97 |
-parser.add_option("-x", "--xml", action="store_const", dest="OUTPUT", const="xml",
|
|
| 98 |
- help="Output results as XML") |
|
| 105 |
+parser.add_option("-f", "--fancy", action="store_const", dest="OUTPUT",
|
|
| 106 |
+ const="fancy", help="Show more fancy output") |
|
| 107 |
+parser.add_option("-x", "--xml", action="store_const", dest="OUTPUT",
|
|
| 108 |
+ const="xml", help="Output results as XML") |
|
| 99 | 109 |
opts, args = parser.parse_args() |
| 100 | 110 |
|
| 101 | 111 |
# Parse vulnerability database |
| ... | ... |
@@ -105,7 +115,7 @@ try: |
| 105 | 115 |
config.read(glob.glob('/usr/local/share/freewvs/*.freewvs'))
|
| 106 | 116 |
config.read(glob.glob(os.path.dirname(sys.argv[0])+'/freewvsdb/*.freewvs')) |
| 107 | 117 |
except configparser.MissingSectionHeaderError as err: |
| 108 |
- print("Error parsing config files: %s" % err);
|
|
| 118 |
+ print("Error parsing config files: %s" % err)
|
|
| 109 | 119 |
|
| 110 | 120 |
vdb = [] |
| 111 | 121 |
for sect in config.sections(): |
| ... | ... |
@@ -185,35 +195,35 @@ for fdir in args: |
| 185 | 195 |
int(item['add_minor'])) |
| 186 | 196 |
findversion = '.'.join(findversion) |
| 187 | 197 |
|
| 188 |
- if not (versioncompare(item['safe'].split('.'), \
|
|
| 198 |
+ if not (versioncompare(item['safe'].split('.'),
|
|
| 189 | 199 |
findversion.split('.'))) or \
|
| 190 | 200 |
item['old_safe'].count(findversion) > 0: |
| 191 | 201 |
if opts.ALL: |
| 192 | 202 |
if opts.DEBUG: |
| 193 | 203 |
print("File "+mfile)
|
| 194 |
- vulnprint(item['name'], findversion, \ |
|
| 195 |
- "ok", "", mfile, item['subdir'], \ |
|
| 204 |
+ vulnprint(item['name'], findversion, |
|
| 205 |
+ "ok", "", mfile, item['subdir'], |
|
| 196 | 206 |
opts.OUTPUT) |
| 197 | 207 |
else: |
| 198 | 208 |
if opts.DEBUG: |
| 199 | 209 |
print("File " + mfile)
|
| 200 | 210 |
safev = "9999" |
| 201 | 211 |
for ver in item['old_safe']: |
| 202 |
- if (versioncompare(ver.split('.'), \
|
|
| 203 |
- findversion.split('.') ) and \
|
|
| 204 |
- not versioncompare(ver.split('.'), \
|
|
| 212 |
+ if(versioncompare(ver.split('.'),
|
|
| 213 |
+ findversion.split('.')) and
|
|
| 214 |
+ not versioncompare(ver.split('.'),
|
|
| 205 | 215 |
safev.split('.'))):
|
| 206 | 216 |
safev = ver |
| 207 | 217 |
if safev == "9999": |
| 208 | 218 |
safev = item['safe'] |
| 209 | 219 |
|
| 210 |
- vulnprint (item['name'], findversion, \ |
|
| 211 |
- safev, item['vuln'], \ |
|
| 220 |
+ vulnprint(item['name'], findversion, |
|
| 221 |
+ safev, item['vuln'], |
|
| 212 | 222 |
mfile, item['subdir'], opts.OUTPUT) |
| 213 | 223 |
|
| 214 | 224 |
else: |
| 215 | 225 |
if opts.DEBUG: |
| 216 |
- print ("regexp failed for " + \
|
|
| 226 |
+ print("regexp failed for " +
|
|
| 217 | 227 |
item['name'] + " on " + mfile) |
| 218 | 228 |
|
| 219 | 229 |
if opts.OUTPUT == 'xml': |
| 220 | 230 |