123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Utilities;
- namespace SMBLibrary.SMB1
- {
-
-
-
- public class SessionSetupAndXRequest : SMBAndXCommand
- {
- public const int ParametersLength = 26;
-
- public ushort MaxBufferSize;
- public ushort MaxMpxCount;
- public ushort VcNumber;
- public uint SessionKey;
- private ushort OEMPasswordLength;
- private ushort UnicodePasswordLength;
- public uint Reserved;
- public Capabilities Capabilities;
-
- public byte[] OEMPassword;
- public byte[] UnicodePassword;
-
- public string AccountName;
- public string PrimaryDomain;
- public string NativeOS;
- public string NativeLanMan;
- public SessionSetupAndXRequest(): base()
- {
- AccountName = String.Empty;
- PrimaryDomain = String.Empty;
- NativeOS = String.Empty;
- NativeLanMan = String.Empty;
- }
- public SessionSetupAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
- {
- MaxBufferSize = LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
- MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 6);
- VcNumber = LittleEndianConverter.ToUInt16(this.SMBParameters, 8);
- SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 10);
- OEMPasswordLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 14);
- UnicodePasswordLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 16);
- Reserved = LittleEndianConverter.ToUInt32(this.SMBParameters, 18);
- Capabilities = (Capabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 22);
- OEMPassword = ByteReader.ReadBytes(this.SMBData, 0, OEMPasswordLength);
- UnicodePassword = ByteReader.ReadBytes(this.SMBData, OEMPasswordLength, UnicodePasswordLength);
- int dataOffset = OEMPasswordLength + UnicodePasswordLength;
- if (isUnicode)
- {
-
-
- int padding = (1 + OEMPasswordLength + UnicodePasswordLength) % 2;
- dataOffset += padding;
- }
- AccountName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- PrimaryDomain = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- NativeOS = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- NativeLanMan = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- }
- public override byte[] GetBytes(bool isUnicode)
- {
- Capabilities &= ~Capabilities.ExtendedSecurity;
- OEMPasswordLength = (ushort)OEMPassword.Length;
- UnicodePasswordLength = (ushort)UnicodePassword.Length;
-
- this.SMBParameters = new byte[ParametersLength];
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxBufferSize);
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxMpxCount);
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, VcNumber);
- LittleEndianWriter.WriteUInt32(this.SMBParameters, 10, SessionKey);
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 14, OEMPasswordLength);
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, UnicodePasswordLength);
- LittleEndianWriter.WriteUInt32(this.SMBParameters, 18, Reserved);
- LittleEndianWriter.WriteUInt32(this.SMBParameters, 22, (uint)Capabilities);
- int padding = 0;
- if (isUnicode)
- {
-
-
- padding = (1 + OEMPasswordLength + UnicodePasswordLength) % 2;
- this.SMBData = new byte[OEMPassword.Length + UnicodePassword.Length + padding + (AccountName.Length + 1) * 2 + (PrimaryDomain.Length + 1) * 2 + (NativeOS.Length + 1) * 2 + (NativeLanMan.Length + 1) * 2];
- }
- else
- {
- this.SMBData = new byte[OEMPassword.Length + UnicodePassword.Length + AccountName.Length + 1 + PrimaryDomain.Length + 1 + NativeOS.Length + 1 + NativeLanMan.Length + 1];
- }
- int offset = 0;
- ByteWriter.WriteBytes(this.SMBData, ref offset, OEMPassword);
- ByteWriter.WriteBytes(this.SMBData, ref offset, UnicodePassword);
- offset += padding;
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, AccountName);
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain);
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS);
- SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan);
- return base.GetBytes(isUnicode);
- }
- public override CommandName CommandName
- {
- get
- {
- return CommandName.SMB_COM_SESSION_SETUP_ANDX;
- }
- }
- }
- }
|