2f5e34d0408b47578a5896a4f6c39a7776c9dd76
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 accept old_safe versions wi...

Hanno Böck authored 1 year ago

44) def checkoldsafe(old_safe, find_version):
45)     find_version_tup = [int(x) for x in find_version.split(".")]
46)     for oldver in old_safe.split(","):
47)         oldver_tup = [int(x) for x in oldver.split(".")]
48) 
49)         if find_version_tup == oldver_tup:
50)             return True
51)         # handle special case where minor version is larger
52)         if (
53)             len(find_version_tup) >= 2
54)             and find_version_tup[:-1] == oldver_tup[:-1]
55)             and find_version_tup[-1] > oldver_tup[-1]
56)         ):
57)             return True
58)     return False
59) 
60) 
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

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

Hanno Böck authored 4 years ago

62)               xml):
Hanno Böck pycodestyle fixes

Hanno Böck authored 6 years ago

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

Hanno Böck authored 4 years ago

64)     if not xml:
Hanno Böck use more f-strings

Hanno Böck authored 2 years ago

65)         print(f"{appname} {version} ({safeversion}) {vuln} {appdir}")
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

66)     else:
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

67)         state = 'vulnerable'
68)         if safeversion == 'ok':
69)             state = 'ok'
Hanno Böck use more f-strings

Hanno Böck authored 2 years ago

70)         print(f'  <app state="{state}">')
71)         print(f'    <appname>{escape(appname)}</appname>')
72)         print(f'    <version>{escape(version)}</version>')
73)         print(f'    <directory>{escape(appdir)}</directory>')
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

74)         if state == 'vulnerable':
Hanno Böck use more f-strings

Hanno Böck authored 2 years ago

75)             print(f'    <safeversion>{escape(safeversion)}</safeversion>')
76)             print(f'    <vulninfo>{escape(vuln)}</vulninfo>')
Hanno Böck format syntax according to...

Hanno Böck authored 7 years ago

77)         print('  </app>')
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

78) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

79) 
80) # Command-line options
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

81) parser = argparse.ArgumentParser()
82) parser.add_argument("dirs", nargs="*",
83)                     help="Directories to scan")
84) parser.add_argument("-a", "--all", action="store_true",
85)                     help="Show all webapps found, not just vulnerable")
86) parser.add_argument("-x", "--xml", action="store_true",
87)                     help="Output results as XML")
88) parser.add_argument("-3", "--thirdparty", action="store_true",
89)                     help="Scan for third-party components like jquery")
90) opts = parser.parse_args()
Hanno Böck initial commit

Hanno Böck authored 16 years ago

91) 
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

98) if not jdir:
99)     print("Can't find freewvs json db")
100)     sys.exit(1)
101) 
102) jconfig = []
103) for cfile in glob.glob(jdir + '/*.json'):
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

104)     with open(cfile, encoding="ascii") as json_file:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

105)         data = json.load(json_file)
106)         jconfig += data
107) 
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 16 years ago

112) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

117) 
118) # start the search
119) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

120) for fdir in opts.dirs:
Hanno Böck protect against deep recurs...

Hanno Böck authored 3 years ago

121)     for root, dirs, files in os.walk(fdir):
122)         # this protects us against nested directories causing
123)         # an exception
124)         if root.count(os.sep) > 500:
125)             del dirs[:]
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

127)             for item in jconfig:
128)                 if not opts.thirdparty and 'thirdparty' in item:
129)                     continue
130)                 for det in item['detection']:
131)                     if filename == det['file']:
132)                         mfile = os.path.join(root, filename)
133)                         try:
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

134)                             file = open(mfile, encoding='ascii',
135)                                         errors='replace')
Hanno Böck replace deprecated IOError...

Hanno Böck authored 3 years ago

136)                         except OSError:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

137)                             continue
Hanno Böck limit data we read from fil...

Hanno Böck authored 3 years ago

138)                         filestr = file.read(200000)
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

139)                         file.close()
140) 
141)                         if (('extra_match' in det
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

142)                              and det['extra_match'] not in filestr)
143)                                 or ('extra_nomatch' in det
144)                                     and det['extra_nomatch'] in filestr)):
145)                             continue
146) 
147)                         if ('path_match' in det
148)                                 and (not root.endswith(det['path_match']))):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

149)                             continue
150) 
151)                         findversion = re.search(re.escape(det['variable'])
152)                                                 + r"[^0-9\n\r]*[.]*"
153)                                                 "([0-9.]*[0-9])[^0-9.]",
154)                                                 filestr)
155)                         if not findversion:
156)                             continue
157)                         findversion = findversion.group(1)
158) 
159)                         # Very ugly phpbb workaround
160)                         if 'add_minor' in det:
161)                             findversion = findversion.split('.')
162)                             findversion[-1] = str(int(findversion[-1])
Hanno Böck fix add_minor

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

164)                             findversion = '.'.join(findversion)
165) 
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

166)                         if (not versioncompare(item['safe'], findversion)
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

167)                                 or ('old_safe' in item
Hanno Böck accept old_safe versions wi...

Hanno Böck authored 1 year ago

168)                                     and checkoldsafe(item['old_safe'],
169)                                                      findversion))):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 4 years ago

184) if opts.xml: