Exemple #1
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)OptionalSupport);
            MaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            GuestMaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);

            // Should be written as OEM string but it doesn't really matter
            string serviceString = TreeConnectHelper.GetServiceString(Service);

            if (isUnicode)
            {
                this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length * 2 + 3];
            }
            else
            {
                this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length + 2];
            }

            int offset = 0;

            ByteWriter.WriteNullTerminatedAnsiString(this.SMBData, ref offset, serviceString);
            SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeFileSystem);

            return(base.GetBytes(isUnicode));
        }
        public override void WriteCommandBytes(byte[] buffer, int offset)
        {
            NameOffset = 0;
            NameLength = (ushort)(Name.Length * 2);
            if (Name.Length > 0)
            {
                NameOffset = SMB2Header.Length + FixedLength;
            }
            CreateContextsOffsets = 0;
            CreateContextsLength  = 0;
            int paddedNameLength = (int)Math.Ceiling((double)(Name.Length * 2) / 8) * 8;

            if (CreateContexts.Count > 0)
            {
                CreateContextsOffsets = (uint)(SMB2Header.Length + 56 + paddedNameLength);
                CreateContextsLength  = (uint)CreateContext.GetCreateContextListLength(CreateContexts);
            }
            LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
            ByteWriter.WriteByte(buffer, offset + 2, SecurityFlags);
            ByteWriter.WriteByte(buffer, offset + 3, (byte)RequestedOplockLevel);
            LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)ImpersonationLevel);
            LittleEndianWriter.WriteUInt64(buffer, offset + 8, (ulong)SmbCreateFlags);
            LittleEndianWriter.WriteUInt64(buffer, offset + 16, (ulong)Reserved);
            DesiredAccess.WriteBytes(buffer, offset + 24);
            LittleEndianWriter.WriteUInt32(buffer, offset + 28, (uint)FileAttributes);
            LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)ShareAccess);
            LittleEndianWriter.WriteUInt32(buffer, offset + 36, (uint)CreateDisposition);
            LittleEndianWriter.WriteUInt32(buffer, offset + 40, (uint)CreateOptions);
            LittleEndianWriter.WriteUInt16(buffer, offset + 44, NameOffset);
            LittleEndianWriter.WriteUInt16(buffer, offset + 46, NameLength);
            LittleEndianWriter.WriteUInt32(buffer, offset + 48, CreateContextsOffsets);
            LittleEndianWriter.WriteUInt32(buffer, offset + 52, CreateContextsLength);
            ByteWriter.WriteUTF16String(buffer, offset + 56, Name);
            CreateContext.WriteCreateContextList(buffer, offset + 56 + paddedNameLength, CreateContexts);
        }
Exemple #3
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     ByteWriter.WriteByte(buffer, offset + 2, (byte)ShareType);
     ByteWriter.WriteByte(buffer, offset + 3, Reserved);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)ShareFlags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 8, (uint)Capabilities);
     MaximalAccess.WriteBytes(buffer, offset + 12);
 }
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)FileAttrs);
            UTimeHelper.WriteUTime(this.SMBParameters, ref parametersOffset, LastWriteTime);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, FileDataSize);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)AccessRights);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType);
            NMPipeStatus.WriteBytes(this.SMBParameters, ref parametersOffset);
            OpenResults.WriteBytes(this.SMBParameters, ref parametersOffset);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, ServerFID);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, Reserved);
            MaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            GuestMaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            return(base.GetBytes(isUnicode));
        }
Exemple #5
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, (byte)OpLockLevel);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)CreateDisposition);
            FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, CreateTime);
            FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastAccessTime);
            FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastWriteTime);
            FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastChangeTime);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)ExtFileAttributes);
            LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, AllocationSize);
            LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, EndOfFile);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, NMPipeStatus_or_FileStatusFlags);
            ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, Convert.ToByte(Directory));
            LittleEndianWriter.WriteGuidBytes(this.SMBParameters, ref parametersOffset, VolumeGuid);
            LittleEndianWriter.WriteUInt64(this.SMBParameters, ref parametersOffset, FileID);
            MaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            GuestMaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            return(base.GetBytes(isUnicode));
        }