使用 Frida 附加到 Dalvik 静态函数以禁用模拟器检测

逆向工程 恶意软件 安卓 仪器仪表
2021-07-02 06:49:37

我在 Frida 上再次出现问题(我使用 Frida 和 Frida-Server for Android x86_64 ver.: 10.6.11),我尝试挂钩一个函数并覆盖它的功能,但由于某种原因我卡住了JS 代码(或 Frida,谁知道这一点?)似乎没有捕捉到我真正需要的功能。

我最近的尝试是在以下 Android 示例 (#Bankbot) 上:https ://koodous.com/apks/6276f23997fff26938b08323322c8ae77b9070ac81851f757c16928f86092f20

现在,这个恶意软件内置了模拟器检测。以下代码静态方法负责检测 Android 模拟器(我与 Frida 一起使用):

    // keitev.ebaziueggzxt.q
    public class q {
    // ....
        // detects emulator
        public static boolean c(Context context) {
        // 
            if (android.os.Debug.isDebuggerConnected()) 
            {
                return true;
            }
            // check hardware related properties of the execution environment
            if (b(context)) 
            {
                return true;
            }
            // create array of used language shorts
            // Region ISOs
            String[] split = "ru|rus|kz|ua|by|az|am|kg|md|tj|tm|uz|us|ca|cs|sk".split("\\|"); // 
            // 
            String[] split2 = "ru|uk|be|az|hy|ky|mo|ro|tg|tk|uz|cs|sk".split("\\|"); // 
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
            // get getNetworkCountryIso()
            if (Arrays.asList(split).contains(j.a(telephonyManager).toLowerCase())) {
                return true;
            }// getSimCountryIso()
            if (Arrays.asList(split).contains(j.b(telephonyManager).toLowerCase())) {
                return true;
            }
            Object obj;
            String language = Locale.getDefault().getLanguage();
            try {
                obj = (String) String.class.getDeclaredMethod("toLowerCase", new Class[0]).invoke(language, new Object[0]);
            } catch (Exception e) {
                String str = language;
            }
            return Arrays.asList(split2).contains(obj);
        }
   // ...
 }

我试图用 frida 做的是找到一个 keitev.ebaziueggzxt.q 的实例:

// DisableEmulatorDetection.js
    Java.perform(function()
            {
                Java.choose('keitev.ebaziueggzxt.q',
                {
                    onMatch:function(keitev_ebaziueggzxt_qInstance)
                    {
                        console.log("[*] Found an instance of keitev.ebaziueggzxt.q" + keitev_ebaziueggzxt_qInstance);
                        var keitev_ebaziueggzxt_qClass = Java.use("keitev.ebaziueggzxt.q");
                        if(typeof keitev_ebaziueggzxt_qClass !== "undefined") 
                        {
                            console.log("keitev_ebaziueggzxt_qClass has been loaded!");
                        }

                        keitev_ebaziueggzxt_qClass.c.implementation = function(arg_ctx)
                        {
                            console.log("keitev_ebaziueggzxt_qClass.c called!");
                            return true;
                        }
                    },
                    onComplete:function()
                    {
                        //console.log("Done looking for keitev.ebaziueggzxt.q!");
                    }
                });
            });

我也尝试使用 keitev_ebaziueggzxt_qClass.c.overload('android.content.Context').implementation。弗里达接受了它,但它什么也没做。据我所知,静态方法不需要从实例化对象中调用,但 Frida 不会应用更改,或者如果应用了更改,它对正在执行的应用程序没有影响。

我尝试使用以下方法执行代码:

蟒蛇代码:

# bot_instrument.py
import frida
import time

device = frida.get_usb_device()
pid = device.spawn(["keitev.ebaziueggzxt"])
device.resume(pid)
time.sleep(1)
session = device.attach(pid)
script = session.create_script(open('DisableEmulatorDetection.js').read())
script.load()

# stop the script from exiting
input()

并在生成恶意软件时加载脚本:

frida -U -l DisableEmulatorDetection.js keitev.ebaziueggzxt

谁能向我解释为什么我不能挂钩keitev_ebaziueggzxt_qClass.c静态辅助函数并提供解决方案?我假设我的方法可能存在两个问题:

  1. 注入的代码不会在我认为应该执行时执行。
  2. 我可能错误地钩住了这个函数。

我非常渴望听到在 Android 上使用 Frida 的任何人的答案。

0个回答
没有发现任何回复~