Sha256: 5ebe9b9de15c448466ce7d861e6e41d14da69b788bf01e6ab89984188d69cc8c

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

module RubySMB
  class Client
    # Contains the methods for handling packet signing
    module Signing
      # The NTLM Session Key used for signing
      # @!attribute [rw] session_key
      #   @return [String]
      attr_accessor :session_key

      # 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.
      #
      # @param packet [RubySMB::GenericPacket] the packet to sign
      # @return [RubySMB::GenericPacket] the packet, signed if needed
      def smb1_sign(packet)
        if signing_required && !session_key.empty?
          # Pack the Sequence counter into a int64le
          packed_sequence_counter = [sequence_counter].pack('Q<')
          packet.smb_header.security_features = packed_sequence_counter
          signature = OpenSSL::Digest::MD5.digest(session_key + packet.to_binary_s)[0, 8]
          packet.smb_header.security_features = signature
          self.sequence_counter += 1
        end
        packet
      end

      # 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.
      #
      # @param packet [RubySMB::GenericPacket] the packet to sign
      # @return [RubySMB::GenericPacket] the packet, signed if needed
      def smb2_sign(packet)
        if signing_required && !session_key.empty?
          packet.smb2_header.flags.signed = 1
          packet.smb2_header.signature = "\x00" * 16
          hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, session_key, packet.to_binary_s)
          packet.smb2_header.signature = hmac[0, 16]
        end
        packet
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruby_smb-1.1.0 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.5 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.4 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.3 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.2 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.1 lib/ruby_smb/client/signing.rb
ruby_smb-1.0.0 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.24 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.23 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.22 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.21 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.20 lib/ruby_smb/client/signing.rb
ruby_smb-0.0.19 lib/ruby_smb/client/signing.rb