df4d48780460560c0cbab15c232ac327b5cfdc30
Hanno Böck Enforce python 3, remove py...

Hanno Böck authored 4 years ago

1) #!/usr/bin/python3 -O
Hanno Böck initial commit

Hanno Böck authored 16 years ago

2) 
3) # freewvs 0.1 - the free web vulnerability scanner
4) #
Hanno Böck convert all http URLs to https

Hanno Böck authored 6 years ago

5) # https://source.schokokeks.org/freewvs/
Hanno Böck initial commit

Hanno Böck authored 16 years ago

6) #
Hanno Böck convert all http URLs to https

Hanno Böck authored 6 years ago

7) # Written 2007-2012 by schokokeks.org Hosting, https://schokokeks.org
Hanno Böck initial commit

Hanno Böck authored 16 years ago

8) #
9) # Contributions by
Hanno Böck convert all http URLs to https

Hanno Böck authored 6 years ago

10) # Hanno Boeck, https://hboeck.de/
11) # Fabian Fingerle, https://fabian-fingerle.de/
12) # Bernd Wurst, https://bwurst.org/
Hanno Böck initial commit

Hanno Böck authored 16 years ago

13) #
Hanno Böck License change to cc0

Hanno Böck authored 11 years ago

14) # To the extent possible under law, the author(s) have dedicated all copyright
15) # and related and neighboring rights to this software to the public domain
16) # worldwide. This software is distributed without any warranty.
Hanno Böck initial commit

Hanno Böck authored 16 years ago

17) #
Hanno Böck License change to cc0

Hanno Böck authored 11 years ago

18) # You should have received a copy of the CC0 Public Domain Dedication along
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

19) # with this software. If not, see
Hanno Böck convert all http URLs to https

Hanno Böck authored 6 years ago

20) # https://creativecommons.org/publicdomain/zero/1.0/
Hanno Böck License change to cc0

Hanno Böck authored 11 years ago

21) # Nevertheless, in case you use a significant part of this code, we ask (but
22) # not require, see the license) that you keep the authors' names in place and
23) # return your changes to the public. We would be especially happy if you tell
24) # us what you're going to do with this code.
Hanno Böck initial commit

Hanno Böck authored 16 years ago

25) 
Hanno Böck Enforce python 3, remove py...

Hanno Böck authored 4 years ago

26) import configparser
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

27) 
28) import os
29) import glob
30) import pprint
31) import re
32) import optparse
33) import sys
34) import gettext
Bernd Wurst Add XML string escaping

Bernd Wurst authored 15 years ago

35) from xml.sax.saxutils import escape
Hanno Böck initial commit

Hanno Böck authored 16 years ago

36) 
Hanno Böck add fancy output

Hanno Böck authored 16 years ago

37) gettext.textdomain('freewvs')
38) _ = gettext.gettext
Hanno Böck initial commit

Hanno Böck authored 16 years ago

39) 
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

40) 
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

41) def versioncompare(safe_version, find_version):
42)     if safe_version == [""]:
43)         return True
44)     for i in range(min(len(find_version), len(safe_version))):
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

45)         if int(find_version[i]) < int(safe_version[i]):
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

46)             return True
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

47)         if int(find_version[i]) > int(safe_version[i]):
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

48)             return False
Hanno implement some recommendati...

Hanno authored 5 years ago

49)     return len(find_version) < len(safe_version)
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

50) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

51) 
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

52) def vulnprint(appname, version, safeversion, vuln, vfilename, subdir,
53)               style=None):
Hanno Böck pycodestyle fixes

Hanno Böck authored 6 years ago

54)     appdir = '/'.join(os.path.abspath(vfilename).split('/')[:-1 - subdir])
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

55)     if not style:
Hanno Böck missing space

Hanno Böck authored 7 years ago

56)         print("%(appname)s %(version)s (%(safeversion)s) %(vuln)s "
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

57)               "%(appdir)s" % vars())
58)     elif style == 'fancy':
59)         print(_("Directory: %(appdir)s") % vars())
60)         if safeversion != "ok":
61)             if safeversion != "":
62)                 print(_("Vulnerable %(appname)s %(version)s found, please "
63)                         "update to %(safeversion)s or above.") % vars())
Hanno Böck add support for unfixed apps

Hanno Böck authored 15 years ago

64)             else:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

