对文件加密进行逆向工程(很可能是异或)



我试图对加密的文件格式进行反向工程。很可能使用异或加密。我可以使用我分析过的已知明文创建加密文件:

enc     71 8d 7e 84 29 20 b8 cb 6c ed bb 8a 62 a1 
dec     74 68 69 73 20 69 73 20 61 20 74 65 73 74 
xor     05 e5 17 f7 09 49 cb eb 0d cd cf ef 11 d5 
txt     t  h  i  s     i  s     a     t  e  s  t  
enc     61 ad be 84 29 20 b8 cb 6c ed bb 8a 62 a1 
dec     64 68 69 73 20 69 73 20 61 20 74 65 73 74 
xor     05 c5 d7 f7 09 49 cb eb 0d cd cf ef 11 d5 
txt     d  h  i  s     i  s     a     t  e  s  t 
enc     62 a5 ae a4 e9 a0 b8 cb 6c ed bb 8a 62 a1 
dec     67 68 69 73 20 69 73 20 61 20 74 65 73 74 
xor     05 cd c7 d7 c9 c9 cb eb 0d cd cf ef 11 d5
txt     g  h  i  s     i  s     a     t  e  s  t  

很明显,原始文本是加密的一部分。键的第一个字节总是05。键的第二个字节可以这样计算:

(enc1 + dec1) OR xor1

密钥的熵相当低,这意味着其他密钥字节也有类似的规则。

任何想法?

你差点就成功了!

键在m位置的字节由:

km = [(en + dn) ^ kn] | secret

where:

en is the previous encrypted byte
dn is the previous plain text byte
kn is the previous key byte (k0 = 5)
secret is an arbitrary number starting at 5 and incremented by 2 every two turns
^ is the xor operator
| is the or operator
一个简单的c#密钥生成器:
namespace Sample.CustomEncrypt {
    using System.Collections.Generic;
    using System.Text;
    class Program {
        static void Main() {
            var key1 = GenerateKey("this is a test");
            var key2 = GenerateKey("dhis is a test");
            var key3 = GenerateKey("ghis is a test");
        }
        public static byte[] GenerateKey(string input) {
            var plain = Encoding.UTF8.GetBytes(input);
            var secret = 5;
            var key = new List<byte> {
                0x05
            };
            for (var i = 0; i < plain.Length - 1; i++) {
                var dn = plain[i];
                var kn = key[i];
                var en = (byte)(dn ^ kn);
                var km = (byte)(((dn + en) ^ kn) | secret);
                key.Add(km);
                if (i % 2 == 0) {
                    secret += 2;
                }
            }
            return key.ToArray();
        }
    }
}

PS:正如Eugene指出的,下次你应该发表逆向工程或密码学

相关内容

最新更新