예제 #1
0
        public override void WriteCommandBytes(byte[] buffer, int offset)
        {
            SecurityBufferOffset = 0;
            SecurityBufferLength = (ushort)SecurityBuffer.Length;
            int paddedSecurityBufferLength = (int)Math.Ceiling((double)SecurityBufferLength / 8) * 8;

            if (SecurityBuffer.Length > 0)
            {
                SecurityBufferOffset = SMB2Header.Length + FixedSize;
            }
            NegotiateContextOffset = 0;
            NegotiateContextCount  = (ushort)NegotiateContextList.Count;
            if (NegotiateContextList.Count > 0)
            {
                // NegotiateContextList must be 8-byte aligned
                NegotiateContextOffset = (uint)(SMB2Header.Length + FixedSize + paddedSecurityBufferLength);
            }
            LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
            LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)SecurityMode);
            LittleEndianWriter.WriteUInt16(buffer, offset + 4, (ushort)DialectRevision);
            LittleEndianWriter.WriteUInt16(buffer, offset + 6, NegotiateContextCount);
            LittleEndianWriter.WriteGuid(buffer, offset + 8, ServerGuid);
            LittleEndianWriter.WriteUInt32(buffer, offset + 24, (uint)Capabilities);
            LittleEndianWriter.WriteUInt32(buffer, offset + 28, MaxTransactSize);
            LittleEndianWriter.WriteUInt32(buffer, offset + 32, MaxReadSize);
            LittleEndianWriter.WriteUInt32(buffer, offset + 36, MaxWriteSize);
            LittleEndianWriter.WriteInt64(buffer, offset + 40, SystemTime.ToFileTimeUtc());
            LittleEndianWriter.WriteInt64(buffer, offset + 48, ServerStartTime.ToFileTimeUtc());
            LittleEndianWriter.WriteUInt16(buffer, offset + 56, SecurityBufferOffset);
            LittleEndianWriter.WriteUInt16(buffer, offset + 58, SecurityBufferLength);
            LittleEndianWriter.WriteUInt32(buffer, offset + 60, NegotiateContextOffset);
            ByteWriter.WriteBytes(buffer, offset + FixedSize, SecurityBuffer);
            NegotiateContext.WriteNegotiateContextList(buffer, offset + FixedSize + paddedSecurityBufferLength, NegotiateContextList);
        }
예제 #2
0
 public static void WriteNegotiateContextList(byte[] buffer, int offset, List <NegotiateContext> negotiateContextList)
 {
     // Subsequent negotiate contexts MUST appear at the first 8-byte aligned offset following the previous negotiate context
     for (int index = 0; index < negotiateContextList.Count; index++)
     {
         NegotiateContext context = negotiateContextList[index];
         int length       = context.Length;
         int paddedLength = (int)Math.Ceiling((double)length / 8) * 8;
         context.WriteBytes(buffer, offset);
         offset += paddedLength;
     }
 }
예제 #3
0
        public static List <NegotiateContext> ReadNegotiateContextList(byte[] buffer, int offset, int count)
        {
            List <NegotiateContext> result = new List <NegotiateContext>();

            for (int index = 0; index < count; index++)
            {
                NegotiateContext context = new NegotiateContext(buffer, offset);
                result.Add(context);
                offset += context.Length;
            }
            return(result);
        }
예제 #4
0
 public NegotiateResponse(byte[] buffer, int offset) : base(buffer, offset)
 {
     StructureSize          = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
     SecurityMode           = (SecurityMode)LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
     DialectRevision        = (SMB2Dialect)LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 4);
     NegotiateContextCount  = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 6);
     ServerGuid             = LittleEndianConverter.ToGuid(buffer, offset + SMB2Header.Length + 8);
     Capabilities           = (Capabilities)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 24);
     MaxTransactSize        = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 28);
     MaxReadSize            = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 32);
     MaxWriteSize           = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 36);
     SystemTime             = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 40));
     ServerStartTime        = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 48));
     SecurityBufferOffset   = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 56);
     SecurityBufferLength   = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 58);
     NegotiateContextOffset = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 60);
     SecurityBuffer         = ByteReader.ReadBytes(buffer, offset + SecurityBufferOffset, SecurityBufferLength);
     NegotiateContextList   = NegotiateContext.ReadNegotiateContextList(buffer, (int)NegotiateContextOffset, NegotiateContextCount);
 }
예제 #5
0
        public static int GetNegotiateContextListLength(List <NegotiateContext> negotiateContextList)
        {
            int result = 0;

            for (int index = 0; index < negotiateContextList.Count; index++)
            {
                NegotiateContext context = negotiateContextList[index];
                int length = context.Length;
                if (index < negotiateContextList.Count - 1)
                {
                    int paddedLength = (int)Math.Ceiling((double)length / 8) * 8;
                    result += paddedLength;
                }
                else
                {
                    result += length;
                }
            }
            return(result);
        }