65)                 print(_("Vulnerable %(appname)s %(version)s found, no fixed "
66)                         "version available.") % vars())
Hanno Böck some i18n fixes

Hanno Böck authored 15 years ago

67)             if vuln[:3] == "CVE":
Hanno Böck convert all http URLs to https

Hanno Böck authored 6 years ago

68)                 print(_("https://cve.mitre.org/cgi-bin/cvename.cgi?name="
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

69)                         "%(vuln)s") % vars())
Hanno Böck some i18n fixes

Hanno Böck authored 15 years ago

70)             else:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

71)                 print(vuln)
Hanno Böck add fancy output

Hanno Böck authored 16 years ago

72)         else:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

73)             print(_("%(appname)s %(version)s found.") % vars())
74)         print("")
75)     elif style == 'xml':
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

76)         state = 'vulnerable'
77)         if safeversion == 'ok':
78)             state = 'ok'
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

79)         print('  <app state="%s">' % state)
80)         print('    <appname>%s</appname>' % escape(appname))
81)         print('    <version>%s</version>' % escape(version))
82)         print('    <directory>%s</directory>' % escape(appdir))
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

83)         if state == 'vulnerable':
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

84)             print('    <safeversion>%s</safeversion>' % escape(safeversion))
85)             print('    <vulninfo>%s</vulninfo>' % escape(vuln))
86)         print('  </app>')
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

87) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

88) 
89) pp = pprint.PrettyPrinter(indent=4)
90) 
91) # Command-line options
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

92) parser = optparse.OptionParser(usage="usage: %prog [options] <path>"
93)                                "[<path2> ...]")
Hanno Böck initial commit

Hanno Böck authored 16 years ago

94) parser.add_option("-a", "--all", action="store_true", dest="ALL",
95)                   help="Show all webapps found, not just vulnerable")
96) parser.add_option("-d", "--debug", action="store_true", dest="DEBUG",
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

97)                   help="Show lots of debugging output, mainly useful"
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

98)                   "for development")
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

99) parser.add_option("-f", "--fancy", action="store_const", dest="OUTPUT",
100)                   const="fancy", help="Show more fancy output")
101) parser.add_option("-x", "--xml", action="store_const", dest="OUTPUT",
102)                   const="xml", help="Output results as XML")
Hanno Böck Add possibility to scan for...

Hanno Böck authored 4 years ago

103) parser.add_option("-3", "--thirdparty", action="store_true", dest="THIRDPARTY",
104)                   help="Scan for third-party components like jquery")
Hanno Böck initial commit

Hanno Böck authored 16 years ago

105) opts, args = parser.parse_args()
106) 
107) # Parse vulnerability database
Hanno Böck make code compatible with p...

Hanno Böck authored 10 years ago

108) config = configparser.ConfigParser()
Hanno Böck catch error message on pars...

Hanno Böck authored 7 years ago

109) try:
110)     config.read(glob.glob('/usr/share/freewvs/*.freewvs'))
111)     config.read(glob.glob('/usr/local/share/freewvs/*.freewvs'))
Hanno Böck codingstyle: avoid long lin...

Hanno Böck authored 4 years ago

112)     config.read(glob.glob(os.path.dirname(sys.argv[0])
113)                           + '/freewvsdb/*.freewvs'))
Hanno Böck catch error message on pars...

Hanno Böck authored 7 years ago

114) except configparser.MissingSectionHeaderError as err:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

115)     print("Error parsing config files: %s" % err)
Hanno Böck initial commit

Hanno Böck authored 16 years ago

116) 
117) vdb = []
118) for sect in config.sections():
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

119)     item = {}
120) 
Hanno Böck codingstyle: avoid long lin...

Hanno Böck authored 4 years ago

121)     if (config.getboolean(sect, 'thirdparty', fallback=False)
122)        and not opts.THIRDPARTY):
Hanno Böck Add possibility to scan for...

Hanno Böck authored 4 years ago

123)         continue
124) 
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

125)     # base options
126)     item['name'] = sect
127)     item['safe'] = config.get(sect, 'safe')
128)     item['file'] = config.get(sect, 'file')
129)     item['vuln'] = config.get(sect, 'vuln')
130)     item['subdir'] = int(config.get(sect, 'subdir'))
131) 
132)     # match magic
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

