mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-10 19:33:18 +02:00
NTLMCryptography: Add .NET 5.0 \ 6.0 support
This commit is contained in:
parent
4c59c21670
commit
0416e5670d
2 changed files with 36 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2014-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
/* Copyright (C) 2014-2023 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,
|
||||
|
@ -27,6 +27,15 @@ namespace SMBLibrary.Tests
|
|||
Assert.IsTrue(ByteUtils.AreByteArraysEqual(hash, expected));
|
||||
}
|
||||
|
||||
// Will use weak DES key
|
||||
[TestMethod]
|
||||
public void LMv1HashTestEmptyPassword()
|
||||
{
|
||||
byte[] hash = NTLMCryptography.LMOWFv1("");
|
||||
byte[] expected = new byte[] { 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee, 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee };
|
||||
Assert.IsTrue(ByteUtils.AreByteArraysEqual(hash, expected));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NTv1HashTest()
|
||||
{
|
||||
|
@ -155,6 +164,7 @@ namespace SMBLibrary.Tests
|
|||
public void TestAll()
|
||||
{
|
||||
LMv1HashTest();
|
||||
LMv1HashTestEmptyPassword();
|
||||
NTv1HashTest();
|
||||
NTv2HashTest();
|
||||
LMv1ResponseTest();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
/* Copyright (C) 2014-2023 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,
|
||||
|
@ -78,11 +78,26 @@ namespace SMBLibrary.Authentication.NTLM
|
|||
{
|
||||
DES des = DES.Create();
|
||||
des.Mode = mode;
|
||||
DESCryptoServiceProvider sm = des as DESCryptoServiceProvider;
|
||||
MethodInfo mi = sm.GetType().GetMethod("_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
object[] Par = { rgbKey, mode, rgbIV, sm.FeedbackSize, 0 };
|
||||
ICryptoTransform trans = mi.Invoke(sm, Par) as ICryptoTransform;
|
||||
return trans;
|
||||
ICryptoTransform transform;
|
||||
if (DES.IsWeakKey(rgbKey) || DES.IsSemiWeakKey(rgbKey))
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
MethodInfo getTransformCoreMethodInfo = des.GetType().GetMethod("CreateTransformCore", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
object[] getTransformCoreParameters = { mode, des.Padding, rgbKey, rgbIV, des.BlockSize / 8 , des.FeedbackSize / 8, des.BlockSize / 8, true };
|
||||
transform = getTransformCoreMethodInfo.Invoke(null, getTransformCoreParameters) as ICryptoTransform;
|
||||
#else
|
||||
DESCryptoServiceProvider desServiceProvider = des as DESCryptoServiceProvider;
|
||||
MethodInfo newEncryptorMethodInfo = desServiceProvider.GetType().GetMethod("_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
object[] encryptorParameters = { rgbKey, mode, rgbIV, desServiceProvider.FeedbackSize, 0 };
|
||||
transform = newEncryptorMethodInfo.Invoke(desServiceProvider, encryptorParameters) as ICryptoTransform;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
transform = des.CreateEncryptor(rgbKey, rgbIV);
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -123,7 +138,11 @@ namespace SMBLibrary.Authentication.NTLM
|
|||
|
||||
public static Encoding GetOEMEncoding()
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
return ASCIIEncoding.GetEncoding(28591);
|
||||
#else
|
||||
return Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue