123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Utilities;
- namespace SMBLibrary.SMB1
- {
-
-
-
- public class NegotiateResponse : SMB1Command
- {
- public const int ParametersLength = 34;
-
- public ushort DialectIndex;
- public SecurityMode SecurityMode;
- public ushort MaxMpxCount;
- public ushort MaxNumberVcs;
- public uint MaxBufferSize;
- public uint MaxRawSize;
- public uint SessionKey;
- public Capabilities Capabilities;
- public DateTime SystemTime;
- public short ServerTimeZone;
- private byte ChallengeLength;
-
- public byte[] Challenge;
- public string DomainName;
- public string ServerName;
- public NegotiateResponse() : base()
- {
- Challenge = new byte[0];
- DomainName = String.Empty;
- ServerName = String.Empty;
- }
- public NegotiateResponse(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
- {
- DialectIndex = LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
- SecurityMode = (SecurityMode)ByteReader.ReadByte(this.SMBParameters, 2);
- MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 3);
- MaxNumberVcs = LittleEndianConverter.ToUInt16(this.SMBParameters, 5);
- MaxBufferSize = LittleEndianConverter.ToUInt32(this.SMBParameters, 7);
- MaxRawSize = LittleEndianConverter.ToUInt32(this.SMBParameters, 11);
- SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 15);
- Capabilities = (Capabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 19);
- SystemTime = FileTimeHelper.ReadFileTime(this.SMBParameters, 23);
- ServerTimeZone = LittleEndianConverter.ToInt16(this.SMBParameters, 31);
- ChallengeLength = ByteReader.ReadByte(this.SMBParameters, 33);
- int dataOffset = 0;
- Challenge = ByteReader.ReadBytes(this.SMBData, ref dataOffset, ChallengeLength);
-
-
- DomainName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, true);
- ServerName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, true);
- }
- public override byte[] GetBytes(bool isUnicode)
- {
- ChallengeLength = (byte)this.Challenge.Length;
- 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[Challenge.Length + (DomainName.Length + 1) * 2 + (ServerName.Length + 1) * 2];
- int offset = 0;
- ByteWriter.WriteBytes(this.SMBData, ref offset, Challenge);
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, true, DomainName);
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, true, ServerName);
- return base.GetBytes(isUnicode);
- }
- public override CommandName CommandName
- {
- get
- {
- return CommandName.SMB_COM_NEGOTIATE;
- }
- }
- }
- }
|