Chinaunix首页 | 论坛 | 博客
  • 博客访问: 504445
  • 博文数量: 184
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1172
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-21 13:40
个人简介

技术改变命运

文章分类

全部博文(184)

文章存档

2020年(16)

2017年(12)

2016年(156)

我的朋友

分类: Android平台

2020-08-09 23:30:20

在这里插入图片描述

Frida输出打印

console

  1. setTimeout(function (){
  2. Java.perform(function (){
  3. console.log("n[*] enumerating classes...");
  4. console.log("Frida version:"+Frida.version);
  5. console.log("Frida heapsize:"+Frida.heapSize);
  6. console.log("Script runtime:"+Script.runtime);
  7. console.warn("warn");
  8. console.error("error");
  9. Java.choose("android.bluetooth.BluetoothDevice",{
  10. onMatch: function (instance){
  11. console.log("[*] "+" android.bluetooth.BluetoothDevice instance found"+" :=> '"+instance+"'");
  12. // console.log(Java.cast(instance,Java.use("android.bluetooth.BluetoothDevice") ).getName());
  13. console.log(instance.getName());
  14. // bluetoothDeviceInfo(instance);
  15. },
  16. onComplete: function() { console.log("[*] -----");}
  17. });
  18. });
  19. });

通过下面的命令运行程序

  1. frida -U -l hello.js android.process.media debug --runtime=v8

在对console.log,console.warn,console.error进行了介绍,望文也可生义。 在这里插入图片描述

Frida.version: property containing the current Frida version, as a string.

Frida.heapSize: dynamic property containing the current size of Frida’s private heap, shared by all scripts and Frida’s own runtime. This is useful for keeping an eye on how much memory your instrumentation is using out of the total consumed by the hosting process.

Script.runtime: string property containing the runtime being used. Either DUK or V8.

hexdump

hexdump(target[, options]): generate a hexdump from the provided ArrayBuffer or NativePointer target, optionally with options for customizing the output.

添加如下的代码:

  1. var libc = Module.findBaseAddress('libc.so');
  2. console.log(hexdump(libc, {
  3. offset: 0,
  4. length: 64,
  5. header: true,
  6. ansi: true
  7. }));

运行: 在这里插入图片描述

send

send(message[, data]): send the JavaScript object message to your Frida-based application (it must be serializable to JSON).

  1. # -*- coding: utf-8 -*-
  2. import frida
  3. import sys
  4. def on_message(message, data):
  5. if message['type'] == 'send':
  6. print("[*] {0}".format(message['payload']))
  7. else:
  8. print(message)
  9. jscode = """
  10. Java.perform(function ()
  11. {
  12. var jni_env = Java.vm.getEnv();
  13. console.log(jni_env);
  14. send(jni_env);
  15. });
  16. """
  17. process = frida.get_usb_device().attach('android.process.media')
  18. script = process.create_script(jscode)
  19. script.on('message', on_message)
  20. script.load()
  21. sys.stdin.read()

通过下面的结果可以看出,send输出的是json格式。 在这里插入图片描述

Frida变量类型

API 含义
new Int64(v) create a new Int64 from v
new UInt64(v) create a new UInt64 from v
NativePointer creates a new NativePointer from the string s
wrap(address, size) creates an ArrayBuffer backed by an existing memory region
new NativeFunction(address, returnType, argTypes[, abi]) create a new NativeFunction to call the function at address
new NativeCallback(func, returnType, argTypes[, abi]) create a new NativeCallback implemented by the JavaScript function func
new SystemFunction(address, returnType, argTypes[, abi]) just like NativeFunction, but also provides a snapshot of the thread’s last error status
ptr(s) short-hand for new NativePointer(s)
NULL short-hand for ptr("0")

添加如下代码:

  1. console.log("new Int64(1):"+new Int64(1));
  2. console.log("new UInt64(1):"+new UInt64(1));
  3. console.log("new NativePointer(0xEC644071):"+new NativePointer(0x123456));
  4. console.log("new ptr('0xEC644071'):"+new ptr(0x123456));
  5. console.log("null point:"+ptr('0'));

运行结果如下: 在这里插入图片描述 对于 Int64一些简单的运算

  1. console.log("8888 + 1:"+new Int64("8888").add(1));
  2. //8888 - 1 = 8887
  3. console.log("8888 - 1:"+new Int64("8888").sub(1));
  4. //8888 << 1 = 4444
  5. console.log("8888 << 1:"+new Int64("8888").shr(1));
  6. //8888 == 22 = 1 1是false
  7. console.log("8888 == 22:"+new Int64("8888").compare(22));
  8. //转string
  9. console.log("8888 toString:"+new Int64("8888").toString());

注释写的很清楚了: 在这里插入图片描述

RPC远程调用

Empty object that you can either replace or insert into to expose an RPC-style API to your application. The key specifies the method name and the value is your exported function.

  1. # -*- coding: utf-8 -*-
  2. import frida
  3. import sys
  4. def on_message(message, data):
  5. if message['type'] == 'send':
  6. print("[*] {0}".format(message['payload']))
  7. else:
  8. print(message)
  9. jscode = """
  10. Java.perform(function ()
  11. {
  12. var jni_env = Java.vm.getEnv();
  13. console.log(jni_env);
  14. send(jni_env);
  15. });
  16. rpc.exports = {
  17. add: function (a, b) {
  18. return a + b;
  19. },
  20. sub: function (a, b) {
  21. return new Promise(function (resolve) {
  22. setTimeout(function () {
  23. resolve(a - b);
  24. }, 100);
  25. });
  26. }
  27. };
  28. """
  29. process = frida.get_usb_device().attach('android.process.media')
  30. script = process.create_script(jscode)
  31. script.on('message', on_message)
  32. script.load()
  33. print(script.exports.sub(2, 3))
  34. process.detach()

