This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
typo3scan.py
executable file
·288 lines (256 loc) · 14.3 KB
/
typo3scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Typo3Scan - Automatic Typo3 Enumeration Tool
# Copyright (c) 2014-2024 Jan Rude
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/)
#-------------------------------------------------------------------------------
__version__ = '1.2'
__program__ = 'Typo3Scan'
__description__ = 'Automatic Typo3 enumeration tool'
__author__ = 'https://github.com/whoot'
import sys
import json
import sqlite3
import os.path
import argparse
from lib.domain import Domain
from fake_useragent import UserAgent
from lib.extensions import Extensions
from pkg_resources import parse_version
from colorama import Fore, init, deinit, Style
init(strip=False)
class Typo3:
def __init__(self, domain_list, threads, timeout, cookie, basic_auth, user_agent, json_out, force, vuln, no_interaction):
self.__database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib', 'typo3scan.db')
self.__extensions = []
self.__domain_list = domain_list
if json_out.endswith('/'):
self.__json = json_out + 'typo3scan.json'
elif json_out.endswith('.json'):
self.__json = json_out
else:
self.__json = json_out + '/typo3scan.json'
self.__json_log = {}
self.__force = force
self.__vuln = vuln
if not user_agent:
ua = UserAgent()
user_agent = ua.random
self.__custom_headers = {'User-Agent' : user_agent}
self.__cookies = {}
if cookie:
name = cookie.split('=')[0]
value = cookie.split('=')[1]
self.__cookies = {name: value}
self.__basic_auth = False
if basic_auth:
self.__basic_auth = basic_auth.split(':', 1)
self.__config = {'threads': threads, 'timeout': timeout, 'auth': self.__basic_auth, 'cookies': self.__cookies, 'headers': self.__custom_headers, 'no_interaction': no_interaction}
def run(self):
try:
for domain in self.__domain_list:
print(Fore.CYAN + Style.BRIGHT + '\n\n[ Checking {} ]\n'.format(domain) + '-'* 73 + Fore.RESET + Style.RESET_ALL)
check = Domain(domain, self.__config)
root = check.check_root()
if not root:
check_404 = check.check_404()
if not check_404:
check_nextGen = check.check_nextGen()
if not check.is_typo3() and self.__force is False:
print(Fore.RED + '\n[x] It seems that Typo3 is not used on this domain\n' + Fore.RESET)
else:
# check for typo3 information
print('\n [+] Core Information')
print(' --------------------')
check.search_login()
check.search_typo3_version()
# Search extensions
print('\n [+] Extension Search')
if not self.__extensions:
conn = sqlite3.connect(self.__database)
c = conn.cursor()
if self.__vuln:
for row in c.execute('SELECT extensionkey FROM extension_vulns'):
self.__extensions.append(row[0])
self.__extensions = set(self.__extensions)
else:
for row in c.execute('SELECT extensionkey FROM extensions'):
self.__extensions.append(row[0])
conn.close()
print (' \u251c Brute-Forcing {} Extensions'.format(len(self.__extensions)))
extensions = Extensions(check.get_path(), self.__extensions, self.__config)
ext_list = extensions.search_extension()
json_ext = []
if ext_list:
print ('\n \u251c Found {} extensions'.format(len(ext_list)))
print (' \u251c Brute-Forcing Version Information'.format(len(self.__extensions)))
print (Fore.YELLOW + ' [!] Version detection for extensions is unreliable. Verify manually!'.format(len(self.__extensions)) + Fore.RESET)
ext_list = extensions.search_ext_version(ext_list)
json_ext = extensions.output(ext_list)
else:
print ('\n [!] No extensions found.\n')
self.__json_log[domain] = {'Backend': check.get_backend(), 'Version': check.get_typo3_version(), 'Vulnerabilities':check.get_typo3_vulns(), 'Extensions': json_ext}
if self.__json:
json.dump(self.__json_log, open(self.__json, 'w'))
except KeyboardInterrupt:
print('\nReceived keyboard interrupt.\nQuitting...')
sys.exit(1)
finally:
deinit()
if __name__ == '__main__':
print('\n' + 73*'=' + Style.BRIGHT)
print(Fore.CYAN)
print(r'________ ________ _________ '.center(73))
print(r'\_ _/__ __ ______ _____\_____ \ / _____/ ____ _____ ___ '.center(73))
print(r' | | | | |\____ \| _ | _(__ < \_____ \_/ ___\\__ \ / \ '.center(73))
print(r' | | |___ || |_) | (_) |/ \/ \ \___ / __ \| | \ '.center(73))
print(r' |__| / ____|| __/|_____|________/_________/\_____|_____/|__|__/ '.center(73))
print(r' \/ |__| '.center(73))
print(Fore.RESET + Style.RESET_ALL)
print(__description__.center(73))
print(('Version ' + __version__).center(73))
print((__author__).center(73))
print(73*'=')
def print_help():
print(
"""\nUsage: python typo3scan.py [options]
Options:
-h, --help Show this help message and exit.
Target:
At least one of these options has to be provided to define the target(s):
--domain | -d <target url> The Typo3 URL(s)/domain(s) to scan.
--file | -f <file> Parse targets from file (one domain per line).
Optional:
You dont need to specify this arguments, but you may want to
--vuln Check for extensions with known vulnerabilities only.
--timeout TIMEOUT Request Timeout.
Default: 10 seconds
--auth USER:PASS Username and Password for HTTP Basic Authorization.
--cookie NAME=VALUE Can be used for authenticiation based on cookies.
--agent USER-AGENT Set custom User-Agent for requests.
--threads THREADS The number of threads to use for enumerating extensions.
Default: 5
--json PATH Path for json output file.
Default: current working directory
--force Force enumeration.
--no-interaction Do not ask any interactive question.
General:
-u | --update Update extensions and vulnerability database.
--core VERSION Show all known vulnerabilities for given Typo3 version.
--ext EXT:VERSION Show all known vulnerabilities for given extension and version.
""")
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_mutually_exclusive_group()
help = parser.add_mutually_exclusive_group()
group.add_argument('-f', '--file', dest='file')
group.add_argument('-d', '--domain', dest='domain', type=str, nargs='+')
group.add_argument('-u', '--update', dest='update', action='store_true')
group.add_argument('--core', dest='core', type=str)
group.add_argument('--ext', dest='extension', type=str)
parser.add_argument('--force', dest='force', action='store_true')
parser.add_argument('--vuln', dest='vuln', action='store_true')
parser.add_argument('--threads', dest='threads', type=int, default=5)
parser.add_argument('--auth', dest='basic_auth', type=str, default='')
parser.add_argument('--cookie', dest='cookie', type=str, default='')
parser.add_argument('--agent', dest='user_agent', type=str, default='')
parser.add_argument('--timeout', dest='timeout', type=int, default=10)
parser.add_argument('--json', dest='json', type=str, default=os.path.join(os.getcwd(), 'typo3scan.json'))
parser.add_argument('--no-interaction', dest='no_interaction', action='store_true')
help.add_argument( '-h', '--help', action='store_true')
args = parser.parse_args()
if args.help or not len(sys.argv) > 1:
print_help()
elif args.update:
from lib.update import Update
Update()
elif args.core:
database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib', 'typo3scan.db')
conn = sqlite3.connect('lib/typo3scan.db')
c = conn.cursor()
c.execute('SELECT advisory, vulnerability, subcomponent, affected_version_max, affected_version_min, severity FROM core_vulns WHERE (?<=affected_version_max AND ?>=affected_version_min)', (args.core, args.core,))
data = c.fetchall()
json_list = {}
if data:
for vulnerability in data:
if parse_version(args.core) <= parse_version(vulnerability[3]):
json_list[vulnerability[0]] = {'Type': vulnerability[1], 'Subcomponent': vulnerability[2], 'Affected': '{} - {}'.format(vulnerability[3], vulnerability[4]), 'Severity': vulnerability[5],'Advisory': 'https://typo3.org/security/advisory/{}'.format(vulnerability[0].lower())}
if json_list:
print(Style.BRIGHT + '\n[+] Known Vulnerabilities for Typo3 v{}\n'.format(args.core) + Style.RESET_ALL)
for vulnerability in json_list.keys():
print(Style.BRIGHT + ' [!] {}'.format(Fore.RED + vulnerability + Style.RESET_ALL))
print(' \u251c Vulnerability Type:'.ljust(28) + json_list[vulnerability]['Type'])
print(' \u251c Subcomponent:'.ljust(28) + json_list[vulnerability]['Subcomponent'])
print(' \u251c Affected Versions:'.ljust(28) + json_list[vulnerability]['Affected'])
print(' \u251c Severity:'.ljust(28) + json_list[vulnerability]['Severity'])
print(' \u2514 Advisory URL:'.ljust(28) + json_list[vulnerability]['Advisory'] + '\n')
if not json_list:
print('\n' + Fore.GREEN + Style.BRIGHT + '[+] Typo3 v{} has no known vulnerabilities\n'.format(args.core) + Style.RESET_ALL)
elif args.extension:
database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib', 'typo3scan.db')
conn = sqlite3.connect('lib/typo3scan.db')
c = conn.cursor()
name = ''
version = ''
if not ':' in args.extension:
name = args.extension
version = '0.0.0'
else:
name = (args.extension).split(':')[0]
version = (args.extension).split(':')[1]
c.execute('SELECT ROWID FROM extensions WHERE extensionkey=?', (name,))
data = c.fetchall()
if (len(data) == 0):
print('\n' + Fore.RED + Style.BRIGHT + '[!] Extension \'{}\' does not exist\n'.format(name) + Style.RESET_ALL)
sys.exit(1)
else:
c.execute('SELECT advisory, vulnerability, affected_version_max, affected_version_min, severity FROM extension_vulns WHERE (extensionkey=? AND ?<=affected_version_max AND ?>=affected_version_min)', (name, version, version,))
data = c.fetchall()
json_list = {}
if data:
for vulnerability in data:
if parse_version(version) <= parse_version(vulnerability[2]):
json_list[vulnerability[0]] = {'Type': vulnerability[1], 'Affected': '{} - {}'.format(vulnerability[2], vulnerability[3]), 'Severity': vulnerability[4], 'Advisory': 'https://typo3.org/security/advisory/{}'.format(vulnerability[0].lower())}
if json_list:
if version == '0.0.0':
print(Style.BRIGHT + '\n[+] Known vulnerabilities for \'{}\'\n'.format(name) + Style.RESET_ALL)
else:
print(Style.BRIGHT + '\n[+] Known vulnerabilities for \'{}\' v{}\n'.format(name, version) + Style.RESET_ALL)
for vulnerability in json_list.keys():
print(Style.BRIGHT + ' [!] {}'.format(Fore.RED + vulnerability + Style.RESET_ALL))
print(' \u251c Vulnerability Type: '.ljust(28) + json_list[vulnerability]['Type'])
print(' \u251c Affected Versions: '.ljust(28) + '{}'.format(json_list[vulnerability]['Affected']))
print(' \u251c Severity:'.ljust(28) + json_list[vulnerability]['Severity'])
print(' \u2514 Advisory URL:'.ljust(28) + '{}\n'.format(json_list[vulnerability]['Advisory'].lower()))
if not json_list:
print('\n' + Fore.GREEN + Style.BRIGHT + '[+] \'{}\' v{} has no known vulnerabilities\n'.format(name, version) + Style.RESET_ALL)
else:
if args.force:
print('\n' + Fore.RED + Style.BRIGHT + '!! FORCE MODE ENABLED !!'.center(73))
print('!! Expect False Positives !!'.center(73) + Style.RESET_ALL)
domain_list = list()
if args.domain:
for dom in args.domain:
domain_list.append(dom)
elif args.file:
if not os.path.isfile(args.file):
print(Fore.RED + '\n[x] File not found: {}\n | Aborting...'.format(args.file) + Fore.RESET)
sys.exit(1)
else:
with open(args.file, 'r') as f:
for line in f:
domain_list.append(line.strip())
main = Typo3(domain_list, args.threads, args.timeout, args.cookie, args.basic_auth, args.user_agent, args.json, args.force, args.vuln, args.no_interaction)
main.run()