【愚公系列】2023年04月 攻防世界-MOBILE(ill-intentions)


前言

下面介绍两个反编译工具

  • jadx是一个用于反编译Android APK文件的开源工具,静态反编译,查找索引功能强大
  • jeb和IDA很像,属于动态调试,可以看java汇编也可以生成伪代码,还可以动态attach到目标调试

对于so文件的逆向工具选择

  • IDA逆向工具是一款反汇编器,被广泛应用于软件逆向工程领域,能够反汇编各种不同平台的二进制程序代码,并还原成可读的汇编代码。

Objection是一款移动设备运行时漏洞利用工具,该工具由Frida驱动,可以帮助研究人员访问移动端应用程序,并在无需越狱或root操作的情况下对移动端应用程序的安全进行评估检查。

安装命令

pip3 install objection 

frida是一款便携的、自由的、支持全平台的hook框架,可以通过编写JavaScript、Python代码来和frida_server端进行交互

frida的安装可以参考:https://www.jianshu.com/p/60cfd3f6afde

一、ill-intentions

1.题目

在这里插入图片描述

2.答题

1、源码分析

jadx打开文件
在这里插入图片描述

public class MainActivity extends Activity {
    
    
    @Override // android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(getApplicationContext());
        tv.setText("Select the activity you wish to interact with.To-Do: Add buttons to select activity, for now use Send_to_Activity");
        setContentView(tv);
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.ctf.INCOMING_INTENT");
        Send_to_Activity receiver = new Send_to_Activity();
        registerReceiver(receiver, filter, Manifest.permission._MSG, null);
    }
}

大概就是动态注册了一个广播接收器,看看接收器代码
在这里插入图片描述

package com.example.application;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/* loaded from: classes.dex */
public class Send_to_Activity extends BroadcastReceiver {
    
    
    @Override // android.content.BroadcastReceiver
    public void onReceive(Context context, Intent intent) {
    
    
        String msgText = intent.getStringExtra("msg");
        if (msgText.equalsIgnoreCase("ThisIsTheRealOne")) {
    
    
            context.startActivity(new Intent(context, ThisIsTheRealOne.class));
        } else if (msgText.equalsIgnoreCase("IsThisTheRealOne")) {
    
    
            context.startActivity(new Intent(context, IsThisTheRealOne.class));
        } else if (msgText.equalsIgnoreCase("DefinitelyNotThisOne")) {
    
    
            context.startActivity(new Intent(context, DefinitelyNotThisOne.class));
        } else {
    
    
            Toast.makeText(context, "Which Activity do you wish to interact with?", 1).show();
        }
    }
}

广播接收就跳转到各个activity,直接使用objecttion来实现直接跳到对应的activity

在这里插入图片描述

三个类逻辑差不多相同,只是调用的native方法不同,关系如下

DefinitelyNotThisOne:definitelyNotThis
sThisTheRealOne:perhapsThis
ThisIsTheRealOne:orThat

2、hook实操(Native hook)

objection -g com.example.hellojni explore
android intent launch_activity com.example.application.IsThisTheRealOne

在这里插入图片描述
hook Native的脚本

//tt.js
//出自https://blog.csdn.net/Palmer9/article/details/122464683
//别问脚本什么意思,frida脚本还不太会写
function main() {
    
    
    function getjstring(jstr) {
    
    
        return Java.vm.getEnv().getStringUtfChars(jstr, null).readCString();
    }
    Java.perform(function () {
    
    
        var so_addr = Module.findBaseAddress("libhello-jni.so");
        var perhapsThis_addr = Module.findExportByName("libhello-jni.so", "Java_com_example_application_IsThisTheRealOne_perhapsThis");
        console.log("perhapsThis_addr", perhapsThis_addr);
        Interceptor.attach(perhapsThis_addr, {
    
    
            onEnter: function (args) {
    
    
                console.log("perhapsThis_args:[1]", getjstring(args[2]), "\n    [2]", getjstring(args[3]), "\n    [3]", getjstring(args[4]), "\n");
            },
            onLeave: function (retval) {
    
    
                console.log("perhapsThis_result:", getjstring(retval));
            },
        });

        Interceptor.attach(Module.findExportByName("libhello-jni.so", "Java_com_example_application_ThisIsTheRealOne_orThat"), {
    
    
            onEnter: function (args) {
    
    
                console.log("orThat_args:[1]", getjstring(args[2]), "\n    [2]", getjstring(args[3]), "\n    [3]", getjstring(args[4]), "\n");
            },
            onLeave: function (retval) {
    
    
                console.log("orThat_result:", getjstring(retval));
            },
        });

        Interceptor.attach(Module.findExportByName("libhello-jni.so", "Java_com_example_application_DefinitelyNotThisOne_definitelyNotThis"), {
    
    
            onEnter: function (args) {
    
    
                console.log("definitelyNotThis_args:[1]", getjstring(args[2]), "\n    [2]", getjstring(args[3]), "\n");
            },
            onLeave: function (retval) {
    
    
                console.log("definitelyNotThis_result:", getjstring(retval));
            },
        });
    });
}
setImmediate(main);

在这里插入图片描述

3、hook实操(java hook)

因为没有修改apk包,触发按钮的Intent显示不了,用objection手动开启,找到相对应的进程注入

在这里插入图片描述
直接Objection注入

objection -g com.example.hellojni explore
>>CLI中输入
android intent launch_activity com.example.application.IsThisTheRealOne
android hooking watch class_method android.content.Intent.putExtra --dump-return --dump-args --dump-backtra
ce

在这里插入图片描述
或者用GDA软件也行

猜你喜欢

转载自blog.csdn.net/aa2528877987/article/details/130278419