script.on('message', on_message) is used to monitor for any messages from the injected process, JavaScript side. 在这里插入图片描述

Process

通过如下的代码获取进程相关信息:

  1. console.log("目标进程的PID:"+Process.id);
  2. console.log("调试器是否附加到目标进程:"+Process.isDebuggerAttached())
  3. //枚举进程加载的模块
  4. var process_Obj_Module_Arr = Process.enumerateModules();
  5. for(var i = 0; i < process_Obj_Module_Arr.length; i++) {
  6. console.log("",process_Obj_Module_Arr[i].name);
  7. }
  8. //枚举当前所有的线程
  9. var enumerateThreads = Process.enumerateThreads();
  10. for(var i = 0; i < enumerateThreads.length; i++) {
  11. console.log("");
  12. console.log("id:",enumerateThreads[i].id);
  13. console.log("state:",enumerateThreads[i].state);
  14. console.log("context:",JSON.stringify(enumerateThreads[i].context));
  15. }
  16. //this thread’s OS-specific id as a number
  17. console.log("this thread’s OS-specific id as a number:"+Process.getCurrentThreadId());

运行上面的程序,可以获取到进程相关的信息。 在这里插入图片描述 这里说一下线程: Process.enumerateThreads():枚举当前所有的线程,返回包含以下属性的对象数组:

  • id: OS-specific id
  • state: string specifying either running, stopped, waiting, uninterruptible or halted
  • context: object with the keys pc and sp, which are NativePointer objects specifying EIP/RIP/PC and ESP/RSP/SP, respectively, for ia32/x64/arm. Other processor-specific keys are also available, e.g. eax, rax, r0, x0, etc.

完成代码

  1. setTimeout(function (){
  2. Java.perform(function (){
  3. console.log("n[*] enumerating classes...");
  4. console.log("Frida version:"+Frida.version);
  5. console.log("Frida heapsize:"+Frida.heapSize);
  6. console.log("Script runtime:"+Script.runtime);
  7. console.warn("warn");
  8. console.error("error");
  9. Java.choose("android.bluetooth.BluetoothDevice",{
  10. onMatch: function (instance){
  11. console.log("[*] "+" android.bluetooth.BluetoothDevice instance found"+" :=> '"+instance+"'");
  12. // console.log(Java.cast(instance,Java.use("android.bluetooth.BluetoothDevice") ).getName());
  13. console.log(instance.getName());
  14. // bluetoothDeviceInfo(instance);
  15. },
  16. onComplete: function() { console.log("[*] -----");}
  17. });
  18. var libc = Module.findBaseAddress('libc.so');
  19. console.log(hexdump(libc, {
  20. offset: 0,
  21. length: 64,
  22. header: true,
  23. ansi: true
  24. }));
  25. console.log("");
  26. console.log("new Int64(1):"+new Int64(1));
  27. console.log("new UInt64(1):"+new UInt64(1));
  28. console.log("new NativePointer(0xEC644071):"+new NativePointer(0x123456));
  29. console.log("new ptr('0xEC644071'):"+new ptr(0x123456));
  30. console.log("null point:"+ptr('0'));
  31. console.log("");
  32. //8888 + 1 = 8889
  33. console.log("8888 + 1:"+new Int64("8888").add(1));
  34. //8888 - 1 = 8887
  35. console.log("8888 - 1:"+new Int64("8888").sub(1));
  36. //8888 << 1 = 4444
  37. console.log("8888 << 1:"+new Int64("8888").shr(1));
  38. //8888 == 22 = 1 1是false
  39. console.log("8888 == 22:"+new Int64("8888").compare(22));
  40. //转string
  41. console.log("8888 toString:"+new Int64("8888").toString());
  42. console.log("目标进程的PID:"+Process.id);
  43. console.log("调试器是否附加到目标进程:"+Process.isDebuggerAttached())
  44. //枚举进程加载的模块
  45. var process_Obj_Module_Arr = Process.enumerateModules();
  46. for(var i = 0; i < process_Obj_Module_Arr.length; i++) {
  47. console.log("",process_Obj_Module_Arr[i].name);
  48. }
  49. //枚举当前所有的线程
  50. var enumerateThreads = Process.enumerateThreads();
  51. for(var i = 0; i < enumerateThreads.length; i++) {
  52. console.log("");
  53. console.log("id:",enumerateThreads[i].id);
  54. console.log("state:",enumerateThreads[i].state);
  55. console.log("context:",JSON.stringify(enumerateThreads[i].context));
  56. }
  57. //this thread’s OS-specific id as a number
  58. console.log("this thread’s OS-specific id as a number:"+Process.getCurrentThreadId());
  59. });
  60. });

公众号

更多Frida相关内容,欢迎关注我的公众号:无情剑客。 在这里插入图片描述

阅读(1551) | 评论(0) | 转发(0) |
0

上一篇:Frida入门

下一篇:Frida之API使用(2)

给主人留下些什么吧!~~