59359902bcf1f261329f89e340f0d9b40e67c8db
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 remove year so we don't hav...

Hanno Böck authored 4 years ago

7) # Written 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 re
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

31) import argparse
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

32) import sys
Bernd Wurst Add XML string escaping

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

36) def versioncompare(safe_version, find_version):
Hanno Böck fix detection with no safe...

Hanno Böck authored 4 years ago

37)     if safe_version == "":
38)         return True
Hanno Böck simplify versioncompare logic

Hanno Böck authored 4 years ago

39)     safe_version_tup = [int(x) for x in safe_version.split(".")]
40)     find_version_tup = [int(x) for x in find_version.split(".")]
41)     return find_version_tup < safe_version_tup
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

42) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 7 years ago

44) def vulnprint(appname, version, safeversion, vuln, vfilename, subdir,
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

45)               xml):
Hanno Böck pycodestyle fixes

Hanno Böck authored 6 years ago

46)     appdir = '/'.join(os.path.abspath(vfilename).split('/')[:-1 - subdir])
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

47)     if not xml:
Hanno Böck missing space

Hanno Böck authored 7 years ago

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

Hanno Böck authored 7 years ago

49)               "%(appdir)s" % vars())
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

50)     else:
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

51)         state = 'vulnerable'
52)         if safeversion == 'ok':
53)             state = 'ok'
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

54)         print('  <app state="%s">' % state)
55)         print('    <appname>%s</appname>' % escape(appname))
56)         print('    <version>%s</version>' % escape(version))
57)         print('    <directory>%s</directory>' % escape(appdir))
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 7 years ago

59)             print('    <safeversion>%s</safeversion>' % escape(safeversion))
60)             print('    <vulninfo>%s</vulninfo>' % escape(vuln))
61)         print('  </app>')
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

62) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

63) 
64) # Command-line options
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

65) parser = argparse.ArgumentParser()
66) parser.add_argument("dirs", nargs="*",
67)                     help="Directories to scan")
68) parser.add_argument("-a", "--all", action="store_true",
69)                     help="Show all webapps found, not just vulnerable")
70) parser.add_argument("-x", "--xml", action="store_true",
71)                     help="Output results as XML")
72) parser.add_argument("-3", "--thirdparty", action="store_true",
73)                     help="Scan for third-party components like jquery")
74) opts = parser.parse_args()
Hanno Böck initial commit

Hanno Böck authored 16 years ago

75) 
76) # Parse vulnerability database
Hanno Böck make code compatible with p...

Hanno Böck authored 10 years ago

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

Hanno Böck authored 7 years ago

78) try:
79)     config.read(glob.glob('/usr/share/freewvs/*.freewvs'))
80)     config.read(glob.glob('/usr/local/share/freewvs/*.freewvs'))
Hanno Böck codingstyle: avoid long lin...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

85) 
86) vdb = []
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

87) scanfiles = set()
Hanno Böck initial commit

Hanno Böck authored 16 years ago

88) for sect in config.sections():
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

89)     item = {}
90) 
Hanno Böck codingstyle: avoid long lin...

Hanno Böck authored 4 years ago

91)     if (config.getboolean(sect, 'thirdparty', fallback=False)
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

92)        and not opts.thirdparty):
Hanno Böck Add possibility to scan for...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 16 years ago

95)     # base options
96)     item['name'] = sect
97)     item['safe'] = config.get(sect, 'safe')
98)     item['file'] = config.get(sect, 'file')
99)     item['vuln'] = config.get(sect, 'vuln')
100)     item['subdir'] = int(config.get(sect, 'subdir'))
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

101)     scanfiles.add(item['file'])
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

102) 
103)     # match magic
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

104)     item['variable'] = re.compile(re.escape(config.get(sect, 'variable'))
Hanno Böck codingstyle

Hanno Böck authored 4 years ago

105)                                   + 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

106) 
107)     # optional options
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 7 years ago

112)     if config.has_option(sect, 'extra_nomatch'):
113)         item['extra_nomatch'] = config.get(sect, 'extra_nomatch')
114)     else:
115)         item['extra_nomatch'] = False
Hanno Böck add path_match feature, all...

Hanno Böck authored 4 years ago

116)     if config.has_option(sect, 'path_match'):
117)         item['path_match'] = config.get(sect, 'path_match')
118)     else:
119)         item['path_match'] = False
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 7 years ago

124)     if config.has_option(sect, 'old_safe'):
125)         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

126)     else:
127)         item['old_safe'] = []
128) 
129)     vdb.append(item)
Hanno Böck initial commit

Hanno Böck authored 16 years ago

130) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

131) if opts.xml:
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

134) 
135) # start the search
136) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

137) for fdir in opts.dirs:
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

138)     for root, NULL, files in os.walk(fdir):
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

139)         for filename in scanfiles.intersection(files):
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

140)             for item in vdb:
141)                 if filename == item['file']:
142)                     mfile = os.path.join(root, filename)
Bernd Wurst error handling when opening...

Bernd Wurst authored 11 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 6 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

147)                     filestr = file.read()
148)                     file.close()
149) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

150)                     if ((item['extra_match']
151)                        and item['extra_match'] not in filestr)
152)                        or (item['extra_nomatch']
Hanno Böck fix nomatch logic

Hanno Böck authored 4 years ago

153)                        and item['extra_nomatch'] in filestr)
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

154)                        or (item['path_match']
155)                        and not root.endswith(item['path_match']))):
Hanno Böck add path_match feature, all...

Hanno Böck authored 4 years ago

156)                         continue
157) 
Hanno Böck simplify loop logic by usin...

Hanno Böck authored 4 years ago

158)                     findversion = item['variable'].search(filestr)
159)                     if not findversion:
160)                         continue
Hanno Böck codingstyle

Hanno Böck authored 4 years ago

161)                     findversion = findversion.group(1)
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

163)                     # Very ugly phpbb workaround
164)                     if item['add_minor']:
165)                         findversion = findversion.split('.')
166)                         findversion[-1] = str(int(findversion[-1])
167)                                               + int(item['add_minor']))
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

168)                         findversion = '.'.join(findversion)
169) 
Hanno Böck simplify versioncompare logic

Hanno Böck authored 4 years ago

170)                     if (not versioncompare(item['safe'], findversion)
171)                        or findversion in item['old_safe']):
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

172)                         if opts.all:
Hanno Böck simplify versioncompare logic

Hanno Böck authored 4 years ago

173)                             vulnprint(item['name'], findversion, "ok", "",
174)                                       mfile, item['subdir'], opts.xml)
175)                         continue
176) 
177)                     safev = item['safe']
178)                     for ver in item['old_safe']:
179)                         if versioncompare(ver, findversion):
180)                             safev = ver
181) 
182)                     vulnprint(item['name'], findversion, safev, item['vuln'],
183)                               mfile, item['subdir'], opts.xml)
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

184) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

185) if opts.xml: