v0.1.3
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 use black codingstyle

Hanno Böck authored 1 year ago

61) def vulnprint(appname, version, safeversion, vuln, vfilename, subdir, xml):
62)     appdir = "/".join(os.path.abspath(vfilename).split("/")[: -1 - subdir])
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

65)     else:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 2 years ago

69)         print(f'  <app state="{state}">')
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

70)         print(f"    <appname>{escape(appname)}</appname>")
71)         print(f"    <version>{escape(version)}</version>")
72)         print(f"    <directory>{escape(appdir)}</directory>")
73)         if state == "vulnerable":
74)             print(f"    <safeversion>{escape(safeversion)}</safeversion>")
75)             print(f"    <vulninfo>{escape(vuln)}</vulninfo>")
76)         print("  </app>")
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

77) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

80) parser = argparse.ArgumentParser()
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

95) opts = parser.parse_args()
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

97) jdir = False
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

106) if not jdir:
107)     print("Can't find freewvs json db")
108)     sys.exit(1)
109) 
110) jconfig = []
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

111) for cfile in glob.glob(jdir + "/*.json"):
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

113)         data = json.load(json_file)
114)         jconfig += data
115) 
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

117) for app in jconfig:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

118)     for det in app["detection"]:
119)         scanfiles.add(det["file"])
Hanno Böck fix lot's of pylint issues...

Hanno Böck authored 16 years ago

120) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

123)     print('<?xml version="1.0" ?>')
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

124)     print("<freewvs>")
Hanno Böck initial commit

Hanno Böck authored 16 years ago

125) 
126) # start the search
127) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

129)     for root, dirs, files in os.walk(fdir):
130)         # this protects us against nested directories causing
131)         # an exception
132)         if root.count(os.sep) > 500:
133)             del dirs[:]
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

135)             for item in jconfig:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

136)                 if not opts.thirdparty and "thirdparty" in item:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

137)                     continue
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

138)                 for det in item["detection"]:
139)                     if filename == det["file"]:
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

140)                         mfile = os.path.join(root, filename)
141)                         try:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

142)                             file = open(mfile, encoding="ascii", errors="replace")
Hanno Böck replace deprecated IOError...

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

146)                         file.close()
147) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

148)                         if (
149)                             "extra_match" in det and det["extra_match"] not in filestr
150)                         ) or (
151)                             "extra_nomatch" in det and det["extra_nomatch"] in filestr
152)                         ):
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

153)                             continue
154) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

155)                         if "path_match" in det and (
156)                             not root.endswith(det["path_match"])
157)                         ):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

158)                             continue
159) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

160)                         findversion = re.search(
161)                             re.escape(det["variable"]) + r"[^0-9\n\r]*[.]*"
162)                             "([0-9.]*[0-9])[^0-9.]",
163)                             filestr,
164)                         )
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

165)                         if not findversion:
166)                             continue
167)                         findversion = findversion.group(1)
168) 
169)                         # Very ugly phpbb workaround
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

170)                         if "add_minor" in det:
171)                             findversion = findversion.split(".")
172)                             findversion[-1] = str(
173)                                 int(findversion[-1]) + int(det["add_minor"])
174)                             )
175)                             findversion = ".".join(findversion)
176) 
177)                         if not versioncompare(item["safe"], findversion) or (
178)                             "old_safe" in item
179)                             and checkoldsafe(item["old_safe"], findversion)
180)                         ):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

181)                             if opts.all:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

182)                                 vulnprint(
183)                                     item["name"],
184)                                     findversion,
185)                                     "ok",
186)                                     "",
187)                                     mfile,
188)                                     det["subdir"],
189)                                     opts.xml,
190)                                 )
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

191)                             continue
192) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

193)                         safev = item["safe"]
194)                         if "old_safe" in item:
195)                             for ver in item["old_safe"].split(","):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

196)                                 if versioncompare(ver, findversion):
197)                                     safev = ver
198) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

199)                         vulnprint(
200)                             item["name"],
201)                             findversion,
202)                             safev,
203)                             item["vuln"],
204)                             mfile,
205)                             det["subdir"],
206)                             opts.xml,
207)                         )
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 4 years ago

209) if opts.xml: