Browse code

fix lot's of pylint issues (not all of them though)

Hanno Böck authored on13/01/2008 13:07:39
Showing1 changed files
... ...
@@ -16,27 +16,29 @@
16 16
 #
17 17
 # This program is distributed in the hope that it will be useful,
18 18
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
20 20
 # GNU General Public License for more details.
21 21
 #
22 22
 # You should have received a copy of the GNU General Public License
23
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
+# along with this program.    If not, see <http://www.gnu.org/licenses/>.
24 24
 
25 25
 import ConfigParser, os, glob, pprint, re, optparse, sys
26 26
 
27 27
 
28
-def versioncompare(safe_version,find_version):
29
-  if safe_version==[""]: return True
30
-  for i in range(min(len(find_version),len(safe_version))):
31
-    if int(find_version[i])<int(safe_version[i]):
32
-      return True
33
-    if int(find_version[i])>int(safe_version[i]):
34
-      return False
35
-  return (len(find_version)<len(safe_version))
28
+def versioncompare(safe_version, find_version):
29
+    if safe_version == [""]:
30
+        return True
31
+    for i in range(min(len(find_version), len(safe_version))):
32
+        if int(find_version[i])<int(safe_version[i]):
33
+            return True
34
+        if int(find_version[i])>int(safe_version[i]):
35
+            return False
36
+    return (len(find_version)<len(safe_version))
36 37
 
37
-def vulnprint(appname,version,safeversion,vuln,filename,subdir):
38
-  appdir='/'.join(os.path.abspath(filename).split('/')[:-1-subdir])
39
-  print "%(appname)s %(version)s (%(safeversion)s) %(vuln)s %(appdir)s" % vars()
38
+def vulnprint(appname, version, safeversion, vuln, vfilename, subdir):
39
+    appdir = '/'.join(os.path.abspath(vfilename).split('/')[:-1-subdir])
40
+    print "%(appname)s %(version)s (%(safeversion)s) %(vuln)s %(appdir)s" \
41
+          % vars()
40 42
 
41 43
 pp = pprint.PrettyPrinter(indent=4)
42 44
 
... ...
@@ -45,7 +47,8 @@ parser = optparse.OptionParser()
45 47
 parser.add_option("-a", "--all", action="store_true", dest="ALL",
46 48
                   help="Show all webapps found, not just vulnerable")
47 49
 parser.add_option("-d", "--debug", action="store_true", dest="DEBUG",
48
-                  help="Show lots of debugging output, mainly useful for development")
50
+                  help="Show lots of debugging output, mainly useful"+ \
51
+                  "for development")
49 52
 opts, args = parser.parse_args()
50 53
 
51 54
 # Parse vulnerability database
... ...
@@ -56,72 +59,92 @@ config.read(glob.glob(os.path.dirname(sys.argv[0])+'/freewvsdb/*.freewvs'))
56 59
 
57 60
 vdb = []
58 61
 for sect in config.sections():
59
-  item={}
60
-
61
-  # base options
62
-  item['name']=sect
63
-  item['safe']=config.get(sect,'safe')
64
-  item['file']=config.get(sect,'file')
65
-  item['vuln']=config.get(sect,'vuln')
66
-  item['subdir']=int(config.get(sect,'subdir'))
67
-
68
-  # match magic
69
-  item['variable']=[]
70
-  for var in config.get(sect,'variable').split(","):
71
-        item['variable'].append(re.compile(re.escape(var)+r"[^0-9.]*[.]*([0-9.]*[0-9])[^0-9.]"))
72
-
73
-  # optional options
74
-  if config.has_option(sect,'extra_match'): item['extra_match']=config.get(sect,'extra_match')
75
-  else: item['extra_match']=False
76
-  if config.has_option(sect,'add_minor'): item['add_minor']=config.get(sect,'add_minor')
77
-  else: item['add_minor']=False
78
-  if config.has_option(sect,'old_safe'): item['old_safe']=config.get(sect,'old_safe').split(",")
79
-  else: item['old_safe']=[]
80
-
81
-  vdb.append(item)
82
-if opts.DEBUG: pp.pprint(vdb)
62
+    item = {}
63
+
64
+    # base options
65
+    item['name'] = sect
66
+    item['safe'] = config.get(sect, 'safe')
67
+    item['file'] = config.get(sect, 'file')
68
+    item['vuln'] = config.get(sect, 'vuln')
69
+    item['subdir'] = int(config.get(sect, 'subdir'))
70
+
71
+    # match magic
72
+    item['variable'] = []
73
+    for var in config.get(sect,'variable').split(","):
74
+        item['variable'].append(re.compile(re.escape(var)+
75
+                                r"[^0-9.]*[.]*([0-9.]*[0-9])[^0-9.]"))
76
+
77
+    # optional options
78
+    if config.has_option(sect,'extra_match'):
79
+        item['extra_match'] = config.get(sect,'extra_match')
80
+    else:
81
+        item['extra_match'] = False
82
+    if config.has_option(sect,'add_minor'):
83
+        item['add_minor'] = config.get(sect,'add_minor')
84
+    else:
85
+        item['add_minor'] = False
86
+    if config.has_option(sect,'old_safe'):
87
+        item['old_safe'] = config.get(sect,'old_safe').split(",")
88
+    else:
89
+        item['old_safe'] = []
90
+
91
+    vdb.append(item)
92
+if opts.DEBUG:
93
+    pp.pprint(vdb)
83 94
 
84 95
 
85 96
 # start the search
86 97
 
87
-for dir in args:
88
-  for root,NULL,files in os.walk(dir):
89
-    for filename in files:
90
-      for item in vdb:
91
-        if filename == item['file']:
92
-          mfile=os.path.join(root,filename)
93
-          file=open(mfile)
94
-          filestr=file.read()
95
-          file.close()
96
-
97
-          if item['extra_match']: ematch=(filestr.find(item['extra_match'])!=-1)
98
-          else: ematch=True
99
-
100
-          findversion=[]
101
-          for var in item['variable']:
102
-            var = var.search(filestr)
103
-            if not var:
104
-              findversion=False
105
-              break
106
-            else:
107
-              findversion.append(var.group(1))
108
-
109
-          if findversion and ematch:
110
-            findversion='.'.join(findversion)
111
-
112
-            # Very ugly phpbb workaround
113
-            if item['add_minor']:
114
-              findversion=findversion.split('.')
115
-              findversion[-1]=str(int(findversion[-1])+int(item['add_minor']))
116
-              findversion='.'.join(findversion)
117
-
118
-            if not (versioncompare(item['safe'].split('.'),findversion.split('.'))) or item['old_safe'].count(findversion)>0:
119
-              if opts.ALL:
120
-                if opts.DEBUG: print "File "+mfile
121
-                vulnprint(item['name'],findversion,"ok","",mfile,item['subdir'])
122
-            else:
123
-              if opts.DEBUG: print "File "+mfile
124
-              vulnprint (item['name'],findversion,item['safe'],item['vuln'],mfile,item['subdir'])
125
-
126
-          else:
127
-            if opts.DEBUG: print "regexp failed for "+item['name']+" on "+mfile
98
+for fdir in args:
99
+    for root, NULL, files in os.walk(fdir):
100
+        for filename in files:
101
+            for item in vdb:
102
+                if filename == item['file']:
103
+                    mfile = os.path.join(root, filename)
104
+                    file = open(mfile)
105
+                    filestr = file.read()
106
+                    file.close()
107
+
108
+                    if item['extra_match']:
109
+                        ematch = (filestr.find(item['extra_match']) != -1)
110
+                    else:
111
+                        ematch = True
112
+
113
+                    findversion = []
114
+                    for var in item['variable']:
115
+                        var = var.search(filestr)
116
+                        if not var:
117
+                            findversion = False
118
+                            break
119
+                        else:
120
+                            findversion.append(var.group(1))
121
+
122
+                    if findversion and ematch:
123
+                        findversion = '.'.join(findversion)
124
+
125
+                        # Very ugly phpbb workaround
126
+                        if item['add_minor']:
127
+                            findversion = findversion.split('.')
128
+                            findversion[-1] = str(int(findversion[-1])+
129
+                                            int(item['add_minor']))
130
+                            findversion = '.'.join(findversion)
131
+
132
+                        if not (versioncompare(item['safe'].split('.'), \
133
+                                findversion.split('.'))) or \
134
+                                item['old_safe'].count(findversion)>0:
135
+                            if opts.ALL:
136
+                                if opts.DEBUG:
137
+                                    print "File "+mfile
138
+                                vulnprint(item['name'], findversion, \
139
+                                          "ok", "", mfile, item['subdir'])
140
+                        else:
141
+                            if opts.DEBUG:
142
+                                print "File "+mfile
143
+                            vulnprint (item['name'], findversion, \
144
+                                       item['safe'], item['vuln'], \
145
+                                       mfile, item['subdir'])
146
+
147
+                    else:
148
+                        if opts.DEBUG:
149
+                            print "regexp failed for " + \
150
+                                  item['name'] + " on " + mfile