Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
Huanwei Liu edited this page Aug 8, 2017 · 1 revision

利用Frida修改微信步数

环境

  • Ubuntu 16.04
  • 小米6 Android 7.1.1(Root权限)
  • 微信 6.5.10

步骤

安装frida

sudo pip -H install frida

frida rellease下载frida-server-xx.x.xx-android-arm64.xz。连接手机,开启USB调试,将解压后的frida-server传到手机并运行。

xz -d frida-server-10.3.14-android-arm64.xz
adb push frida-server-10.3.14-android-arm64 /data/local/tmp
adb shell
su
cd /data/local/tmp
./frida-server-10.3.14-android-arm64

运行stepchanger.py

python stepchanger.py

现在微信步数应该已经改到40000了

原理

Sensor, SensorEvent, SensorEventListener

手机上有很多传感器,例如加速度传感器,磁场传感器等。在有step counter sensor的手机上,手机是根据step counter sensor计步的。这个sensor的值在手机重启时会清零。详见android.hardware.Sensor

App通过 public void onSensorChanged(SensorEvent event)从系统获得Sensor的数据。详见android.hardware.SensorManager

要获取Sensor的数据,首先实现SensorEventListener接口,然后实现函数onSensorChanged,最后通过SensorManager注册,让这个类监听某一个Sensor的事件。

SensorEvent详见android.hardware.SensorEvent

Hook

知道了原理之后,就是如何找到onSensorChanged函数,然后Hook的问题。首先用apktool反编译。微信中注册了不止一个SensorEventListener,所以简单的搜索onSensorChanged会找到很多个,还需要根据其他的字符串判断一下那个才是step counter sensor对应的那个。最终可以找到smali_classes3/com/tencent/mm/plugin/sport/c/j.smali(不同的微信版本可能不一样?)。

找到之后就可以Hook了。

.class public final Lcom/tencent/mm/plugin/sport/c/j;
.super Ljava/lang/Object;
.source "SourceFile"

# interfaces
.implements Landroid/hardware/SensorEventListener;


# static fields
.field private static qFA:J

.field private static qFB:J

.field private static qFC:J

.field private static qFD:J

.field private static qFw:J

.field private static qFx:J

.field private static qFy:J

.field private static qFz:J

com/tencent/mm/plugin/sport/c/j.smali这个类有很多数据成员,暂时还不知道是什么意思,可以通过两种方法,一是通过Hook把这些值打印出来找一下规律,还有就是通过代码中的Log字符串判断每个数据成员代表的是什么。

例如有这样的字符串

const-string/jumbo v4, "MicroMsg.Sport.SportStepDetector"

const-string/jumbo v5, "currentVar: beginOfToday %d saveTodayTime %d preSensorStep %d currentTodayStep %d lastSaveSensorStep %d lastSaveStepTime %d preSysStepTime %d preSensorNanoTime %d"

通过分析可以知道qFy代表的是当前今日步数,其他数据成员的意义可以见smali代码的注释。

现在可以用Frida来Hook了。

Java.perform(function () {
    var cj = Java.use('com.tencent.mm.plugin.sport.c.j');

    cj.onSensorChanged.implementation = function(sensorEvent) {

        console.log('***** onSensorChanged *****');
        console.log("sensorEvent values: " + sensorEvent.values.value + ", timestamp: " + sensorEvent.timestamp.value);
        console.log('qFA: ' + this.qFA.value + ', saveTodayTime');
        console.log('qFB: ' + this.qFB.value + ', lastSaveStepTime');
        console.log('qFC: ' + this.qFC.value + ', preSysStepTime');
        console.log('qFD: ' + this.qFD.value + ', preSensorNanoTime');
        console.log('qFw: ' + this.qFw.value);
        console.log('qFx: ' + this.qFx.value + ', preSensorStep');
        console.log('qFy: ' + this.qFy.value + ', currentTodayStep');
        console.log('qFz: ' + this.qFz.value + ', lastSaveSensorStep');

        this.qFy.value = 40000;
        sensorEvent.values.value = [40000, 0];
        this.onSensorChanged(sensorEvent);
    };

    cj.bkZ.implementation = function() {
        console.log('***************** bkZ');
        this.bkZ();
    };

    cj.bla.implementation = function() {
        console.log('***************** bla');
        this.bla();
    };
});

以上代码是stepchanger.py的一部分可以讲微信步数改为40000步。Frida的一些使用方法可以自己在网上找教程,我也是新手。

附件

Clone this wiki locally