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
|
|
|
|
2008-11-12 22:47:21 +00:00
|
|
|
@@loaded_openssl = false
|
2012-05-24 23:10:26 +00:00
|
|
|
|
2008-11-12 22:47:21 +00:00
|
|
|
begin
|
|
|
|
require 'openssl'
|
|
|
|
@@loaded_openssl = true
|
|
|
|
rescue ::Exception
|
|
|
|
end
|
2005-11-03 04:43:19 +00:00
|
|
|
|
2011-03-09 05:04:42 +00:00
|
|
|
# Return a signed SMB packet
|
2011-03-07 19:57:53 +00:00
|
|
|
def self.sign_smb_packet(mackey, sequence_counter, data)
|
2011-03-09 05:04:42 +00:00
|
|
|
raise RuntimeError, "No OpenSSL support" if not @@loaded_openssl
|
2011-03-07 19:57:53 +00:00
|
|
|
seq = Rex::Text::pack_int64le(sequence_counter)
|
|
|
|
netbios_hdr = data.slice!(0,4)
|
2012-05-24 23:10:26 +00:00
|
|
|
data[14,8] = seq
|
2011-03-07 19:57:53 +00:00
|
|
|
signature = OpenSSL::Digest::MD5.digest(mackey + data)[0,8]
|
|
|
|
data[14,8] = signature
|
|
|
|
netbios_hdr + data
|
2005-03-27 00:23:10 +00:00
|
|
|
end
|
|
|
|
|
2011-03-07 19:57:53 +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
|
2005-03-27 00:23:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-10-22 22:42:52 +00:00
|
|
|
end
|