首页 > 其他分享 >某咖啡 app 加密参数分析进阶版

某咖啡 app 加密参数分析进阶版

时间:2022-11-16 18:37:47浏览次数:65  
标签:github 加密 进阶 app emulator unidbg import com md5

本文由 简悦 SimpRead 转码, 原文地址 mp.weixin.qq.com

仅供学习研究 。请勿用于非法用途,本人将不承担任何法律责任。

前言

  • app 某某咖啡

  • v4.4.0

mitmproxy 抓包

java 分析

定位到 CryptoHelper 类的名为 md5_crypt 的 native 静态方法。

frida hook

脚本如下所示

function hook() {
    Java.perform(function() {
    var CryptoHelper = Java.use('com.l*****e.safeboxlib.CryptoHelper');
    CryptoHelper.md5_crypt.implementation = function (x, y) {
        console.log('md5_crypt_x', bytes2str(x));
        console.log('md5_crypt_y', y);
        var result = this.md5_crypt(x, y);
        console.warn('md5_crypt_ret', bytes2str(result));
        return result;
        };
  }
  }


我们可以看到,hook 的结果和抓包结果一致

so 分析

使用 lasting-yang 的脚本 hook_RegisterNatives

脚本地址:https://github.com/lasting-yang/frida_hook_libart

使用开源的 cutter 到 so 去一探究竟,我们搜索上图中的偏移 0x1a981,来到 android_native_md5 函数。

经过一番分析,应该是 md5 加密完之后,还有一个 bytesToInt 的逻辑。

unidbg

去年的文章里用 frida 就能搞定了,这次我们用 lilac、qinless、qxp 等大佬极力推荐的神器 unidbg 进行辅助分析。

首先是搭建架子

package com.*;

import com.github.unidbg.AndroidEmulator;
import com.github.unidbg.Module;
import com.github.unidbg.debugger.Debugger;
import com.github.unidbg.file.IOResolver;
import com.github.unidbg.linux.android.AndroidEmulatorBuilder;
import com.github.unidbg.linux.android.AndroidResolver;
import com.github.unidbg.linux.android.dvm.*;
import com.github.unidbg.linux.android.dvm.array.ByteArray;
import com.github.unidbg.linux.android.dvm.array.IntArray;
import com.github.unidbg.linux.android.dvm.wrapper.DvmInteger;
import com.github.unidbg.memory.Memory;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Md5Crypt440 extends AbstractJni {
    private final AndroidEmulator emulator;
    private final Module module;
    private final VM vm;

    public String apkPath = "/Users/darbra/Downloads/apk/com.*/temp.apk";
    public String soPath2 = "/Users/darbra/Downloads/apk/com.*/lib/armeabi-v7a/libcryptoDD.so";

    Md5Crypt440() {
        emulator = AndroidEmulatorBuilder.for32Bit().setProcessName("com.*").build();
        final Memory memory = emulator.getMemory();
        memory.setLibraryResolver(new AndroidResolver(23));
        vm = emulator.createDalvikVM(new File(apkPath));
        vm.setVerbose(true);
        vm.setJni(this);
        DalvikModule dm2 = vm.loadLibrary(new File(soPath2), true);
        dm2.callJNI_OnLoad(emulator);
        module = dm2.getModule();
    }

    public void call() {
        String methodId = "md5_crypt([BI)[B";
        DvmClass SigEntity = vm.resolveClass("com/luckincoffee/safeboxlib/CryptoHelper");
        String fakeInput1 = "cid=210101;q=j***=;uid=***";
        ByteArray inputByteArray1 = new ByteArray(vm, fakeInput1.getBytes(StandardCharsets.UTF_8));
        DvmObject ret = SigEntity.callStaticJniMethodObject(
                emulator, methodId,
                inputByteArray1,
                1
        );
        byte [] strByte = (byte[]) ret.getValue();
        String strString = new String(strByte);
        System.out.println("callObject执行结果:"+ strString);
    }

    public static void main(String[] args) {
        Md5Crypt440 getSig = new Md5Crypt440();
        getSig.call();
        getSig.destroy();
    }

    private void destroy() {
        try {
            emulator.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



值得注意的是,这个 app 不用补任何环境,非常轻松地就运行出了结果。

结果和抓包、frida 完全一致。

我们在 md5 函数打个断点。

public void HookByConsoleDebugger(){
    Debugger debugger = emulator.attach();
    debugger.addBreakPoint(module.base+0x13E3C);
}


输入 mr0,我们可以看到第一个参数就是明文,但不够完整。

接着输入 mr0 0x100,后面可以跟的是大小。我们欣喜地发现,之前的那坨明文后面加了个 salt 值,d******9

参数 2,r1=0xef=239,我们去 cyberchef 看看这个明文长度是否为 239

果不其然是的。

接着输入 mr2,查看第三个参数。

看情况参数 3 不出重大意外是 buffer,所以我们需要 hook 它的返回值。在这里我们先记下 r2 的地址 --->>> 0xbffff5d8。

我们使用 blr 命令用于在函数返回时设置一个一次性断点,然后 c 运行函数,它在返回处断下来。

接着输入刚刚记录下来的 m0xbffff5d8

我们去 cyberchef 进行验证,完全正确!

md5 步骤解决了,接着查看 bytesToInt。

我们在 0x13924 那里进行 hook 操作

public void hookBytesToInt() {
        IHookZz hookZz = HookZz.getInstance(emulator);

        hookZz.wrap(module.base + 0x13924 + 1, new WrapCallback<HookZzArm32RegisterContext>() {
            @Override
            public void preCall(Emulator<?> emulator, HookZzArm32RegisterContext ctx, HookEntryInfo info) {
                Inspector.inspect(ctx.getR0Pointer().getByteArray(0, 0x10), "参数1");
                System.out.println("参数2->>" + ctx.getR1Int());
            };
            @Override
            public void postCall(Emulator<?> emulator, HookZzArm32RegisterContext ctx, HookEntryInfo info) {
                System.out.println("返回值->>" + ctx.getR0Int());
            }

        });
    }


我们看一下输出结果了,四个输出值都能对应上最后的 sign 结果。

其中的正负号处理应该是对应的如下逻辑

我们写个小脚本还原下,与之前的抓包、frida、unidbg 都一致,大功告成。

在本人 github.com/darbra/sign 有更多的一些思路交流,如果对朋友们有所帮助,不甚欣喜。

标签:github,加密,进阶,app,emulator,unidbg,import,com,md5
From: https://www.cnblogs.com/xiaofubase/p/16897086.html

相关文章

  • 12APP数据抓取
    我们知道Web站点有多种渲染和反爬方式,渲染分为服务端渲染和客户端渲染;反爬也是多种多样,如请求头验证、WebDriver限制、验证码、字体反爬、封禁IP、账号验证等等,综合来......
  • 7对称加密非对称加密
    数据的编码与加密ASCII编码ASCII((AmericanStandardCodeforInformationInterchange):美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英......
  • Error: Failed to download metadata for repo 'appstream': Cannot prepare internal
    报错原因:     Centos8于2021年年底停止了服务,大家再在使用yum源安装时候,出现下面错误“错误:Failedtodownloadmetadataforrepo‘AppStream’:Cannotprepa......
  • Application.properties文件(持续更新)
    1.通过@Value注入2.通过ConfigurationProperties(prefix="")注入3.数组注入4.map注入1.通过@Value注入oracle.datasource.druid.initial-size=20Value("${oracle.......
  • Pig4cloud密码加密-AES加密key为什么是16位?
    AES算法是一种分组密码算法,有三种不同的密钥长度规模,分别是128比特、192比特和256比特。在pig中前端加密后端这里我们说的16位就是16字节,也就是AES中的128比特。为......
  • 艾思最新案例分享:塔蓝物流app-物流仓储管理系统app. app开发
    塔蓝物流app是一款物流仓储管理app;主要业务范围空运,海运,进出口货物及过境货物的运输代理,包括揽物订舱,仓储(危险品除外),包装,搬运装卸,中转,流通加工,集装箱拼装拆箱(危险品......
  • VBA代码混淆加密保护 VBA代码加密 VBA混淆
    VBA代码助手下载地址本功能一般可结合模块隐藏和工程不可查看一起使用  代码混淆适用于任何vba环境cadvbawordvbacoldrawvba的代码均可以用本工具混淆!VBA模块......
  • uniapp 微信小程序 配置分享朋友和朋友圈
    uniapp微信小程序配置分享朋友和朋友圈首先在小程序中配置微信分享,和微信朋友圈,onShareAppMessage,onShareTimeline这两个API和onLoad同级目录配置在小程序每个......
  • 云小课|使用SQL加密函数实现数据列的加解密
    摘要:数据加密作为有效防止未授权访问和防护数据泄露的技术,在各种信息系统中广泛使用。作为信息系统的核心,GaussDB(DWS)数仓也提供数据加密功能,包括透明加密和使用SQL函数加......
  • log4j2.xml 使用 application.yml 配置的属性
    转自:https://blog.csdn.net/xiaokanfuchen86/article/details/126695797 log4j2.xml 是不归spring管理的,所以也就没法读取到application.yml里面的配置了。解决方......