坚持在 .NET 中逆向 TripleDES

Stuck on reversing TripleDES in .NET

我被困在一个目标上,我想知道是否可以反转这部分代码,目标是处理 'nodeData' 以获得 'True' 条件 'result'。 由于我不熟悉这种类型的密码学,所以我无法理解这部分代码。顺便说一句,我认为 'serialNumber' 是密钥而 'iV' 可能是 IV 我无法弄清楚这是否是一个解密例程,是否可以生成正确的密钥以对结果执行 true ?

    Dim serialNumber As Byte() = New Byte() {&H2, &H4E, &HA0, &HC5, &HFD, &HE0, &H99, &HF6, &H9D, &HAD, &H7A, &H2F, &H16, &HB, &HA2, &HA7,
    &HDC, &H23, &H9F, &H3F, &HE6, &H28, &HC4, &H5D, &H36, &H76, &H88, &HC3, &H86, &HE6, &H72, &HD7,
    &H5E, &HF3, &H30, &H3F, &HD2, &H2B, &H7F, &H16, &H9C, &H9B, &H4E, &HC4, &HF2, &H46, &HDC, &H2
    }
    Dim iV As Byte() = New Byte() {&H36, &H76, &H88, &HC3, &H86, &HE6, &H72, &HD7}
    Dim provider As New TripleDESCryptoServiceProvider With { _
        .KeySize = &HC0, _
        .BlockSize = &H40, _
        .Padding = PaddingMode.None _
    }
    Dim destinationArray As Byte() = New Byte(&H18 - 1) {}
    Array.Copy(serialNumber, destinationArray, &H18)
    Dim buffer4 As Byte() = New Byte(8 - 1) {}
    Array.Copy(serialNumber, &H18, buffer4, 0, 8)
    Dim encryptor As ICryptoTransform = provider.CreateDecryptor(destinationArray, iV)

    Dim nodeData As Byte() = New Byte() {&HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA,
        &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA,
        &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA, &HAA
    }

    Dim arrays As Byte() = Nothing
    Dim stream As MemoryStream = New MemoryStream(nodeData)
    Using cryptoStream As CryptoStream = New CryptoStream(stream, encryptor, CryptoStreamMode.Read)
        Dim list As List(Of Byte) = New List(Of Byte)()
        While True
            Dim expr_91 As Integer = cryptoStream.ReadByte()
            Dim num As Integer = expr_91
            If expr_91 = -1 Then
                Exit While
            End If
            list.Add(CByte(num))
        End While
        arrays = list.ToArray()
    End Using
    Dim result As Boolean = False
    Dim volumeSerialNumber As Integer = &HC45D3676
    Dim bytes As Byte() = BitConverter.GetBytes(volumeSerialNumber)
    Dim array2 As Byte() = New Byte() {arrays(22), arrays(23), arrays(24), arrays(25)}
    If array2.Length = 4 AndAlso bytes.Length = 4 Then
        result = (bytes(0) = array2(0) AndAlso bytes(1) = array2(1) AndAlso bytes(2) = array2(2) AndAlso bytes(3) = array2(3))
    End If

抱歉,VB 不流利。在 C# 中,加密代码可能如下所示:

        byte[] serial = { 
            2, 0x4e, 160, 0xc5, 0xfd, 0xe0, 0x99, 0xf6, 0x9d, 0xad, 0x7a, 0x2f, 0x16, 11, 0xa2, 0xa7, 
            220, 0x23, 0x9f, 0x3f, 230, 40, 0xc4, 0x5d, 0x36, 0x76, 0x88, 0xc3, 0x86, 230, 0x72, 0xd7, 
            0x5e, 0xf3, 0x30, 0x3f, 210, 0x2b, 0x7f, 0x16, 0x9c, 0x9b, 0x4e, 0xc4, 0xf2, 70, 220, 2
         };
        byte[] iv = { 0x36, 0x76, 0x88, 0xc3, 0x86, 230, 0x72, 0xd7 };
        TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider
        {
            KeySize = 0xc0,
            BlockSize = 0x40,
            Padding = PaddingMode.None
        };
        byte[] destinationArray = new byte[0x18];
        Array.Copy(serial, destinationArray, 0x18);


        ICryptoTransform transform = provider.CreateDecryptor(destinationArray, iv);
        byte[] data = { 
            170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 
            170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 
            170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170
         };

        byte[] decryptedData;
        MemoryStream stream = new MemoryStream(data);
        using (CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read))
        {
            List<byte> list = new List<byte>();
            while (true)
            {
                int current = stream2.ReadByte();
                if (current == -1)
                {
                    break;
                }
                list.Add((byte)current);
            }
            decryptedData = list.ToArray();
        }

        int num = -1000524170;
        byte[] bytes = BitConverter.GetBytes(num);

        decryptedData[0x16] = bytes[0];
        decryptedData[0x17] = bytes[1];
        decryptedData[0x18] = bytes[2];
        decryptedData[0x19] = bytes[3];

        ICryptoTransform transform2 = provider.CreateEncryptor(destinationArray, iv);
        byte[] bla = transform2.TransformFinalBlock(decryptedData, 0, decryptedData.Length);
        for (int i = 0; i < bla.Length; i++)
        {
            Console.Write(bla[i]);
            Console.Write(",");
            if (i % 16 == 15)
                Console.WriteLine();
        }