# This file is part of packetgen-plugin-smb. # See https://github.com/sdaubert/packetgen-plugin-smb for more informations # Copyright (C) 2018 Sylvain Daubert # This program is published under MIT license. # frozen_string_literal: true module PacketGen::Plugin # Base class for NTLM authentication protocol. # @author Sylvain Daubert class NTLM < PacketGen::Types::Fields # NTLM message types TYPES = { 'negotiate' => 1, 'challenge' => 2, 'authenticate' => 3 }.freeze # NTLM signature SIGNATURE = "NTLMSSP\0" # void version VOID_VERSION = [0].pack('q').freeze VOID_CHALLENGE = VOID_VERSION # @!attribute signature # 8-byte NTLM signature # @return [String] define_field :signature, PacketGen::Types::String, static_length: 8, default: SIGNATURE # @!attribute type # 4-byte message type # @return [Integer] define_field :type, PacketGen::Types::Int32leEnum, enum: TYPES # @!attribute payload # @return [String] define_field :payload, PacketGen::Types::String class < 0 send(:"#{name}=", content) end self end # @abstract This class is meaningful for {NTLM} subclasses only. # Calculate and set +len+, +maxlen+ and +offset+ fields defined for # fields in {#payload}. # @return [void] def calc_length return self if self.class.payload_fields.nil? previous_len = 0 self.class.payload_fields.each do |name, _type_and_opt| send(:"#{name}_len=", 0) send(:"#{name}_offset=", offset_of(:payload) + previous_len) field = send(name) next unless field && !field.empty? length = field.respond_to?(:sz) ? field.sz : field.size send(:"#{name}_len=", length) send(:"#{name}_maxlen=", length) previous_len = length end end # @abstract This class is meaningful for {NTLM} subclasses only. # @return [String] def to_s s = super return s if self.class.payload_fields.nil? self.class.payload_fields.each do |name, _type_and_opt| attr = send(name) attr.unicode = unicode? if attr.respond_to?(:unicode=) s << attr.to_s unless attr.nil? || send("#{name}_len").zero? end s end end end require_relative 'ntlm/av_pair' require_relative 'ntlm/ntlmv2_response' require_relative 'ntlm/negotiate' require_relative 'ntlm/challenge' require_relative 'ntlm/authenticate'