摊手,缺cb,从博客搬点旧文,大伙看看图一乐就行,都是水文,只发布过于个人博客,算是原创吧(app版本已经更新,文中方法不适用,只是作为上手unidbg的入门case)
看了四哥的帖子,有点手痒,就来自己试一试分析下最右的协议
抓包与初步分析
可以看到在登录页面发送的请求中,有一个sign值,在post的字段中,有手机号,密码的md5值,以及设备的部分信息,具体情况马上继续分析,拖入jadx中,无壳无混淆(只能挑这种软柿子捏了),搜索sign,找到生成签名的java层函数
可以看到,sign主要来自于native层的generateSign函数,先不分析so,继续摸索摸索
可以看出只是对密码进行了md5操作
各个字段的具体含义也知道了,在分析过程中,只需要关心每次登陆过程中变化的值,先写段hook代码,将NetCrypto类的a函数的参数与运算结果hook出来,确认下结果
可以看到,在两次发送登陆请求包的过程中,主要的不同是h_ts字段,这个字段的值来源于currentTimeMillis,别的字段在登录过程中目前是不变的,经过验证,我们确定了这个函数就是签名生成的函数
public class RightHook implements IXposedHookLoadPackage{
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook()
{ @Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
ClassLoader cl = ((Context)param.args[0]).getClassLoader();
Class<?> hookclass = null;
try {
hookclass = cl.loadClass("cn.xiaochuankeji.netcrypto.NetCrypto");
}
catch (Exception e)
{
Log.e("123", "寻找报错", e);
return;
}
Log.i("123", "寻找成功");
XposedHelpers.findAndHookMethod(hookclass, "a",
String.class,
String.class,
new XC_MethodHook()
{ //进行hook操作
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
XposedBridge.log("xposed str :" + param.args[0]);
XposedBridge.log("xposed str2 :" + param.args[1]);
}
});
XposedHelpers.findAndHookMethod(hookclass, "a",
String.class,
String.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("xposed getSign :"+param.getResult());
}
});
}
});
}
}
Hook代码也没什么好说的,主要就是这个app属于multiDex,需要先hook attach拿到上下文才能hook到目标函数,接下来就可以去so层分析函数了
分析so
将app解压并且取出里面的libnet-crypto.so并拖入ida分析,直接去看jniOnload函数
没有看到registNative的参数,可以直接去汇编里观察下
注册的generateSign函数地址为4976
初步把加密算法的核心部分定位在sub50,算法的具体分析可以看四哥的帖子,这里主要还是练手下unicorn
x右的库不仅仅注册了一个生成签名的算法,而且注册了一个native_init函数进行了初始化,在调用getsign算法前还是得先调用下初始化函数
package com.com.zuiyou;
import cn.banny.unidbg.LibraryResolver;
import cn.banny.unidbg.Module;
import cn.banny.unidbg.arm.ARMEmulator;
import cn.banny.unidbg.file.FileIO;
import cn.banny.unidbg.file.IOResolver
import cn.banny.unidbg.linux.android.AndroidARMEmulator;
import cn.banny.unidbg.linux.android.AndroidResolver;
import cn.banny.unidbg.linux.android.dvm.*;
import cn.banny.unidbg.memory.Memory;
import org.apache.log4j.Level;
import java.io.File;
public class Nmsl extends AbstractJni implements IOResolver {
private static LibraryResolver createLibraryResolver() {
return new AndroidResolver(23);
}
@Override
public FileIO resolve(File workDir, String pathname, int oflags) {
return null;
}
private static ARMEmulator createARMEmulator() {
return new AndroidARMEmulator("com.zuiyou");
}
private static final String APK_PATH = "src/test/resources/app/zuiyou.apk";
private final ARMEmulator emulator;
private final VM vm;
private final Module module;
private final DvmClass Nmsl;
private Nmsl() throws IOException {
emulator = createARMEmulator();
emulator.getSyscallHandler().addIOResolver(this);
System.out.println("== init ===");
final Memory memory = emulator.getMemory();
memory.setLibraryResolver(createLibraryResolver());
memory.setCallInitFunction();
vm = emulator.createDalvikVM(new File(APK_PATH));
vm.setJni(this);
DalvikModule dm = vm.loadLibrary("net_crypto", false);
dm.callJNI_OnLoad(emulator);
module = dm.getModule();
Nmsl = vm.resolveClass("cn/xiaochuankeji/netcrypto/NetCrypto");
}
//析构函数
private void destroy() throws IOException {
emulator.close();
System.out.println("destroy");
}
//主函数
public static void main(String[] args) throws Exception {
Nmsl test = new Nmsl();
test.GetSign();
test.destroy();
}
private void GetSign() throws IOException {
//申请参数空间
String str="{\"size\":\"big\",\"version\":0,\"h_av\":\"4.1.6\",\"h_dt\":0,\"h_os\":22,\"h_app\":\"zuiyou\",\"h_model\":\"vivo v3\",\"h_did\":\"865166029899062_00:81:81\",\"h_nt\":1,\"h_m\":172480973,\"h_ch\":\"zuiyou\",\"h_ts\":1577500409477,\"token\":\"T2K2NvcwR06ehMlhs2CXF-xHH5Eks5Haq0WiU-KKv22mArxaNmXoWiycBZdigmZJE7h3k\"}";
//调用函数generateSign(Ljava/lang/String;)Ljava/lang/String;
Nmsl.callStaticJniMethod(emulator,"native_init()V");
Number ret =Nmsl.callStaticJniMethod(emulator,"generateSign([B)Ljava/lang/String;",
vm.addLocalObject(new ByteArray(str.getBytes())),23);
long hash = ret.intValue() & 0xffffffffL;
StringObject obj = vm.getObject(hash);
//vm.deleteLocalRefs();
System.out.println(obj.getValue());
}
}
最终结果
![http://static.zybuluo.com/Disp41r/uxq0ikad4cuxmdwyv343p1l2/image_1dt56v1gee9p19t8k2s1nd7h2am.png]()