133)     item['variable'] = re.compile(re.escape(config.get(sect, 'variable'))
134)                                 + r"[^0-9\n\r]*[.]*([0-9.]*[0-9])[^0-9.]")
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

135) 
136)     # optional options
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

137)     if config.has_option(sect, 'extra_match'):
138)         item['extra_match'] = config.get(sect, 'extra_match')
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

139)     else:
140)         item['extra_match'] = False
Hanno Böck a bit better detection for...

Hanno Böck authored 7 years ago

141)     if config.has_option(sect, 'extra_nomatch'):
142)         item['extra_nomatch'] = config.get(sect, 'extra_nomatch')
143)     else:
144)         item['extra_nomatch'] = False
Hanno Böck add path_match feature, all...

Hanno Böck authored 4 years ago

145)     if config.has_option(sect, 'path_match'):
146)         item['path_match'] = config.get(sect, 'path_match')
147)     else:
148)         item['path_match'] = False
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

149)     if config.has_option(sect, 'add_minor'):
150)         item['add_minor'] = config.get(sect, 'add_minor')
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

151)     else:
152)         item['add_minor'] = False
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

153)     if config.has_option(sect, 'old_safe'):
154)         item['old_safe'] = config.get(sect, 'old_safe').split(",")
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

155)     else:
156)         item['old_safe'] = []
157) 
158)     vdb.append(item)
159) if opts.DEBUG:
160)     pp.pprint(vdb)
Hanno Böck initial commit

Hanno Böck authored 16 years ago

161) 
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

162) if opts.OUTPUT == 'xml':
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

163)     print('<?xml version="1.0" ?>')
164)     print('<freewvs>')
Hanno Böck initial commit

Hanno Böck authored 16 years ago

165) 
166) # start the search
167) 
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

168) for fdir in args:
169)     for root, NULL, files in os.walk(fdir):
170)         for filename in files:
171)             for item in vdb:
172)                 if filename == item['file']:
173)                     mfile = os.path.join(root, filename)
Bernd Wurst error handling when opening...

Bernd Wurst authored 11 years ago

174)                     try:
Hanno Böck Don't stop on decoding errors

Hanno Böck authored 4 years ago

175)                         file = open(mfile, errors='replace')
Hanno Böck pycodestyle fixes

Hanno Böck authored 6 years ago

176)                     except Exception:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

177)                         continue
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

178)                     filestr = file.read()
179)                     file.close()
180) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

181)                     if ((item['extra_match']
182)                        and item['extra_match'] not in filestr)
183)                        or (item['extra_nomatch']
184)                        and item['extra_nomatch'] not in filestr)
185)                        or (item['path_match']
186)                        and not root.endswith(item['path_match']))):
Hanno Böck add path_match feature, all...

Hanno Böck authored 4 years ago

187)                         continue
188) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

189)                     findversion = item['variable'].search(filestr)
190)                     if not findversion:
191)                         continue
192)                     findversion=findversion.group(1)
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

193) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

194)                     # Very ugly phpbb workaround
195)                     if item['add_minor']:
196)                         findversion = findversion.split('.')
197)                         findversion[-1] = str(int(findversion[-1])
198)                                               + int(item['add_minor']))
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

199)                         findversion = '.'.join(findversion)
200) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

201)                     if not (versioncompare(item['safe'].split('.'),
202)                             findversion.split('.'))) or \
203)                             item['old_safe'].count(findversion) > 0:
204)                         if opts.ALL:
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

205)                             if opts.DEBUG:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

206)                                 print("File " + mfile)
207)                             vulnprint(item['name'], findversion,
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

208)                                       "ok", "", mfile, item['subdir'],
209)                                       opts.OUTPUT)
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

210)                     else:
211)                         if opts.DEBUG:
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

212)                             print("File " + mfile)
213)                         safev = "9999"
214)                         for ver in item['old_safe']:
215)                             if(versioncompare(ver.split('.'),
216)                                findversion.split('.'))
217)                                and not versioncompare(ver.split('.'),
218)                                safev.split('.'))):
219)                                 safev = ver
220)                         if safev == "9999":
221)                             safev = item['safe']
222) 
223)                         vulnprint(item['name'], findversion,
224)                                   safev, item['vuln'],
225)                                   mfile, item['subdir'], opts.OUTPUT)
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

226) 
227) if opts.OUTPUT == 'xml':