首页 > 解决方案 > Mirai 使用什么类型的加密?

问题描述

我无法弄清楚这一点。它使用密钥进行加密,当密钥更改时,输出完全不同。真是天才。但是,我有使用的密钥,我只是不知道如何解密它。因此,如果有人可以为这种加密方法命名和/或告诉我如何解密用它编译的字符串,将不胜感激。

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdint.h>
    #include <arpa/inet.h>
    static uint32_t table_key = 0xdedefbaf; // here is the key
    void *x(void *, int);
    int main(int argc, char **args)
    {
        void *data;
        int len, i;
        if (argc != 3)
        {
            printf("Usage: %s <string> <data>\n", args[0]);
            return 0;
        }
        if (strcmp(args[1], "string") == 0)
        {
            data = args[2];
            len = strlen(args[2]) + 1;
        }
        else
        {
            printf("Unknown data type `%s`!\n", args[1]);
            return -1;
        }
        printf("XOR'ing %d bytes of data...\n", len);
        data = x(data, len);
        for (i = 0; i < len; i++)
        printf("\\x%02X", ((unsigned char *)data)[i]);
        printf("\n");
    }
    void *x(void *_buf, int len)
    {
        unsigned char *buf = (char *)_buf, *out = malloc(len);
        int i;
        uint8_t k1 = table_key & 0xff,
                k2 = (table_key >> 8) & 0xff,
                k3 = (table_key >> 16) & 0xff,
                k4 = (table_key >> 24) & 0xff;
        for (i = 0; i < len; i++)
        {
            char tmp = buf[i] ^ k1;
            tmp ^= k2;
            tmp ^= k3;
            tmp ^= k4;
            out[i] = tmp;
        }
        return out;
    }

标签: cencryption

解决方案


这是一种对称加密,它只是将输入字符串的每个字节与密钥的四个字节进行异或。要解密它,您需要将输出作为输入运行。

例子:

./sotest string "dies ist ein test"
XOR'ing 18 bytes of data...
\x30\x3D\x31\x27\x74\x3D\x27\x20\x74\x31\x3D\x3A\x74\x20\x31\x27\x20\x54

如果你翻译字节的十六进制表示,echo -e你会得到

echo -e "\x30\x3D\x31\x27\x74\x3D\x27\x20\x74\x31\x3D\x3A\x74\x20\x31\x27\x20\x54"
0=1't=' t1=:t 1' T

通过程序运行它并得到

./sotest string "0=1't=' t1=:t 1' T"
XOR'ing 19 bytes of data...
\x64\x69\x65\x73\x20\x69\x73\x74\x20\x65\x69\x6E\x20\x74\x65\x73\x74\x00\x54

(我们现在多了一个字节,我们发现了一个错误。)echo -e使用该输入运行会导致

echo -e "\x64\x69\x65\x73\x20\x69\x73\x74\x20\x65\x69\x6E\x20\x74\x65\x73\x74\x00\x54"
dies ist ein testT

Das NUL 字节\x00以 C 字符串结尾,但这不是 C 字符串,因此尾随T.


推荐阅读