1beae8164abac0f7c1962a5e40a6f4aae90cdaa7
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 change license to 0BSD due...

Hanno Böck authored 1 year ago

13) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

15) import argparse
Hanno Böck sort imports

Hanno Böck authored 4 months ago

16) import glob
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

17) import json
Hanno Böck sort imports

Hanno Böck authored 4 months ago

18) import os
Hanno Böck add ~/.cache/freewvs/ dir o...

Hanno Böck authored 4 years ago

19) import pathlib
Hanno Böck sort imports

Hanno Böck authored 4 months ago

20) import re
21) import sys
Hanno Böck noqa for dlint, the escape...

Hanno Böck authored 4 years ago

22) from xml.sax.saxutils import escape  # noqa: DUO107
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

26)     if safe_version == "":
27)         return True
Hanno Böck simplify versioncompare logic

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

31) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

32) 
Hanno Böck accept old_safe versions wi...

Hanno Böck authored 1 year ago

33) def checkoldsafe(old_safe, find_version):
34)     find_version_tup = [int(x) for x in find_version.split(".")]
35)     for oldver in old_safe.split(","):
36)         oldver_tup = [int(x) for x in oldver.split(".")]
37) 
38)         if find_version_tup == oldver_tup:
39)             return True
40)         # handle special case where minor version is larger
41)         if (
42)             len(find_version_tup) >= 2
43)             and find_version_tup[:-1] == oldver_tup[:-1]
44)             and find_version_tup[-1] > oldver_tup[-1]
45)         ):
46)             return True
47)     return False
48) 
49) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

54)     else:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

55)         state = "vulnerable"
56)         if safeversion == "ok":
57)             state = "ok"
Hanno Böck use more f-strings

Hanno Böck authored 2 years ago

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

Hanno Böck authored 1 year ago

59)         print(f"    <appname>{escape(appname)}</appname>")
60)         print(f"    <version>{escape(version)}</version>")
61)         print(f"    <directory>{escape(appdir)}</directory>")
62)         if state == "vulnerable":
63)             print(f"    <safeversion>{escape(safeversion)}</safeversion>")
64)             print(f"    <vulninfo>{escape(vuln)}</vulninfo>")
65)         print("  </app>")
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

66) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

67) 
68) # Command-line options
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

70) parser.add_argument("dirs", nargs="*", help="Directories to scan")
71) parser.add_argument(
72)     "-a",
73)     "--all",
74)     action="store_true",
75)     help="Show all webapps found, not just vulnerable",
76) )
77) parser.add_argument("-x", "--xml", action="store_true", help="Output results as XML")
78) parser.add_argument(
79)     "-3",
80)     "--thirdparty",
81)     action="store_true",
82)     help="Scan for third-party components like jquery",
83) )
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

95) if not jdir:
96)     print("Can't find freewvs json db")
97)     sys.exit(1)
98) 
99) jconfig = []
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

102)         data = json.load(json_file)
103)         jconfig += data
104) 
Hanno Böck performance improvement by...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 16 years ago

109) 
Hanno Böck initial commit

Hanno Böck authored 16 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 16 years ago

114) 
115) # start the search
116) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

126)                     continue
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

135)                         file.close()
136) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

137)                         if (
138)                             "extra_match" in det and det["extra_match"] not in filestr
139)                         ) or (
140)                             "extra_nomatch" in det and det["extra_nomatch"] in filestr
141)                         ):
Hanno Böck make pylint happier

Hanno Böck authored 4 years ago

142)                             continue
143) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

147)                             continue
148) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

149)                         findversion = re.search(
150)                             re.escape(det["variable"]) + r"[^0-9\n\r]*[.]*"
151)                             "([0-9.]*[0-9])[^0-9.]",
152)                             filestr,
153)                         )
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

154)                         if not findversion:
155)                             continue
156)                         findversion = findversion.group(1)
157) 
158)                         # Very ugly phpbb workaround
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

159)                         if "add_minor" in det:
160)                             findversion = findversion.split(".")
161)                             findversion[-1] = str(
162)                                 int(findversion[-1]) + int(det["add_minor"])
163)                             )
164)                             findversion = ".".join(findversion)
165) 
166)                         if not versioncompare(item["safe"], findversion) or (
167)                             "old_safe" in item
168)                             and checkoldsafe(item["old_safe"], findversion)
169)                         ):
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

171)                                 vulnprint(
172)                                     item["name"],
173)                                     findversion,
174)                                     "ok",
175)                                     "",
176)                                     mfile,
177)                                     det["subdir"],
178)                                     opts.xml,
179)                                 )
Hanno Böck switch to json-based freewvsdb

Hanno Böck authored 4 years ago

180)                             continue
181) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

185)                                 if versioncompare(ver, findversion):
186)                                     safev = ver
187) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

188)                         vulnprint(
189)                             item["name"],
190)                             findversion,
191)                             safev,
192)                             item["vuln"],
193)                             mfile,
194)                             det["subdir"],
195)                             opts.xml,
196)                         )
Bernd Wurst add XML output format

Bernd Wurst authored 15 years ago

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

Hanno Böck authored 4 years ago

198) if opts.xml: