Пример #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 byte[] GetBytes()
 {
     byte[] buffer = new byte[Length];
     LittleEndianWriter.WriteGuid(buffer, 0, ObjectId);
     LittleEndianWriter.WriteGuid(buffer, 16, BirthVolumeId);
     LittleEndianWriter.WriteGuid(buffer, 32, BirthObjectId);
     LittleEndianWriter.WriteGuid(buffer, 48, DomainId);
     return(buffer);
 }
Пример #3
0
 public void WriteBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteGuid(buffer, offset + 0, PartitionTypeGuid);
     LittleEndianWriter.WriteGuid(buffer, offset + 16, PartitionGuid);
     LittleEndianWriter.WriteUInt64(buffer, offset + 32, FirstLBA);
     LittleEndianWriter.WriteUInt64(buffer, offset + 40, LastLBA);
     LittleEndianWriter.WriteUInt64(buffer, offset + 48, AttributeFlags);
     while (PartitionName.Length < 36)
     {
         PartitionName += "\0";
     }
     ByteWriter.WriteUTF16String(buffer, offset + 56, PartitionName, 36);
 }
Пример #4
0
        public override void WriteCommandBytes(byte[] buffer, int offset)
        {
            LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
            LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Dialects.Count);
            LittleEndianWriter.WriteUInt16(buffer, offset + 4, (ushort)SecurityMode);
            LittleEndianWriter.WriteUInt16(buffer, offset + 6, Reserved);
            LittleEndianWriter.WriteUInt32(buffer, offset + 8, (uint)Capabilities);
            LittleEndianWriter.WriteGuid(buffer, offset + 12, ClientGuid);
            LittleEndianWriter.WriteInt64(buffer, offset + 28, ClientStartTime.ToFileTimeUtc());

            for (int index = 0; index < Dialects.Count; index++)
            {
                SMB2Dialect dialect = Dialects[index];
                LittleEndianWriter.WriteUInt16(buffer, offset + 36 + index * 2, (ushort)dialect);
            }
        }
Пример #5
0
        public override byte[] GetBytes()
        {
            AuthLength = (ushort)AuthVerifier.Length;
            byte[] buffer = new byte[Length];
            WriteCommonFieldsBytes(buffer);
            int offset = CommonFieldsLength;

            LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationHint);
            LittleEndianWriter.WriteUInt16(buffer, ref offset, ContextID);
            LittleEndianWriter.WriteUInt16(buffer, ref offset, OpNum);
            if ((Flags & PacketFlags.ObjectUUID) > 0)
            {
                LittleEndianWriter.WriteGuid(buffer, ref offset, ObjectGuid);
            }
            ByteWriter.WriteBytes(buffer, ref offset, Data);
            ByteWriter.WriteBytes(buffer, ref offset, AuthVerifier);
            return(buffer);
        }
Пример #6
0
        public byte[] GetBytes(int bytesPerSector)
        {
            byte[] buffer = new byte[bytesPerSector];
            ByteWriter.WriteAnsiString(buffer, 0, Signature, 8);
            LittleEndianWriter.WriteUInt32(buffer, 8, Revision);
            LittleEndianWriter.WriteUInt32(buffer, 12, HeaderSize);
            LittleEndianWriter.WriteUInt64(buffer, 24, CurrentLBA);
            LittleEndianWriter.WriteUInt64(buffer, 32, BackupLBA);
            LittleEndianWriter.WriteUInt64(buffer, 40, FirstUsableLBA);
            LittleEndianWriter.WriteUInt64(buffer, 48, LastUsableLBA);
            LittleEndianWriter.WriteGuid(buffer, 56, DiskGuid);
            LittleEndianWriter.WriteUInt64(buffer, 72, PartitionEntriesLBA);
            LittleEndianWriter.WriteUInt32(buffer, 80, NumberOfPartitionEntries);
            LittleEndianWriter.WriteUInt32(buffer, 84, SizeOfPartitionEntry);
            LittleEndianWriter.WriteUInt32(buffer, 88, PartitionArrayCRC32);

            CRC32 = ComputeCRC32(buffer);
            LittleEndianWriter.WriteUInt32(buffer, 16, CRC32);

            return(buffer);
        }
Пример #7
0
        public override byte[] GetBytes(bool isUnicode)
        {
            ChallengeLength = 0;

            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, DialectIndex);
            ByteWriter.WriteByte(this.SMBParameters, 2, (byte)SecurityMode);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 3, MaxMpxCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 5, MaxNumberVcs);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 7, MaxBufferSize);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 11, MaxRawSize);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 15, SessionKey);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 19, (uint)Capabilities);
            FileTimeHelper.WriteFileTime(this.SMBParameters, 23, SystemTime);
            LittleEndianWriter.WriteInt16(this.SMBParameters, 31, ServerTimeZone);
            ByteWriter.WriteByte(this.SMBParameters, 33, ChallengeLength);

            this.SMBData = new byte[16 + SecurityBlob.Length];
            LittleEndianWriter.WriteGuid(this.SMBData, 0, ServerGuid);
            ByteWriter.WriteBytes(this.SMBData, 16, SecurityBlob);

            return(base.GetBytes(isUnicode));
        }
        public override byte[] GetBytes(bool isUnicode)
        {
            SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            ByteWriter.WriteByte(SMBParameters, ref parametersOffset, (byte)OpLockLevel);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, FID);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, (uint)CreateDisposition);
            FileTimeHelper.WriteFileTime(SMBParameters, ref parametersOffset, CreateTime);
            FileTimeHelper.WriteFileTime(SMBParameters, ref parametersOffset, LastAccessTime);
            FileTimeHelper.WriteFileTime(SMBParameters, ref parametersOffset, LastWriteTime);
            FileTimeHelper.WriteFileTime(SMBParameters, ref parametersOffset, LastChangeTime);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, (uint)ExtFileAttributes);
            LittleEndianWriter.WriteInt64(SMBParameters, ref parametersOffset, AllocationSize);
            LittleEndianWriter.WriteInt64(SMBParameters, ref parametersOffset, EndOfFile);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, (ushort)ResourceType);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, NMPipeStatus_or_FileStatusFlags);
            ByteWriter.WriteByte(SMBParameters, ref parametersOffset, Convert.ToByte(Directory));
            LittleEndianWriter.WriteGuid(SMBParameters, ref parametersOffset, VolumeGuid);
            LittleEndianWriter.WriteUInt64(SMBParameters, ref parametersOffset, FileID);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, (uint)MaximalAccessRights);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, (uint)GuestMaximalAccessRights);
            return(base.GetBytes(isUnicode));
        }
Пример #9
0
 public void WriteBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteGuid(buffer, offset + 0, InterfaceUUID);
     LittleEndianWriter.WriteUInt32(buffer, offset + 16, InterfaceVersion);
 }
 public override void WriteBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteGuid(buffer, offset + 0, ObjectID);
     ByteWriter.WriteBytes(buffer, offset + 16, ExtendedInfo);
 }