Frida 操作参数 - Android

逆向工程 安卓 爪哇 javascript apk
2021-06-30 00:46:05

我试图学习如何使用 Frida 来检测 android 应用程序,只是为了个人兴趣。

到目前为止,我已经成功地使用物理 android 平板电脑设置了我的环境,并且我可以在 Frida 的网站上成功运行该示例除了更改方法中的变量之外,我还想更改传递给该方法的参数。我知道如何使用 Xposed 做到这一点,但我不确定使用 Frida。

一般问题:如何使用 Frida 操作传递给方法的参数?Frida 有哪些好的文档和示例来源?


更具体的问题:

我想要一些更具挑战性的东西,所以我转向了 Snapchat。我的目标是模拟SnapPrefs Xposed 模块的速度欺骗功能,因为这看起来很简单,并且可以在应用程序中轻松看到其效果。我查看了 SnapPrefs 源,发现我需要挂钩“adL”类并更改传递给“a”方法的参数。

APK中方法的代码是:

public final void a(float paramFloat) { .... }

我使用此 JavaScript 代码是为了在该方法处于活动状态时将“速度显示”打印到屏幕上。

Java.perform(function () {
// Function to hook is defined here
var SpeedometerView = Java.use('adL');

// Whenever button is clicked
SpeedometerView.a.overload('float').implementation = function (v) {
    // Show a message to know that the function got called
    send('Speed showing');

    // Call the original onClick handler
    this.a.overload('float');
};
});

因此,从这里开始:操纵 pa​​ramFloat 参数的最简单方法是什么?

1个回答

如果我正确理解您的问题,您想更改v内部函数中的参数 , 对?如果是这种情况,您就已经可以访问v内部函数中参数了。所以你可以做的是这样的:

Java.perform(function () {
// Function to hook is defined here
var SpeedometerView = Java.use('adL');

// Whenever button is clicked
SpeedometerView.a.overload('float').implementation = function (v) {
    // Show a message to know that the function got called
    send('Speed showing');
    old_param_value = v;
    new_param_value = 100.00;
    // Call the original onClick handler
    x = this.a(new_param_value);
};
});

此外,假设您想将 param 的值从任何退出更改为 100.00 return x 如果需要。

但是,如果您希望在运行时动态执行此操作,例如基于用户输入等,我不知道该怎么做。事实上,如果有人回答这个问题,我会留意它!

事实上,我尝试过这样的事情:

s4.js

Java.perform(
 function()
 {
   var item = Java.use("java.util.Random");
   console.log("Found random loaded");
   item.nextInt.overload("int").implementation = function(a)
   {
     var ret = this.nextInt(a);
     send("[*] The random no " + ret.toString());
     recv(function (received_json_object) {
           cheat_num = received_json_object.my_data
           console.log("[*] Cheated bot number received " + cheat_num);            
       }).wait();
     return cheat_num;
   }
 }
);

not_working.py

import time
import frida

def my_message_handler(message, payload):
   print message.get('payload')

   if message["type"] == "send":
       print "in here"      
       place_bot_chic_at = raw_input("Give the index where bot chicken should be placed ")
       print "bot chick will be placed at " + str(place_bot_chic_at)
       # script.post({"my_data": 7331}) # This works perfectly fine.
       script.post({"my_data": place_bot_chic_at}) # This gives error as :
       print "Bot chick position sent"

device = frida.get_device_manager().enumerate_devices()[-1]
pid = device.spawn(["chicken.wars.main"])
device.resume(pid)
time.sleep(1)  
session = device.attach(pid)
with open("s4.js") as f:
   jss = f.read()
   script = session.create_script(jss)

script.on("message", my_message_handler) #register the message handler
script.load()
raw_input()

但是当我运行那个 python 时,我收到以下错误:

lib/python2.7/site-packages/frida/core.py", line 298, in _on_message
  callback(message, data)
File "not_working.py", line 12, in my_message_handler
  script.post({"my_data": place_bot_chic_at}) # This gives error as :
AttributeError: 'NoneType' object has no attribute 'post'

另外,奇怪的是,在in here打印字符串后的那一刻,我期待接下来执行用户输入行。但这不会发生,除非我按回车键。一旦我按下回车键,用户输入行place_bot_chic_at = raw_input("Give the index where bot chicken should be placed ")就会被执行。我给出一个值并输入,这就是发生上述错误的时候。我不知道出了什么问题。如果有人这样做,请帮助理解我哪里出错了。