03d0903de13355892914fa2151ca6cc8e0c781a6
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) 
Hanno Böck update URL and remove versi...

Hanno Böck authored 4 years ago

3) # freewvs - a free web vulnerability scanner
Hanno Böck initial commit

Hanno Böck authored 16 years ago

4) #
Hanno Böck update URL and remove versi...

Hanno Böck authored 4 years ago

5) # https://freewvs.schokokeks.org/
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 format syntax according to...

Hanno Böck authored 7 years ago

26) import os
27) import glob
28) import re
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

30) import sys
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

31) import json
Hanno Böck add ~/.cache/freewvs/ dir o...

Hanno Böck authored 4 years ago

32) import pathlib
Hanno Böck noqa for dlint, the escape...

Hanno Böck authored 4 years ago

33) from xml.sax.saxutils import escape  # noqa: DUO107
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) 
Hanno Böck warn people who have old-st...

Hanno Böck authored 4 years ago

76) # Warn people with old-style freewvsdb dirs,
77) # should be removed in a few months
78) for d in ["/usr/share/freewvs", "/usr/local/share/freewvs"]:
79)     if os.path.isdir(d):
80)         print("WARNING: Obsolete freewvs data in %s, removal recommended" % d,
81)               file=sys.stderr)
82) 
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

83) jdir = False
Hanno Böck add ~/.cache/freewvs/ dir o...

Hanno Böck authored 4 years ago

84) for p in [os.path.dirname(sys.argv[0]) + '/freewvsdb', '/var/lib/freewvs',
85)           str(pathlib.Path.home()) + "/.cache/freewvs/"]:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

86)     if os.path.isdir(p):
87)         jdir = p
Hanno Böck add ~/.cache/freewvs/ dir o...

Hanno Böck authored 4 years ago

88)         break
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

89) if not jdir:
90)     print("Can't find freewvs json db")
91)     sys.exit(1)
92) 
93) jconfig = []
94) for cfile in glob.glob(jdir + '/*.json'):
95)     with open(cfile) as json_file:
96)         data = json.load(json_file)
97)         jconfig += data
98) 
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

99) scanfiles = set()
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

100) for app in jconfig:
101)     for det in app['detection']:
102)         scanfiles.add(det['file'])
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

103) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

108) 
109) # start the search
110) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

111) for fdir in opts.dirs:
Hanno Böck use _ for unused variable t...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

113)         for filename in scanfiles.intersection(files):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

114)             for item in jconfig:
115)                 if not opts.thirdparty and 'thirdparty' in item:
116)                     continue
117)                 for det in item['detection']:
118)                     if filename == det['file']:
119)                         mfile = os.path.join(root, filename)
120)                         try:
121)                             file = open(mfile, errors='replace')
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

122)                         except IOError:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

123)                             continue
124)                         filestr = file.read()
125)                         file.close()
126) 
127)                         if (('extra_match' in det
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

128)                              and det['extra_match'] not in filestr)
129)                                 or ('extra_nomatch' in det
130)                                     and det['extra_nomatch'] in filestr)):
131)                             continue
132) 
133)                         if ('path_match' in det
134)                                 and (not root.endswith(det['path_match']))):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

135)                             continue
136) 
137)                         findversion = re.search(re.escape(det['variable'])
138)                                                 + r"[^0-9\n\r]*[.]*"
139)                                                 "([0-9.]*[0-9])[^0-9.]",
140)                                                 filestr)
141)                         if not findversion:
142)                             continue
143)                         findversion = findversion.group(1)
144) 
145)                         # Very ugly phpbb workaround
146)                         if 'add_minor' in det:
147)                             findversion = findversion.split('.')
148)                             findversion[-1] = str(int(findversion[-1])
Hanno Böck fix add_minor

Hanno Böck authored 4 years ago

149)                                                   + int(det['add_minor']))
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

150)                             findversion = '.'.join(findversion)
151) 
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

152)                         if ((not versioncompare(item['safe'], findversion))
153)                                 or ('old_safe' in item
154)                                     and findversion in
155)                                     item['old_safe'].split(','))):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

156)                             if opts.all:
157)                                 vulnprint(item['name'], findversion, "ok", "",
158)                                           mfile, det['subdir'], opts.xml)
159)                             continue
160) 
161)                         safev = item['safe']
162)                         if 'old_safe' in item:
163)                             for ver in item['old_safe'].split(','):
164)                                 if versioncompare(ver, findversion):
165)                                     safev = ver
166) 
167)                         vulnprint(item['name'], findversion, safev,
168)                                   item['vuln'], mfile, det['subdir'], opts.xml)
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 4 years ago

170) if opts.xml: