2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-11-26 02:34:39 +00:00
|
|
|
require 'rex/text'
|
|
|
|
|
2005-03-27 00:23:10 +00:00
|
|
|
module Rex
|
2005-07-16 07:38:31 +00:00
|
|
|
module Proto
|
2005-03-27 00:23:10 +00:00
|
|
|
module SMB
|
2005-09-16 09:27:41 +00:00
|
|
|
class Crypt
|
2005-03-27 00:23:10 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
@@loaded_openssl = false
|
2012-05-24 23:10:26 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
begin
|
|
|
|
require 'openssl'
|
|
|
|
@@loaded_openssl = true
|
|
|
|
rescue ::Exception
|
|
|
|
end
|
2005-11-03 04:43:19 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
# Return a signed SMB packet
|
|
|
|
def self.sign_smb_packet(mackey, sequence_counter, data)
|
|
|
|
raise RuntimeError, "No OpenSSL support" if not @@loaded_openssl
|
|
|
|
seq = Rex::Text::pack_int64le(sequence_counter)
|
|
|
|
netbios_hdr = data.slice!(0,4)
|
|
|
|
data[14,8] = seq
|
|
|
|
signature = OpenSSL::Digest::MD5.digest(mackey + data)[0,8]
|
|
|
|
data[14,8] = signature
|
|
|
|
netbios_hdr + data
|
|
|
|
end
|
2005-03-27 00:23:10 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.is_signature_correct?(mackey, sequence_counter, data)
|
|
|
|
signature1 = data[18,8]
|
|
|
|
signature2 = sign_smb_packet(mackey, sequence_counter, data.dup)[18,8]
|
|
|
|
return signature1 == signature2
|
|
|
|
end
|
2005-03-27 00:23:10 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-10-22 22:42:52 +00:00
|
|
|
end
|