mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-14 21:35:04 +02:00
Added SMB2TransformHeader implementation
This commit is contained in:
parent
a5555a43ab
commit
cdd3d182b5
3 changed files with 69 additions and 0 deletions
10
SMBLibrary/SMB2/Enums/SMB2TransformHeaderFlags.cs
Normal file
10
SMBLibrary/SMB2/Enums/SMB2TransformHeaderFlags.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB2
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum SMB2TransformHeaderFlags : ushort
|
||||||
|
{
|
||||||
|
Encrypted = 0x0001,
|
||||||
|
}
|
||||||
|
}
|
57
SMBLibrary/SMB2/SMB2TransformHeader.cs
Normal file
57
SMBLibrary/SMB2/SMB2TransformHeader.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* Copyright (C) 2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
|
*
|
||||||
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using Utilities;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB2
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used by the client or server when sending encrypted messages. only valid for the SMB 3.x dialect family.
|
||||||
|
/// </summary>
|
||||||
|
public class SMB2TransformHeader
|
||||||
|
{
|
||||||
|
public const int Length = 52;
|
||||||
|
public const int SignatureOffset = 4;
|
||||||
|
|
||||||
|
public static readonly byte[] ProtocolSignature = new byte[] { 0xFD, 0x53, 0x4D, 0x42 };
|
||||||
|
|
||||||
|
private byte[] ProtocolId; // 4 bytes, 0xFD followed by "SMB"
|
||||||
|
public byte[] Signature; // 16 bytes
|
||||||
|
public byte[] Nonce; // 16 bytes
|
||||||
|
public uint OriginalMessageSize;
|
||||||
|
public ushort Reserved;
|
||||||
|
public SMB2TransformHeaderFlags Flags; // EncryptionAlgorithm in SMB 3.0 / 3.0.2 where the only possible value is SMB2_ENCRYPTION_AES128_CCM = 0x0001
|
||||||
|
public ulong SessionId;
|
||||||
|
|
||||||
|
public SMB2TransformHeader()
|
||||||
|
{
|
||||||
|
ProtocolId = ProtocolSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SMB2TransformHeader(byte[] buffer, int offset)
|
||||||
|
{
|
||||||
|
ProtocolId = ByteReader.ReadBytes(buffer, offset + 0, 4);
|
||||||
|
Signature = ByteReader.ReadBytes(buffer, offset + 4, 16);
|
||||||
|
Nonce = ByteReader.ReadBytes(buffer, offset + 20, 16);
|
||||||
|
OriginalMessageSize = LittleEndianConverter.ToUInt32(buffer, offset + 36);
|
||||||
|
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 40);
|
||||||
|
Flags = (SMB2TransformHeaderFlags)LittleEndianConverter.ToUInt16(buffer, offset + 42);
|
||||||
|
SessionId = LittleEndianConverter.ToUInt64(buffer, offset + 44);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBytes(byte[] buffer, int offset)
|
||||||
|
{
|
||||||
|
ByteWriter.WriteBytes(buffer, offset + 0, ProtocolId);
|
||||||
|
ByteWriter.WriteBytes(buffer, offset + 4, Signature);
|
||||||
|
ByteWriter.WriteBytes(buffer, offset + 20, Nonce);
|
||||||
|
LittleEndianWriter.WriteUInt32(buffer, offset + 36, OriginalMessageSize);
|
||||||
|
LittleEndianWriter.WriteUInt16(buffer, offset + 40, Reserved);
|
||||||
|
LittleEndianWriter.WriteUInt16(buffer, offset + 42, (ushort)Flags);
|
||||||
|
LittleEndianWriter.WriteUInt64(buffer, offset + 44, SessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -575,11 +575,13 @@
|
||||||
<Compile Include="SMB2\Enums\SessionSetup\SessionSetupFlags.cs" />
|
<Compile Include="SMB2\Enums\SessionSetup\SessionSetupFlags.cs" />
|
||||||
<Compile Include="SMB2\Enums\SMB2CommandName.cs" />
|
<Compile Include="SMB2\Enums\SMB2CommandName.cs" />
|
||||||
<Compile Include="SMB2\Enums\SMB2PacketHeaderFlags.cs" />
|
<Compile Include="SMB2\Enums\SMB2PacketHeaderFlags.cs" />
|
||||||
|
<Compile Include="SMB2\Enums\SMB2TransformHeaderFlags.cs" />
|
||||||
<Compile Include="SMB2\Enums\TreeConnect\ShareCapabilities.cs" />
|
<Compile Include="SMB2\Enums\TreeConnect\ShareCapabilities.cs" />
|
||||||
<Compile Include="SMB2\Enums\TreeConnect\ShareFlags.cs" />
|
<Compile Include="SMB2\Enums\TreeConnect\ShareFlags.cs" />
|
||||||
<Compile Include="SMB2\Enums\TreeConnect\ShareType.cs" />
|
<Compile Include="SMB2\Enums\TreeConnect\ShareType.cs" />
|
||||||
<Compile Include="SMB2\Enums\Write\WriteFlags.cs" />
|
<Compile Include="SMB2\Enums\Write\WriteFlags.cs" />
|
||||||
<Compile Include="SMB2\SMB2Header.cs" />
|
<Compile Include="SMB2\SMB2Header.cs" />
|
||||||
|
<Compile Include="SMB2\SMB2TransformHeader.cs" />
|
||||||
<Compile Include="SMB2\Structures\CreateContext.cs" />
|
<Compile Include="SMB2\Structures\CreateContext.cs" />
|
||||||
<Compile Include="SMB2\Structures\Enums\LockFlags.cs" />
|
<Compile Include="SMB2\Structures\Enums\LockFlags.cs" />
|
||||||
<Compile Include="SMB2\Structures\FileID.cs" />
|
<Compile Include="SMB2\Structures\FileID.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue