d9b52caaf53d09eee43d101ecdb8450ef4cfe331
Hanno Böck Enforce python 3, remove py...

Hanno Böck authored 5 years ago

1) #!/usr/bin/python3 -O
Hanno Böck initial commit

Hanno Böck authored 17 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 7 years ago

5) # https://source.schokokeks.org/freewvs/
Hanno Böck initial commit

Hanno Böck authored 17 years ago

6) #
Hanno Böck remove year so we don't hav...

Hanno Böck authored 5 years ago

7) # Written by schokokeks.org Hosting, https://schokokeks.org
Hanno Böck initial commit

Hanno Böck authored 17 years ago

8) #
9) # Contributions by
Hanno Böck convert all http URLs to https

Hanno Böck authored 7 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 17 years ago

13) #
Hanno Böck License change to cc0

Hanno Böck authored 12 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 17 years ago

17) #
Hanno Böck License change to cc0

Hanno Böck authored 12 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 7 years ago

20) # https://creativecommons.org/publicdomain/zero/1.0/
Hanno Böck License change to cc0

Hanno Böck authored 12 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 17 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 5 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 5 years ago

31) import json
Bernd Wurst Add XML string escaping

Bernd Wurst authored 16 years ago

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

Hanno Böck authored 17 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 7 years ago

41) 
Hanno Böck initial commit

Hanno Böck authored 17 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 5 years ago

44)               xml):
Hanno Böck pycodestyle fixes

Hanno Böck authored 7 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 5 years ago

49)     else:
Bernd Wurst add XML output format

Bernd Wurst authored 16 years ago

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

Hanno Böck authored 7 years ago

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

Bernd Wurst authored 16 years ago

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

Hanno Böck authored 7 years ago

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

Bernd Wurst authored 16 years ago

61) 
Hanno Böck initial commit

Hanno Böck authored 17 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 17 years ago

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

Hanno Böck authored 5 years ago

75) jdir = False
76) for p in [os.path.dirname(sys.argv[0]) + '/freewvsdb', '/var/lib/freewvs']:
77)     if os.path.isdir(p):
78)         jdir = p
79) if not jdir:
80)     print("Can't find freewvs json db")
81)     sys.exit(1)
82) 
83) jconfig = []
84) for cfile in glob.glob(jdir + '/*.json'):
85)     with open(cfile) as json_file:
86)         data = json.load(json_file)
87)         jconfig += data
88) 
Hanno Böck performance improvement by...

Hanno Böck authored 5 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 16 years ago

93) 
Hanno Böck initial commit

Hanno Böck authored 17 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 17 years ago

98) 
99) # start the search
100) 
Hanno Böck argparse instead of depreca...

Hanno Böck authored 5 years ago

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

Hanno Böck authored 16 years ago

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

Hanno Böck authored 5 years ago

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

Hanno Böck authored 5 years ago

104)             for item in jconfig:
105)                 if not opts.thirdparty and 'thirdparty' in item:
106)                     continue
107)                 for det in item['detection']:
108)                     if filename == det['file']:
109)                         mfile = os.path.join(root, filename)
110)                         try:
111)                             file = open(mfile, errors='replace')
112)                         except Exception:
113)                             continue
114)                         filestr = file.read()
115)                         file.close()
116) 
117)                         if (('extra_match' in det
118)                            and det['extra_match'] not in filestr)
119)                            or ('extra_nomatch' in det
120)                            and det['extra_nomatch'] in filestr)
121)                            or ('path_match' in det
122)                            and not root.endswith(det['path_match']))):
123)                             continue
124) 
125)                         findversion = re.search(re.escape(det['variable'])
126)                                                 + r"[^0-9\n\r]*[.]*"
127)                                                 "([0-9.]*[0-9])[^0-9.]",
128)                                                 filestr)
129)                         if not findversion:
130)                             continue
131)                         findversion = findversion.group(1)
132) 
133)                         # Very ugly phpbb workaround
134)                         if 'add_minor' in det:
135)                             findversion = findversion.split('.')
136)                             findversion[-1] = str(int(findversion[-1])
Hanno Böck fix add_minor

Hanno Böck authored 5 years ago

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

Hanno Böck authored 5 years ago

138)                             findversion = '.'.join(findversion)
139) 
140)                         if (not versioncompare(item['safe'], findversion)
141)                            or ('old_safe' in item
142)                            and findversion in item['old_safe'].split(','))):
143)                             if opts.all:
144)                                 vulnprint(item['name'], findversion, "ok", "",
145)                                           mfile, det['subdir'], opts.xml)
146)                             continue
147) 
148)                         safev = item['safe']
149)                         if 'old_safe' in item:
150)                             for ver in item['old_safe'].split(','):
151)                                 if versioncompare(ver, findversion):
152)                                     safev = ver
153) 
154)                         vulnprint(item['name'], findversion, safev,
155)                                   item['vuln'], mfile, det['subdir'], opts.xml)
Bernd Wurst add XML output format

Bernd Wurst authored 16 years ago

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

Hanno Böck authored 5 years ago

157) if opts.xml: