-
Notifications
You must be signed in to change notification settings - Fork 39
/
prober.py
executable file
·282 lines (257 loc) · 8.03 KB
/
prober.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
#!/usr/bin/env python
import sys
import logging
import os.path
from optparse import OptionParser
# Ensure we can see the pytls/tls subdir for the pytls submodule
sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'pytls'))
from tls import *
from probes import *
import probe_db
__version__ = '0.0.4'
__author__ = 'Richard J. Moore'
__email__ = 'rich@kde.org'
# List all the probes we have
probes = [
NormalHandshake(),
NormalHandshakePFS(),
NormalHandshake11(),
NormalHandshake11PFS(),
NormalHandshake12(),
NormalHandshake12PFS(),
NormalHandshake12PFSw13(),
ChangeCipherSpec(),
ChangeCipherSpec12(),
ChangeCipherSpec12PFS(),
OnlyECCipherSuites(),
HighTLSVersion(),
HighTLSVersion12(),
HighTLSVersion12PFS(),
VeryHighTLSVersion(),
VeryHighTLSVersion12(),
VeryHighTLSVersion12PFS(),
ZeroTLSVersion(),
ZeroTLSVersion12(),
ZeroTLSVersion12PFS(),
HighHelloVersion(),
HighHelloVersionNew(),
HighHelloVersionPFS(),
VeryHighHelloVersion(),
VeryHighHelloVersionNew(),
VeryHighHelloVersionPFS(),
ZeroHelloVersion(),
BadContentType(),
RecordLengthOverflow(),
RecordLengthUnderflow(),
Heartbeat(),
Heartbeat12(),
Heartbeat12PFS(),
Heartbleed(),
Heartbleed12(),
Heartbleed12PFS(),
BadHandshakeMessage(),
InvalidSessionID(),
InvalidSessionID12(),
InvalidSessionID12PFS(),
InvalidCiphersLength(),
InvalidCiphersLength12(),
InvalidCiphersLength12PFS(),
InvalidExtLength(),
InvalidExtLength12(),
InvalidExtLength12PFS(),
EmptyCompression(),
EmptyCompression12(),
EmptyCompression12PFS(),
CompressOnly(),
CompressOnly12(),
CompressOnly12PFS(),
ExtensionsUnderflow(),
ExtensionsUnderflow12(),
ExtensionsUnderflow12PFS(),
DoubleClientHello(),
DoubleClientHello12(),
DoubleClientHello12PFS(),
EmptyRecord(),
EmptyRecord12(),
EmptyRecord12PFS(),
TwoInvalidPackets(),
SplitHelloRecords(),
SplitHelloRecords12(),
SplitHelloRecords12PFS(),
SplitHelloPackets(),
SplitHelloPackets12(),
SplitHelloPackets12PFS(),
NoCiphers(),
NoCiphers12(),
EmptyChangeCipherSpec(),
EmptyChangeCipherSpec12(),
EmptyChangeCipherSpec12PFS(),
HelloRequest(),
HelloRequest12(),
HelloRequest12PFS(),
SNIWrongName(),
SNIWrongName12(),
SNIWrongName12PFS(),
SNILongName(),
SNILongName12(),
SNILongName12PFS(),
SNIEmptyName(),
SNIEmptyName12(),
SNIEmptyName12PFS(),
SNIOneWrong(),
SNIOneWrong12(),
SNIOneWrong12PFS(),
SNIWithDifferentType(),
SNIWithDifferentType12(),
SNIWithDifferentType12PFS(),
SNIDifferentTypeRev(),
SNIDifferentTypeRev12(),
SNIDifferentTypeRev12PFS(),
SNIOverflow(),
SNIOverflow12(),
SNIOverflow12PFS(),
SNIUnderflow(),
SNIUnderflow12(),
SNIUnderflow12PFS(),
SecureRenegoOverflow(),
SecureRenegoOverflow12(),
SecureRenegoOverflow12PFS(),
SecureRenegoUnderflow(),
SecureRenegoUnderflow12(),
SecureRenegoUnderflow12PFS(),
SecureRenegoNonEmpty(),
SecureRenegoNonEmpty12(),
SecureRenegoNonEmpty12PFS(),
SecureRenegoNull(),
SecureRenegoNull12(),
SecureRenegoNull12PFS(),
MaxFragmentNull(),
MaxFragmentNull12(),
MaxFragmentNull12PFS(),
MaxFragmentInvalid(),
MaxFragmentInvalid12(),
MaxFragmentInvalid12PFS(),
ClientCertURLsNotNull(),
ClientCertURLsNotNull12(),
ClientCertURLsNotNull12PFS(),
TrustedCANull(),
TrustedCANull12(),
TrustedCANull12PFS(),
TrustedCAOverflow(),
TrustedCAOverflow12(),
TrustedCAOverflow12PFS(),
TrustedCAUnderflow(),
TrustedCAUnderflow12(),
TrustedCAUnderflow12PFS(),
TruncatedHMACNotNull(),
TruncatedHMACNotNull12(),
TruncatedHMACNotNull12PFS(),
OCSPNull(),
OCSPNull12(),
OCSPNull12PFS(),
OCSPOverflow(),
OCSPOverflow12(),
OCSPOverflow12PFS(),
OCSPUnderflow(),
OCSPUnderflow12(),
OCSPUnderflow12PFS(),
DoubleExtension(),
DoubleExtension12(),
DoubleExtension12PFS(),
UserMappingNull(),
UserMappingNull12(),
UserMappingNull12PFS(),
UserMappingOverflow(),
UserMappingOverflow12(),
UserMappingOverflow12PFS(),
ClientAuthzNull(),
ClientAuthzNull12(),
ClientAuthzNull12PFS(),
ClientAuthzOverflow(),
ClientAuthzOverflow12(),
ClientAuthzOverflow12PFS()
]
def probe(ipaddress, port, starttls, specified_probe):
results = {}
for probe in probes:
if specified_probe and specified_probe != type(probe).__name__:
continue
logging.info('Probing... %s', type(probe).__name__)
result = probe.probe(ipaddress, port, starttls)
results[type(probe).__name__] = result
return results
def list_probes():
for probe in probes:
if type(probe).__doc__ is None:
print type(probe).__name__
else:
print '%s: %s' % (type(probe).__name__, type(probe).__doc__)
def main():
options = OptionParser(usage='%prog server [options]',
description='A tool to fingerprint SSL/TLS servers')
options.add_option('-p', '--port',
type='int', default=443,
help='TCP port to test (default: 443)')
options.add_option('-m', '--matches', dest='matches',
type='int', default=0,
help=('Only display the first N matching scores'
'(default: 0 which displays them all)') )
options.add_option('-d', '--debug', action='store_true', dest='debug',
default=False,
help='Print debugging messages')
options.add_option( '-s', '--starttls', dest='starttls',
type='choice', action='store', default='auto',
choices=['auto','smtp','ftp','pop3','imap','none'],
help=('Enable a starttls mode. '
'The available modes are: auto, smtp, ftp, pop3, imap, none') )
options.add_option('-t', '--probe', dest='probe',
type='string',
help='Run the specified probe')
options.add_option('-a', '--add', dest='add', type='string',
help='Add the specified fingerprint to the database')
options.add_option('-l', '--list', dest='list', action='store_true',
help='List the fingerprints of the target')
options.add_option('--list-probes', dest='list_probes', action='store_true',
help='List the available probes')
options.add_option('-v', '--version', dest='version', action='store_true',
help='Display the version information')
opts, args = options.parse_args()
if opts.version:
print 'TLS Prober version %s, %s <%s>' % (__version__, __author__, __email__)
return
if opts.list_probes:
list_probes()
return
if len(args) < 1:
options.print_help()
return
if opts.debug:
logging.basicConfig(level=logging.DEBUG)
# Probe the server
results = probe(args[0], opts.port, opts.starttls, opts.probe)
# Add a fingerprint to the db
if opts.add:
filename = probe_db.add_fingerprint(opts.add, results)
print 'Added %s to the database' % opts.add
print 'The fingerprint is located at:', filename
print 'Please submit your new fingerprint for inclusion in the next release!'
return
# Print the results of the probe
if opts.list:
for key, val in sorted(results.items()):
print '%24s:\t%s' % (key, val)
return
# Print the matches
matches = probe_db.find_matches(results)
count = 0
prev_score = None
for server, score in matches:
if opts.matches:
if score != prev_score:
prev_score = score
count += 1
if count > opts.matches:
break
print("{0:>65}: {1:6.2f}%".format(server, score*100))
if __name__ == '__main__':
main()