public void NoPropertiesOutput () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); // no out! AssertNull ("Password", ntlm.Password); AssertNull ("Challenge", ntlm.Challenge); }
public void NoPropertiesOutput () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); // no out! Assert.IsNull (ntlm.Password, "Password"); Assert.IsNull (ntlm.Challenge, "Challenge"); }
// Example from http://www.innovation.ch/java/ntlm.html public void BeeblebroxSrvNonce () { byte[] SrvNonce = Encoding.ASCII.GetBytes ("SrvNonce"); using (ChallengeResponse ntlm = new ChallengeResponse ("Beeblebrox", SrvNonce)) { Assert.AreEqual ("E0-E0-0D-E3-10-4A-1B-F2-05-3F-07-C7-DD-A8-2D-3C-48-9A-E9-89-E1-B0-00-D3", BitConverter.ToString (ntlm.NT), "NT"); Assert.AreEqual ("AD-87-CA-6D-EF-E3-46-85-B9-C4-3C-47-7A-8C-42-D6-00-66-7D-68-92-E7-E8-97", BitConverter.ToString (ntlm.LM), "LM"); } }
// Example from http://packetstormsecurity.nl/Crackers/NT/l0phtcrack/l0phtcrack2.5-readme.html public void L0phtCrack () { byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; using (ChallengeResponse ntlm = new ChallengeResponse ("WELCOME", SrvNonce)) { Assert.AreEqual ("7A-CE-90-85-AB-CC-37-59-38-0B-1C-68-62-E3-98-C3-C0-EF-9C-FC-22-E8-A2-C2", BitConverter.ToString (ntlm.NT), "NT"); Assert.AreEqual ("CA-12-00-72-3C-41-D5-77-AB-18-C7-64-C6-DE-F3-4F-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM"); } }
public void NullPassword () { byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; using (ChallengeResponse ntlm = new ChallengeResponse (null, SrvNonce)) { Assert.AreEqual ("4A-FD-81-EC-01-87-E8-8D-97-77-8D-F7-93-C6-DA-D4-F0-3A-36-63-66-9D-20-1C", BitConverter.ToString (ntlm.NT), "NT"); // note the last 8 bytes... they are the same as the previous unit test ;-) Assert.AreEqual ("0A-39-2B-11-CF-05-2B-02-6D-65-CF-F5-68-BD-E4-15-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM"); } }
public void EmptyPassword () { byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; using (ChallengeResponse ntlm = new ChallengeResponse (String.Empty, SrvNonce)) { // same as the previous one as this is the same (null/empty) password expressed diffently Assert.AreEqual ("4A-FD-81-EC-01-87-E8-8D-97-77-8D-F7-93-C6-DA-D4-F0-3A-36-63-66-9D-20-1C", BitConverter.ToString (ntlm.NT), "NT"); Assert.AreEqual ("0A-39-2B-11-CF-05-2B-02-6D-65-CF-F5-68-BD-E4-15-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM"); } }
public override byte[] GetBytes() { byte[] domain = Encoding.Unicode.GetBytes (_domain.ToUpper (CultureInfo.InvariantCulture)); byte[] user = Encoding.Unicode.GetBytes (_username); byte[] host = Encoding.Unicode.GetBytes (_host.ToUpper (CultureInfo.InvariantCulture)); byte[] data = PrepareMessage (64 + domain.Length + user.Length + host.Length + 24 + 24); // LM response short lmresp_off = (short)(64 + domain.Length + user.Length + host.Length); data [12] = (byte) 0x18; data [13] = (byte) 0x00; data [14] = (byte) 0x18; data [15] = (byte) 0x00; data [16] = (byte) lmresp_off; data [17] = (byte)(lmresp_off >> 8); // NT response short ntresp_off = (short)(lmresp_off + 24); data [20] = (byte) 0x18; data [21] = (byte) 0x00; data [22] = (byte) 0x18; data [23] = (byte) 0x00; data [24] = (byte) ntresp_off; data [25] = (byte)(ntresp_off >> 8); // domain short dom_len = (short)domain.Length; short dom_off = 64; data [28] = (byte) dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte) dom_off; data [33] = (byte)(dom_off >> 8); // username short uname_len = (short)user.Length; short uname_off = (short)(dom_off + dom_len); data [36] = (byte) uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte) uname_off; data [41] = (byte)(uname_off >> 8); // host short host_len = (short)host.Length; short host_off = (short)(uname_off + uname_len); data [44] = (byte) host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte) host_off; data [49] = (byte)(host_off >> 8); // message length short msg_len = (short)data.Length; data [56] = (byte) msg_len; data [57] = (byte)(msg_len >> 8); // options flags data [60] = (byte) Flags; data [61] = (byte)((uint)Flags >> 8); data [62] = (byte)((uint)Flags >> 16); data [63] = (byte)((uint)Flags >> 24); Buffer.BlockCopy (domain, 0, data, dom_off, domain.Length); Buffer.BlockCopy (user, 0, data, uname_off, user.Length); Buffer.BlockCopy (host, 0, data, host_off, host.Length); using (ChallengeResponse ntlm = new ChallengeResponse (_password, _challenge)) { Buffer.BlockCopy (ntlm.LM, 0, data, lmresp_off, 24); Buffer.BlockCopy (ntlm.NT, 0, data, ntresp_off, 24); } return data; }
public override byte[] GetBytes () { byte[] domain = Encoding.Unicode.GetBytes (_domain.ToUpper (CultureInfo.InvariantCulture)); byte[] user = Encoding.Unicode.GetBytes (_username); byte[] host = Encoding.Unicode.GetBytes (_host.ToUpper (CultureInfo.InvariantCulture)); int fixed_size = Version == NtlmVersion.Version3 ? 72 : 64; short skey_len = (short) (Version != NtlmVersion.Version1 ? 16 : 0); int skey_off = 0; byte[] data = PrepareMessage (fixed_size + domain.Length + user.Length + host.Length + 24 + 24 + skey_len); // LM response int lmresp_off = fixed_size + domain.Length + user.Length + host.Length; data [12] = (byte) 0x18; data [13] = (byte) 0x00; data [14] = (byte) 0x18; data [15] = (byte) 0x00; data [16] = (byte) lmresp_off; data [17] = (byte)(lmresp_off >> 8); data [18] = (byte)(lmresp_off >> 16); data [19] = (byte)(lmresp_off >> 24); // NT response int ntresp_off = lmresp_off + 24; data [20] = (byte) 0x18; data [21] = (byte) 0x00; data [22] = (byte) 0x18; data [23] = (byte) 0x00; data [24] = (byte) ntresp_off; data [25] = (byte)(ntresp_off >> 8); data [26] = (byte)(ntresp_off >> 16); data [27] = (byte)(ntresp_off >> 24); // domain short dom_len = (short)domain.Length; int dom_off = (short)fixed_size; data [28] = (byte) dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte) dom_off; data [33] = (byte)(dom_off >> 8); data [34] = (byte)(dom_off >> 16); data [35] = (byte)(dom_off >> 24); // username short uname_len = (short)user.Length; int uname_off = dom_off + dom_len; data [36] = (byte) uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte) uname_off; data [41] = (byte)(uname_off >> 8); data [42] = (byte)(uname_off >> 16); data [43] = (byte)(uname_off >> 24); // host short host_len = (short)host.Length; int host_off = uname_off + uname_len; data [44] = (byte) host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte) host_off; data [49] = (byte)(host_off >> 8); data [50] = (byte)(host_off >> 16); data [51] = (byte)(host_off >> 24); // session key // FIXME: This Version condition is introduced to make // nunit tests pass, and hence not based on the NTLM // analysis docs. Find out the reason why it is needed. if (Version != NtlmVersion.Version1) { skey_off = (short)(data.Length - skey_len); data [52] = (byte) skey_len; data [53] = (byte)(skey_len >> 8); data [54] = data [52]; data [55] = data [53]; data [56] = (byte) skey_off; data [57] = (byte)(skey_off >> 8); data [58] = (byte)(skey_off >> 16); data [59] = (byte)(skey_off >> 24); } else { // message length short msg_len = (short)data.Length; data [56] = (byte) msg_len; data [57] = (byte)(msg_len >> 8); } // options flags data [60] = (byte) Flags; data [61] = (byte)((uint)Flags >> 8); data [62] = (byte)((uint)Flags >> 16); data [63] = (byte)((uint)Flags >> 24); // osversion if (Version == NtlmVersion.Version3) Buffer.BlockCopy (OSVersion, 0, data, 64, OSVersion.Length); Buffer.BlockCopy (domain, 0, data, dom_off, domain.Length); Buffer.BlockCopy (user, 0, data, uname_off, user.Length); Buffer.BlockCopy (host, 0, data, host_off, host.Length); using (ChallengeResponse ntlm = new ChallengeResponse (_password, _challenge)) { Buffer.BlockCopy (ntlm.LM, 0, data, lmresp_off, 24); Buffer.BlockCopy (ntlm.NT, 0, data, ntresp_off, 24); if (Version != NtlmVersion.Version1) // session key Buffer.BlockCopy (ntlm.LMSessionKey, 0, data, skey_off, 16); } return data; }
public void Challenge_Disposed () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); ntlm.Dispose (); ntlm.Challenge = new byte [8]; }
public void Password_Disposed () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); ntlm.Dispose (); ntlm.Password = "******"; }
public void Challenge_Null () { ChallengeResponse ntlm = new ChallengeResponse (); ntlm.Challenge = null; }
public override byte[] GetBytes() { byte[] domain = Encoding.Unicode.GetBytes(_domain.ToUpper(CultureInfo.InvariantCulture)); byte[] user = Encoding.Unicode.GetBytes(_username); byte[] host = Encoding.Unicode.GetBytes(_host.ToUpper(CultureInfo.InvariantCulture)); int fixed_size = Version == NtlmVersion.Version3 ? 72 : 64; short skey_len = (short)(Version != NtlmVersion.Version1 ? 16 : 0); int skey_off = 0; byte[] data = PrepareMessage(fixed_size + domain.Length + user.Length + host.Length + 24 + 24 + skey_len); // LM response int lmresp_off = fixed_size + domain.Length + user.Length + host.Length; data [12] = (byte)0x18; data [13] = (byte)0x00; data [14] = (byte)0x18; data [15] = (byte)0x00; data [16] = (byte)lmresp_off; data [17] = (byte)(lmresp_off >> 8); data [18] = (byte)(lmresp_off >> 16); data [19] = (byte)(lmresp_off >> 24); // NT response int ntresp_off = lmresp_off + 24; data [20] = (byte)0x18; data [21] = (byte)0x00; data [22] = (byte)0x18; data [23] = (byte)0x00; data [24] = (byte)ntresp_off; data [25] = (byte)(ntresp_off >> 8); data [26] = (byte)(ntresp_off >> 16); data [27] = (byte)(ntresp_off >> 24); // domain short dom_len = (short)domain.Length; int dom_off = (short)fixed_size; data [28] = (byte)dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte)dom_off; data [33] = (byte)(dom_off >> 8); data [34] = (byte)(dom_off >> 16); data [35] = (byte)(dom_off >> 24); // username short uname_len = (short)user.Length; int uname_off = dom_off + dom_len; data [36] = (byte)uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte)uname_off; data [41] = (byte)(uname_off >> 8); data [42] = (byte)(uname_off >> 16); data [43] = (byte)(uname_off >> 24); // host short host_len = (short)host.Length; int host_off = uname_off + uname_len; data [44] = (byte)host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte)host_off; data [49] = (byte)(host_off >> 8); data [50] = (byte)(host_off >> 16); data [51] = (byte)(host_off >> 24); // session key // FIXME: This Version condition is introduced to make // nunit tests pass, and hence not based on the NTLM // analysis docs. Find out the reason why it is needed. if (Version != NtlmVersion.Version1) { skey_off = (short)(data.Length - skey_len); data [52] = (byte)skey_len; data [53] = (byte)(skey_len >> 8); data [54] = data [52]; data [55] = data [53]; data [56] = (byte)skey_off; data [57] = (byte)(skey_off >> 8); data [58] = (byte)(skey_off >> 16); data [59] = (byte)(skey_off >> 24); } else { // message length short msg_len = (short)data.Length; data [56] = (byte)msg_len; data [57] = (byte)(msg_len >> 8); } // options flags data [60] = (byte)Flags; data [61] = (byte)((uint)Flags >> 8); data [62] = (byte)((uint)Flags >> 16); data [63] = (byte)((uint)Flags >> 24); // osversion if (Version == NtlmVersion.Version3) { Buffer.BlockCopy(OSVersion, 0, data, 64, OSVersion.Length); } Buffer.BlockCopy(domain, 0, data, dom_off, domain.Length); Buffer.BlockCopy(user, 0, data, uname_off, user.Length); Buffer.BlockCopy(host, 0, data, host_off, host.Length); using (ChallengeResponse ntlm = new ChallengeResponse(_password, _challenge)) { Buffer.BlockCopy(ntlm.LM, 0, data, lmresp_off, 24); Buffer.BlockCopy(ntlm.NT, 0, data, ntresp_off, 24); if (Version != NtlmVersion.Version1) { // session key Buffer.BlockCopy(ntlm.LMSessionKey, 0, data, skey_off, 16); } } return(data); }
public override byte[] GetBytes() { byte[] bytes1 = Encoding.Unicode.GetBytes(this._domain.ToUpper(CultureInfo.InvariantCulture)); byte[] bytes2 = Encoding.Unicode.GetBytes(this._username); byte[] bytes3 = Encoding.Unicode.GetBytes(this._host.ToUpper(CultureInfo.InvariantCulture)); byte[] numArray = this.PrepareMessage(64 + bytes1.Length + bytes2.Length + bytes3.Length + 24 + 24); short num1 = (short)(64 + bytes1.Length + bytes2.Length + bytes3.Length); numArray[12] = (byte)24; numArray[13] = (byte)0; numArray[14] = (byte)24; numArray[15] = (byte)0; numArray[16] = (byte)num1; numArray[17] = (byte)((uint)num1 >> 8); short num2 = (short)((int)num1 + 24); numArray[20] = (byte)24; numArray[21] = (byte)0; numArray[22] = (byte)24; numArray[23] = (byte)0; numArray[24] = (byte)num2; numArray[25] = (byte)((uint)num2 >> 8); short length1 = (short)bytes1.Length; short num3 = 64; numArray[28] = (byte)length1; numArray[29] = (byte)((uint)length1 >> 8); numArray[30] = numArray[28]; numArray[31] = numArray[29]; numArray[32] = (byte)num3; numArray[33] = (byte)((uint)num3 >> 8); short length2 = (short)bytes2.Length; short num4 = (short)((int)num3 + (int)length1); numArray[36] = (byte)length2; numArray[37] = (byte)((uint)length2 >> 8); numArray[38] = numArray[36]; numArray[39] = numArray[37]; numArray[40] = (byte)num4; numArray[41] = (byte)((uint)num4 >> 8); short length3 = (short)bytes3.Length; short num5 = (short)((int)num4 + (int)length2); numArray[44] = (byte)length3; numArray[45] = (byte)((uint)length3 >> 8); numArray[46] = numArray[44]; numArray[47] = numArray[45]; numArray[48] = (byte)num5; numArray[49] = (byte)((uint)num5 >> 8); short length4 = (short)numArray.Length; numArray[56] = (byte)length4; numArray[57] = (byte)((uint)length4 >> 8); numArray[60] = (byte)this.Flags; numArray[61] = (byte)((uint)this.Flags >> 8); numArray[62] = (byte)((uint)this.Flags >> 16); numArray[63] = (byte)((uint)this.Flags >> 24); Buffer.BlockCopy((Array)bytes1, 0, (Array)numArray, (int)num3, bytes1.Length); Buffer.BlockCopy((Array)bytes2, 0, (Array)numArray, (int)num4, bytes2.Length); Buffer.BlockCopy((Array)bytes3, 0, (Array)numArray, (int)num5, bytes3.Length); using (ChallengeResponse challengeResponse = new ChallengeResponse(this._password, this._challenge)) { Buffer.BlockCopy((Array)challengeResponse.LM, 0, (Array)numArray, (int)num1, 24); Buffer.BlockCopy((Array)challengeResponse.NT, 0, (Array)numArray, (int)num2, 24); } return(numArray); }
public override byte[] GetBytes() { byte[] target = EncodeString(_domain); byte[] user = EncodeString(_username); byte[] host = EncodeString(_host); byte[] lm, ntlm; if (_type2 == null) { if (_level != NtlmAuthLevel.LM_and_NTLM) { throw new InvalidOperationException( "Refusing to use legacy-mode LM/NTLM authentication " + "unless explicitly enabled using DefaultAuthLevel."); } using (var legacy = new ChallengeResponse(_password, _challenge)) { lm = legacy.LM; ntlm = legacy.NT; } } else { ChallengeResponse2.Compute(_type2, _level, _username, _password, _domain, out lm, out ntlm); } var lmresp_len = lm != null ? lm.Length : 0; var ntresp_len = ntlm != null ? ntlm.Length : 0; byte[] data = PrepareMessage(64 + target.Length + user.Length + host.Length + lmresp_len + ntresp_len); // LM response short lmresp_off = (short)(64 + target.Length + user.Length + host.Length); data [12] = (byte)lmresp_len; data [13] = (byte)0x00; data [14] = (byte)lmresp_len; data [15] = (byte)0x00; data [16] = (byte)lmresp_off; data [17] = (byte)(lmresp_off >> 8); // NT response short ntresp_off = (short)(lmresp_off + lmresp_len); data [20] = (byte)ntresp_len; data [21] = (byte)(ntresp_len >> 8); data [22] = (byte)ntresp_len; data [23] = (byte)(ntresp_len >> 8); data [24] = (byte)ntresp_off; data [25] = (byte)(ntresp_off >> 8); // target short dom_len = (short)target.Length; short dom_off = 64; data [28] = (byte)dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte)dom_off; data [33] = (byte)(dom_off >> 8); // username short uname_len = (short)user.Length; short uname_off = (short)(dom_off + dom_len); data [36] = (byte)uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte)uname_off; data [41] = (byte)(uname_off >> 8); // host short host_len = (short)host.Length; short host_off = (short)(uname_off + uname_len); data [44] = (byte)host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte)host_off; data [49] = (byte)(host_off >> 8); // message length short msg_len = (short)data.Length; data [56] = (byte)msg_len; data [57] = (byte)(msg_len >> 8); int flags = (int)Flags; // options flags data [60] = (byte)flags; data [61] = (byte)((uint)flags >> 8); data [62] = (byte)((uint)flags >> 16); data [63] = (byte)((uint)flags >> 24); Buffer.BlockCopy(target, 0, data, dom_off, target.Length); Buffer.BlockCopy(user, 0, data, uname_off, user.Length); Buffer.BlockCopy(host, 0, data, host_off, host.Length); if (lm != null) { Buffer.BlockCopy(lm, 0, data, lmresp_off, lm.Length); Array.Clear(lm, 0, lm.Length); } Buffer.BlockCopy(ntlm, 0, data, ntresp_off, ntlm.Length); Array.Clear(ntlm, 0, ntlm.Length); return(data); }
public override byte[] GetBytes() { byte[] bytes = Encoding.Unicode.GetBytes(_domain.ToUpper(CultureInfo.InvariantCulture)); byte[] bytes2 = Encoding.Unicode.GetBytes(_username); byte[] bytes3 = Encoding.Unicode.GetBytes(_host.ToUpper(CultureInfo.InvariantCulture)); byte[] array = PrepareMessage(64 + bytes.Length + bytes2.Length + bytes3.Length + 24 + 24); short num = (short)(64 + bytes.Length + bytes2.Length + bytes3.Length); array[12] = 24; array[13] = 0; array[14] = 24; array[15] = 0; array[16] = (byte)num; array[17] = (byte)(num >> 8); short num2 = (short)(num + 24); array[20] = 24; array[21] = 0; array[22] = 24; array[23] = 0; array[24] = (byte)num2; array[25] = (byte)(num2 >> 8); short num3 = (short)bytes.Length; short num4 = 64; array[28] = (byte)num3; array[29] = (byte)(num3 >> 8); array[30] = array[28]; array[31] = array[29]; array[32] = (byte)num4; array[33] = (byte)(num4 >> 8); short num5 = (short)bytes2.Length; short num6 = (short)(num4 + num3); array[36] = (byte)num5; array[37] = (byte)(num5 >> 8); array[38] = array[36]; array[39] = array[37]; array[40] = (byte)num6; array[41] = (byte)(num6 >> 8); short num7 = (short)bytes3.Length; short num8 = (short)(num6 + num5); array[44] = (byte)num7; array[45] = (byte)(num7 >> 8); array[46] = array[44]; array[47] = array[45]; array[48] = (byte)num8; array[49] = (byte)(num8 >> 8); short num9 = (short)array.Length; array[56] = (byte)num9; array[57] = (byte)(num9 >> 8); array[60] = (byte)base.Flags; array[61] = (byte)((uint)base.Flags >> 8); array[62] = (byte)((uint)base.Flags >> 16); array[63] = (byte)((uint)base.Flags >> 24); Buffer.BlockCopy(bytes, 0, array, num4, bytes.Length); Buffer.BlockCopy(bytes2, 0, array, num6, bytes2.Length); Buffer.BlockCopy(bytes3, 0, array, num8, bytes3.Length); using (ChallengeResponse challengeResponse = new ChallengeResponse(_password, _challenge)) { Buffer.BlockCopy(challengeResponse.LM, 0, array, num, 24); Buffer.BlockCopy(challengeResponse.NT, 0, array, num2, 24); return(array); } }
public void LM_Disposed () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); ntlm.Dispose (); Assert.IsNotNull (ntlm.LM, "LM"); }
public void NT_Disposed () { ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]); ntlm.Dispose (); Assert.IsNotNull (ntlm.NT, "NT"); }
public override byte[] GetBytes () { byte[] target = EncodeString (_domain); byte[] user = EncodeString (_username); byte[] host = EncodeString (_host); byte[] lm, ntlm; if (_type2 == null) { if (_level != NtlmAuthLevel.LM_and_NTLM) throw new InvalidOperationException ( "Refusing to use legacy-mode LM/NTLM authentication " + "unless explicitly enabled using DefaultAuthLevel."); using (var legacy = new ChallengeResponse (_password, _challenge)) { lm = legacy.LM; ntlm = legacy.NT; } } else { ChallengeResponse2.Compute (_type2, _level, _username, _password, _domain, out lm, out ntlm); } var lmresp_len = lm != null ? lm.Length : 0; var ntresp_len = ntlm != null ? ntlm.Length : 0; byte[] data = PrepareMessage (64 + target.Length + user.Length + host.Length + lmresp_len + ntresp_len); // LM response short lmresp_off = (short)(64 + target.Length + user.Length + host.Length); data [12] = (byte)lmresp_len; data [13] = (byte)0x00; data [14] = (byte)lmresp_len; data [15] = (byte)0x00; data [16] = (byte)lmresp_off; data [17] = (byte)(lmresp_off >> 8); // NT response short ntresp_off = (short)(lmresp_off + lmresp_len); data [20] = (byte)ntresp_len; data [21] = (byte)(ntresp_len >> 8); data [22] = (byte)ntresp_len; data [23] = (byte)(ntresp_len >> 8); data [24] = (byte)ntresp_off; data [25] = (byte)(ntresp_off >> 8); // target short dom_len = (short)target.Length; short dom_off = 64; data [28] = (byte)dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte)dom_off; data [33] = (byte)(dom_off >> 8); // username short uname_len = (short)user.Length; short uname_off = (short)(dom_off + dom_len); data [36] = (byte)uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte)uname_off; data [41] = (byte)(uname_off >> 8); // host short host_len = (short)host.Length; short host_off = (short)(uname_off + uname_len); data [44] = (byte)host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte)host_off; data [49] = (byte)(host_off >> 8); // message length short msg_len = (short)data.Length; data [56] = (byte)msg_len; data [57] = (byte)(msg_len >> 8); int flags = (int)Flags; // options flags data [60] = (byte)flags; data [61] = (byte)((uint)flags >> 8); data [62] = (byte)((uint)flags >> 16); data [63] = (byte)((uint)flags >> 24); Buffer.BlockCopy (target, 0, data, dom_off, target.Length); Buffer.BlockCopy (user, 0, data, uname_off, user.Length); Buffer.BlockCopy (host, 0, data, host_off, host.Length); if (lm != null) { Buffer.BlockCopy (lm, 0, data, lmresp_off, lm.Length); Array.Clear (lm, 0, lm.Length); } Buffer.BlockCopy (ntlm, 0, data, ntresp_off, ntlm.Length); Array.Clear (ntlm, 0, ntlm.Length); return data; }
public override byte[] GetBytes() { byte[] domain = Encoding.Unicode.GetBytes(_domain.ToUpper(CultureInfo.InvariantCulture)); byte[] user = Encoding.Unicode.GetBytes(_username); byte[] host = Encoding.Unicode.GetBytes(_host.ToUpper(CultureInfo.InvariantCulture)); byte[] data = PrepareMessage(64 + domain.Length + user.Length + host.Length + 24 + 24); // LM response short lmresp_off = (short)(64 + domain.Length + user.Length + host.Length); data [12] = (byte)0x18; data [13] = (byte)0x00; data [14] = (byte)0x18; data [15] = (byte)0x00; data [16] = (byte)lmresp_off; data [17] = (byte)(lmresp_off >> 8); // NT response short ntresp_off = (short)(lmresp_off + 24); data [20] = (byte)0x18; data [21] = (byte)0x00; data [22] = (byte)0x18; data [23] = (byte)0x00; data [24] = (byte)ntresp_off; data [25] = (byte)(ntresp_off >> 8); // domain short dom_len = (short)domain.Length; short dom_off = 64; data [28] = (byte)dom_len; data [29] = (byte)(dom_len >> 8); data [30] = data [28]; data [31] = data [29]; data [32] = (byte)dom_off; data [33] = (byte)(dom_off >> 8); // username short uname_len = (short)user.Length; short uname_off = (short)(dom_off + dom_len); data [36] = (byte)uname_len; data [37] = (byte)(uname_len >> 8); data [38] = data [36]; data [39] = data [37]; data [40] = (byte)uname_off; data [41] = (byte)(uname_off >> 8); // host short host_len = (short)host.Length; short host_off = (short)(uname_off + uname_len); data [44] = (byte)host_len; data [45] = (byte)(host_len >> 8); data [46] = data [44]; data [47] = data [45]; data [48] = (byte)host_off; data [49] = (byte)(host_off >> 8); // message length short msg_len = (short)data.Length; data [56] = (byte)msg_len; data [57] = (byte)(msg_len >> 8); // options flags data [60] = (byte)Flags; data [61] = (byte)((uint)Flags >> 8); data [62] = (byte)((uint)Flags >> 16); data [63] = (byte)((uint)Flags >> 24); Buffer.BlockCopy(domain, 0, data, dom_off, domain.Length); Buffer.BlockCopy(user, 0, data, uname_off, user.Length); Buffer.BlockCopy(host, 0, data, host_off, host.Length); using (ChallengeResponse ntlm = new ChallengeResponse(_password, _challenge)) { Buffer.BlockCopy(ntlm.LM, 0, data, lmresp_off, 24); Buffer.BlockCopy(ntlm.NT, 0, data, ntresp_off, 24); } return(data); }