Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android hook方案调研 #4

Open
summer506hai opened this issue Jan 26, 2023 · 2 comments
Open

Android hook方案调研 #4

summer506hai opened this issue Jan 26, 2023 · 2 comments

Comments

@summer506hai
Copy link
Owner

summer506hai commented Jan 26, 2023

frida hook

  1. Windows 安装 frida
    pip install frida
    pip install frida-tools

  2. 安卓安装
    adb 连接后输入以下命令查看CPU型号
    getprop ro.product.cpu.abi
    image

  3. https://github.com/frida/frida/releases 中下载对应型号且与电脑安装Frida版本一致的Frida-server版本
    image

  4. 下载完成后将其解压出来,然后重命名为frida-server
    然后通过adb将其上传到手机 adb push .\frida-server /data/local/tmp
    然后再给其授予777权限 chmod 777 frida-server

  5. 在手机端启动(设备需root) ./frida-server

image

  1. 然后在windows上执行 Frida-ps -U
    如下图所示,则表示安装成功

image

  1. 自己写一个apk
  • MainActivity中,每隔5秒打印 50 + 30 的值
    image
    image

  • 编写js hook掉 fun计算的结果
    image

  • 编写python脚本进行注入

import time
import frida

device = frida.get_usb_device()
pid = device.spawn(["com.example.myapplication"])
device.resume(pid)
time.sleep(1)  # Without it Java.perform silently fails
session = device.attach(pid)
with open("s1.js") as f:
    script = session.create_script(f.read())
script.load()

# prevent the python script from terminating
input()

image

  • ClickActivity中,点击button,弹出 toast提示

image

  • 编写js hook掉 toast弹窗的内容
Java.perform(
    function () {
      // 获得Toast组件
        var Toast = Java.use('android.widget.Toast')
        var makeText = Toast.makeText
        var String = Java.use('java.lang.String')
        makeText.overload('android.content.Context', 'java.lang.CharSequence', 'int').implementation=function (context,content,time) {
            var hookContent = String.$new('hook hook')
            return this.makeText(context,hookContent,time)
        }
    }
)
  • 编写python脚本进行注入
import time
import frida

device = frida.get_usb_device()
pid = device.spawn(["com.example.myapplication"])
device.resume(pid)
time.sleep(1)  # Without it Java.perform silently fails
session = device.attach(pid)
with open("s3.js") as f:
    script = session.create_script(f.read())
script.load()

# prevent the python script from terminating
input()
@summer506hai
Copy link
Owner Author

summer506hai commented Jan 26, 2023

virtual xposed

import android.util.Log;
import android.view.View;

import android.widget.Button;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        Log.i("hnzhu2","MainActivity");
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, toastMessage(), Toast.LENGTH_SHORT).show();
            }
        });
    }
    public String toastMessage() {
        return "我未被劫持";
    }
}

运行该apk安装到设备上

  • 编写hook程序,新建一个项目 HookMyApplication :

image

  • 新建 HookTest类,并实现IXposedHookLoadPackage接口

image

  • 在src/main下新建一个Assets Folder

image

  • 在AndroidManifest.xml中指定模块的名称
    image

  • 利用VirtualXposed将 待HOOK应用 和 编写的HOOK模块 添加到VirtualXposed中

image
image
image
image
image

  • 重启 VirtualXposed
  • 打开 MyApplication,点击按钮,弹出,你已被劫持 的弹窗
    image

@summer506hai
Copy link
Owner Author

summer506hai commented Jan 26, 2023

whale 框架

项目地址: https://github.com/asLody/whale

  1. 把whale项目里的java文件夹的代码复制到自己的项目中
  2. 复制 built/Android 下所需的abi到自己项目的src/main/jniLibs下

image

  1. 新建一个类Test,写一个测试的方法get,用于hook测试

image

  1. 新建一个hook的类,用于写hook的方法

image

  1. 将hook在程序启动的时候执行,在MainActivity的onCreate方法里执行,只能在app内进行hook,无法hook第三方应用

image

hook第三方应用

asLody/whale#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant