public byte[] GetBytes()
        {
            int fixedLength = 32;

            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                fixedLength += 8;
            }
            int payloadLength = DomainName.Length * 2 + Workstation.Length * 2;

            byte[] buffer = new byte[fixedLength + payloadLength];
            ByteWriter.WriteAnsiString(buffer, 0, AuthenticationMessageUtils.ValidSignature, 8);
            LittleEndianWriter.WriteUInt32(buffer, 8, (uint)MessageType);
            LittleEndianWriter.WriteUInt32(buffer, 12, (uint)NegotiateFlags);

            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                Version.WriteBytes(buffer, 32);
            }

            int offset = fixedLength;

            AuthenticationMessageUtils.WriteBufferPointer(buffer, 16, (ushort)(DomainName.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, DomainName);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 16, (ushort)(Workstation.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, Workstation);

            return(buffer);
        }
        public byte[] GetBytes()
        {
            int fixedLength = 48;

            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                fixedLength += 8;
            }

            int payloadLength = TargetName.Length * 2 + TargetInfo.Length;

            byte[] buffer = new byte[fixedLength + payloadLength];
            ByteWriter.WriteAnsiString(buffer, 0, AuthenticationMessageUtils.ValidSignature, 8);
            LittleEndianWriter.WriteUInt32(buffer, 8, (uint)MessageType);
            LittleEndianWriter.WriteUInt32(buffer, 20, (uint)NegotiateFlags);
            ByteWriter.WriteBytes(buffer, 24, ServerChallenge);
            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                Version.WriteBytes(buffer, 48);
            }

            int offset = fixedLength;

            AuthenticationMessageUtils.WriteBufferPointer(buffer, 12, (ushort)(TargetName.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, TargetName);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 40, (ushort)TargetInfo.Length, (uint)offset);
            ByteWriter.WriteBytes(buffer, ref offset, TargetInfo);

            return(buffer);
        }
 public NegotiateMessage(byte[] buffer)
 {
     Signature      = ByteReader.ReadAnsiString(buffer, 0, 8);
     MessageType    = (MessageTypeName)LittleEndianConverter.ToUInt32(buffer, 8);
     NegotiateFlags = (NegotiateFlags)LittleEndianConverter.ToUInt32(buffer, 12);
     DomainName     = AuthenticationMessageUtils.ReadAnsiStringBufferPointer(buffer, 16);
     Workstation    = AuthenticationMessageUtils.ReadAnsiStringBufferPointer(buffer, 24);
     if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
     {
         Version = new Version(buffer, 32);
     }
 }
 public ChallengeMessage(byte[] buffer)
 {
     Signature       = ByteReader.ReadAnsiString(buffer, 0, 8);
     MessageType     = (MessageTypeName)LittleEndianConverter.ToUInt32(buffer, 8);
     TargetName      = AuthenticationMessageUtils.ReadUnicodeStringBufferPointer(buffer, 12);
     NegotiateFlags  = (NegotiateFlags)LittleEndianConverter.ToUInt32(buffer, 20);
     ServerChallenge = ByteReader.ReadBytes(buffer, 24, 8);
     // Reserved
     TargetInfo = AuthenticationMessageUtils.ReadBufferPointer(buffer, 40);
     if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
     {
         Version = new Version(buffer, 48);
     }
 }
Example #5
0
 public AuthenticateMessage(byte[] buffer)
 {
     Signature                 = ByteReader.ReadAnsiString(buffer, 0, 8);
     MessageType               = (MessageTypeName)LittleEndianConverter.ToUInt32(buffer, 8);
     LmChallengeResponse       = AuthenticationMessageUtils.ReadBufferPointer(buffer, 12);
     NtChallengeResponse       = AuthenticationMessageUtils.ReadBufferPointer(buffer, 20);
     DomainName                = AuthenticationMessageUtils.ReadUnicodeStringBufferPointer(buffer, 28);
     UserName                  = AuthenticationMessageUtils.ReadUnicodeStringBufferPointer(buffer, 36);
     WorkStation               = AuthenticationMessageUtils.ReadUnicodeStringBufferPointer(buffer, 44);
     EncryptedRandomSessionKey = AuthenticationMessageUtils.ReadBufferPointer(buffer, 52);
     NegotiateFlags            = (NegotiateFlags)LittleEndianConverter.ToUInt32(buffer, 60);
     if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
     {
         Version = new Version(buffer, 64);
     }
 }
Example #6
0
        public byte[] GetBytes()
        {
            int fixedLength = 64;

            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                fixedLength += 8;
            }

            int payloadLength = LmChallengeResponse.Length + NtChallengeResponse.Length + DomainName.Length * 2 + UserName.Length * 2 + WorkStation.Length * 2 + EncryptedRandomSessionKey.Length;

            byte[] buffer = new byte[fixedLength + payloadLength];
            ByteWriter.WriteAnsiString(buffer, 0, AuthenticationMessageUtils.ValidSignature, 8);
            LittleEndianWriter.WriteUInt32(buffer, 8, (uint)MessageType);
            LittleEndianWriter.WriteUInt32(buffer, 60, (uint)NegotiateFlags);
            if ((NegotiateFlags & NegotiateFlags.NegotiateVersion) > 0)
            {
                Version.WriteBytes(buffer, 64);
            }

            int offset = fixedLength;

            AuthenticationMessageUtils.WriteBufferPointer(buffer, 12, (ushort)LmChallengeResponse.Length, (uint)offset);
            ByteWriter.WriteBytes(buffer, ref offset, LmChallengeResponse);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 20, (ushort)NtChallengeResponse.Length, (uint)offset);
            ByteWriter.WriteBytes(buffer, ref offset, NtChallengeResponse);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 28, (ushort)(DomainName.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, DomainName);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 36, (ushort)(UserName.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, UserName);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 44, (ushort)(WorkStation.Length * 2), (uint)offset);
            ByteWriter.WriteUnicodeString(buffer, ref offset, WorkStation);
            AuthenticationMessageUtils.WriteBufferPointer(buffer, 52, (ushort)EncryptedRandomSessionKey.Length, (uint)offset);
            ByteWriter.WriteBytes(buffer, ref offset, EncryptedRandomSessionKey);

            return(buffer);
        }