mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-04-30 18:57:48 +02:00
NTLMv2ClientChallenge: Renamed variables, exposed reserved fields
This commit is contained in:
parent
efc8c683ea
commit
f6feaced77
1 changed files with 25 additions and 19 deletions
|
@ -16,25 +16,27 @@ namespace SMBLibrary.Authentication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class NTLMv2ClientChallenge
|
public class NTLMv2ClientChallenge
|
||||||
{
|
{
|
||||||
|
public const byte StructureVersion = 0x01;
|
||||||
public static readonly DateTime EpochTime = DateTime.FromFileTimeUtc(0);
|
public static readonly DateTime EpochTime = DateTime.FromFileTimeUtc(0);
|
||||||
|
|
||||||
public byte ResponseVersion;
|
public byte CurrentVersion;
|
||||||
public byte ResponseVersionHigh;
|
public byte MaximumSupportedVersion;
|
||||||
// 6 zero bytes
|
public ushort Reserved1;
|
||||||
public DateTime Time;
|
public uint Reserved2;
|
||||||
// 4 zero bytes
|
public DateTime TimeStamp;
|
||||||
public byte[] ClientChallenge; // 8-byte challenge message generated by the client
|
public uint Reserved3;
|
||||||
|
public byte[] ClientChallenge; // 8-byte challenge generated by the client
|
||||||
public KeyValuePairList<AVPairKey, byte[]> AVPairs;
|
public KeyValuePairList<AVPairKey, byte[]> AVPairs;
|
||||||
|
|
||||||
public NTLMv2ClientChallenge()
|
public NTLMv2ClientChallenge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public NTLMv2ClientChallenge(DateTime time, byte[] clientChallenge, string domainName, string computerName)
|
public NTLMv2ClientChallenge(DateTime timeStamp, byte[] clientChallenge, string domainName, string computerName)
|
||||||
{
|
{
|
||||||
ResponseVersion = 1;
|
CurrentVersion = StructureVersion;
|
||||||
ResponseVersionHigh = 1;
|
MaximumSupportedVersion = StructureVersion;
|
||||||
Time = time;
|
TimeStamp = timeStamp;
|
||||||
ClientChallenge = clientChallenge;
|
ClientChallenge = clientChallenge;
|
||||||
AVPairs = new KeyValuePairList<AVPairKey, byte[]>();
|
AVPairs = new KeyValuePairList<AVPairKey, byte[]>();
|
||||||
AVPairs.Add(AVPairKey.NbDomainName, UnicodeEncoding.Unicode.GetBytes(domainName));
|
AVPairs.Add(AVPairKey.NbDomainName, UnicodeEncoding.Unicode.GetBytes(domainName));
|
||||||
|
@ -47,24 +49,28 @@ namespace SMBLibrary.Authentication
|
||||||
|
|
||||||
public NTLMv2ClientChallenge(byte[] buffer, int offset)
|
public NTLMv2ClientChallenge(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
ResponseVersion = ByteReader.ReadByte(buffer, offset + 0);
|
CurrentVersion = ByteReader.ReadByte(buffer, offset + 0);
|
||||||
ResponseVersionHigh = ByteReader.ReadByte(buffer, offset + 1);
|
MaximumSupportedVersion = ByteReader.ReadByte(buffer, offset + 1);
|
||||||
long temp = LittleEndianConverter.ToInt64(buffer, offset + 8);
|
Reserved1 = LittleEndianConverter.ToUInt16(buffer, offset + 2);
|
||||||
Time = DateTime.FromFileTimeUtc(temp);
|
Reserved2 = LittleEndianConverter.ToUInt32(buffer, offset + 4);
|
||||||
|
TimeStamp = FileTimeHelper.ReadFileTime(buffer, offset + 8);
|
||||||
ClientChallenge = ByteReader.ReadBytes(buffer, offset + 16, 8);
|
ClientChallenge = ByteReader.ReadBytes(buffer, offset + 16, 8);
|
||||||
|
Reserved3 = LittleEndianConverter.ToUInt32(buffer, offset + 24);
|
||||||
AVPairs = AVPairUtils.ReadAVPairSequence(buffer, offset + 28);
|
AVPairs = AVPairUtils.ReadAVPairSequence(buffer, offset + 28);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GetBytes()
|
public byte[] GetBytes()
|
||||||
{
|
{
|
||||||
byte[] sequenceBytes = AVPairUtils.GetAVPairSequenceBytes(AVPairs);
|
byte[] sequenceBytes = AVPairUtils.GetAVPairSequenceBytes(AVPairs);
|
||||||
byte[] timeBytes = LittleEndianConverter.GetBytes((ulong)Time.ToFileTimeUtc());
|
|
||||||
|
|
||||||
byte[] buffer = new byte[28 + sequenceBytes.Length];
|
byte[] buffer = new byte[28 + sequenceBytes.Length];
|
||||||
ByteWriter.WriteByte(buffer, 0, ResponseVersion);
|
ByteWriter.WriteByte(buffer, 0, CurrentVersion);
|
||||||
ByteWriter.WriteByte(buffer, 1, ResponseVersionHigh);
|
ByteWriter.WriteByte(buffer, 1, MaximumSupportedVersion);
|
||||||
ByteWriter.WriteBytes(buffer, 8, timeBytes);
|
LittleEndianWriter.WriteUInt16(buffer, 2, Reserved1);
|
||||||
|
LittleEndianWriter.WriteUInt32(buffer, 4, Reserved2);
|
||||||
|
FileTimeHelper.WriteFileTime(buffer, 8, TimeStamp);
|
||||||
ByteWriter.WriteBytes(buffer, 16, ClientChallenge, 8);
|
ByteWriter.WriteBytes(buffer, 16, ClientChallenge, 8);
|
||||||
|
LittleEndianWriter.WriteUInt32(buffer, 24, Reserved3);
|
||||||
ByteWriter.WriteBytes(buffer, 28, sequenceBytes);
|
ByteWriter.WriteBytes(buffer, 28, sequenceBytes);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue