简体   繁体   English

如何与Frida一起获得ANDROID_ID

[英]How to get ANDROID_ID with Frida

The ANDROID_ID is unique in each application in Android. ANDROID_ID在Android中的每个应用程序中都是唯一的。

To get the ANDROID_ID with Java inside Android I amd using this code: 要在Android中使用Java获取ANDROID_ID ,我将使用以下代码:

import android.content.Context;
import android.content.ContentResolver;
import android.provider.Settings;
protected void onCreate(...) {
  context = (Context)this;
  String androidId = Settings.Secure.getString((ContentResolver)context.getContentResolver(), (String)"android_id");
}

But I want to run it inside some other application on my andoird phone. 但我想在我的andoird手机上的其他应用程序中运行它。
I wanted to use Frida for this. 我想用Frida来做这件事。

I am loading my injected script with Python: 我正在用Python加载我注入的脚本:

import frida
device = frida.get_usb_device()
pid = device.spawn(["com.target.app"])
device.resume(pid)
time.sleep(1) #Without it Java.perform silently fails
session = device.attach(pid)
script = session.create_script(open("jsfrida.js").read())
script.load()

#prevent the python script from terminating
raw_input()

But inside my script I don't understand how to call it, this is what I tried: 但在我的脚本中我不明白如何调用它,这就是我尝试过的:

Java.perform(function (){
  console.log("Inside java perform function");
  var ActivityThread = Java.use('android.app.ActivityThread');
  var Context = Java.use('android.content.Context');
  var settings = Java.use('android.provider.Settings.Secure');
  var ctx = Java.cast(ActivityThread.currentApplication().getApplicationContext(), Context);
  //console.log(ctx.getPackageName());
  //console.log(ctx.getContentResolver());
  var androidId = settings.Secure.getString(ctx.getContentResolver(), "android_id");
  console.log(androidId);
  console.log("END");
 });

But it doesn't print the androidId , it only prints: 但它不打印androidId ,它只打印:

Script loaded successfully 
Inside java perform function
  • Secure is inner class so you need to use $ 安全是内部类,所以你需要使用$
  • To get CotentResolver you can invoke getContentResolver without casting. 要获得CotentResolver您可以在不进行强制转换的情况下调用getContentResolver
$ frida -Uf com.app.example --no-pause
     ____
    / _  |   Frida 12.1.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Spawned `com.app.example`. Resuming main thread!                    
[Android::com.app.example]-> 
function getContext() {
  return Java.use('android.app.ActivityThread').currentApplication().getApplicationContext().getContentResolver();
}                                         
function logAndroidId() {
  console.log('[?]', Java.use('android.provider.Settings$Secure').getString(getContext(), 'android_id'));
}
undefined
[Android::com.app.example]-> Java.perform(logAndroidId)
[?] 52d1497b52bf8a11
undefined
[Android::com.app.example]-> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM