Module: RubySMB::Client::Signing
- Included in:
- RubySMB::Client
- Defined in:
- lib/ruby_smb/client/signing.rb
Overview
Contains the methods for handling packet signing
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#smb1_sign(packet) ⇒ RubySMB::GenericPacket
Take an SMB1 packet and checks to see if it should be signed.
-
#smb2_sign(packet) ⇒ RubySMB::GenericPacket
Take an SMB2 packet and checks to see if it should be signed.
Instance Attribute Details
#session_key ⇒ String
10 11 12 |
# File 'lib/ruby_smb/client/signing.rb', line 10 def session_key @session_key end |
Instance Method Details
#smb1_sign(packet) ⇒ RubySMB::GenericPacket
Take an SMB1 packet and checks to see if it should be signed. If signing is enabled and we have a session key already, then it will sign the packet appropriately.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_smb/client/signing.rb', line 18 def smb1_sign(packet) if self.signing_required && !self.session_key.empty? # Pack the Sequence counter into a int64le packed_sequence_counter = [self.sequence_counter].pack('Q<') packet.smb_header.security_features = packed_sequence_counter signature = OpenSSL::Digest::MD5.digest(self.session_key + packet.to_binary_s)[0,8] packet.smb_header.security_features = signature self.sequence_counter += 1 packet else packet end end |
#smb2_sign(packet) ⇒ RubySMB::GenericPacket
Take an SMB2 packet and checks to see if it should be signed. If signing is enabled and we have a session key already, then it will sign the packet appropriately.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_smb/client/signing.rb', line 38 def smb2_sign(packet) if self.signing_required && !self.session_key.empty? packet.smb2_header.flags.signed = 1 packet.smb2_header.signature = "\x00" * 16 hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, self.session_key, packet.to_binary_s) packet.smb2_header.signature = hmac[0,16] packet else packet end end |