尝试反转函数以从 HMAC 签名生成某些颜色字符串 - 反编译代码看起来正确,但我的结果不同

逆向工程 爪哇 散列函数
2021-07-10 12:11:47

如果没有上下文,这可能有点难以理解,但其要点如下;我正在尝试反转某个应用程序,并且我尝试在应用程序中反转的部分内容基于通过 API 请求传递的字符串生成 3 种独特的颜色。我知道我已经成功地像另一个一样正确地反转了 API我收到的数据运行良好,我已经构建了一个与 API 正确交互的客户端的克隆。我坚持的是每天生成的三种颜色代码,基于 API 传递的特定密钥。

今天,2017 年 7 月 26 日,颜色代码是[#c698c8, #72555f, #2f1021],根据 API 传递的字符串创建 - 87gs4

我已经反汇编了 Java 代码,并将这些颜色的生成追溯到以下函数集。我已经验证它确实是我从负责生成这些的 API 中抓取的字符串。SALT在功能提到从格式化为日期时间产生yyyyMd-在今天的颜色的情况下,该盐是20170727,或者作为HMAC签名函数生成它,20170727是与输入87gs4的键。

然后获取生成的签名(64 个十六进制字符),只保存前 18 个,然后分成 3 个以形成颜色代码。因此,我知道我正在寻找的签名(今天)以c698c872555f2f1021- 但由于某种原因,我的结果没有达到这一点。我已经检查过以确保我使用的是正确的键/输入顺序(为了以防万一,甚至可以将其颠倒),并且我是 getitng9a0ca25fff8eeccdbaf741436ddacf364f517adcb28299f0544c72a67dca208930c21ae7995415220e427588e451cbdd58d84785bcd58f8e3f0db2ca0fc104c4。我也检查过字母无济于事。

我没有明天的颜色,但我有来自 API 的数据并且知道盐 - 明天它将是20170728kRG86

我已经确认没有通过getColorBand()getSalt()在传递值以创建签名之前进行外部操作,我什至有另一双眼睛看了一下这个 - 对这类东西相当有经验的人 - 他认为也许我们在字节到十六进制(反之亦然)对话中遗漏了一些导致错误结果的内容,但我们走在正确的轨道上,并且使用 yyyyMd salt 的 HMAC-SHA256 哈希生成器和我收到的数据是正确的是它应该生成正确的数据。

实际字符串操作和生成的代码:

        String color = this.hexFortmat.substring(0, 6);
        ImageView colorBand1 = ((ImageView) DecompiledFile.this.findViewById(R.id.image_view1));
        ImageView colorBand2 = ((ImageView) DecompiledFile.this.findViewById(R.id.image_view2));
        ImageView colorBand3 = ((ImageView) DecompiledFile.this.findViewById(R.id.image_view3));
        String hexFortmat = DecompiledFile.bin2hex(this.mdbytes);
        byte[] mdbytes = DecompiledFile.generateHmacSHA256Signature(DecompiledFile.this.getSalt(), DecompiledFile.this.getColorBand());
        boolean performAllTimerFunctions = true;
        TextView specialInstruction = ((TextView) DecompiledFile.this.findViewById(R.id.textView9));
        boolean visibleColorBand = false;
        boolean visibleSpecialInstruction = false;

相关签名代码:

public static byte[] generateHmacSHA256Signature(String data, String key) throws GeneralSecurityException, IOException {
    try {
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StringEncodings.UTF8), HMAC_SHA_256);
        Mac mac = Mac.getInstance(HMAC_SHA_256);
        mac.init(secretKey);
        return mac.doFinal(data.getBytes(StringEncodings.UTF8));
    } catch (UnsupportedEncodingException e) {
        throw new GeneralSecurityException(e);
    }
}

static String bin2hex(byte[] data) {
    return String.format("%0" + (data.length * 2) + "X", new Object[]{new BigInteger(1, data)});
}
1个回答

你可能在这个月有一个额外的 0

https://www.freeformatter.com/hmac-generator.html#ad-output

2017727

87GS4

c698c872565f2f1021645993fe29eff6adba41cb1260b7e671fc1752ae8d94a0

它根据格式字符串填充

http://www.fileformat.info/tip/java/simpledateformat.htm

在此处输入图片说明