一个小脚本,用于trace so中native函数的调用。

Overview

trace_natives

一个IDA小脚本,获取SO代码段中所有函数的偏移地址,再使用frida-trace 批量trace so函数的调用。

使用方法

1.将traceNatives.py丢进IDA plugins目录中

2.IDA中,Edit-Plugins-traceNatives

IDA输出窗口就会显示如下字眼:

使用方法如下: frida-trace -UF -O C:\Users\Lenovo\Desktop\2021\mt\libmtguard.txt

效果

代码出发点

和朋友在分析android so的时候,他感慨了一句,“唉,要是能捋清整个流程就好了”。确实,搞清楚流向的件挺重要的事,只要代码复杂一些,函数多一些,分支多一些,通过函数指针跳转多一些……不管哪一个多一些,静态分析SO就会变得十分恼人。

得益于Frida布道师@r0ysue以及看雪Android逆向课程的大力推广,近来入门Android逆向的技术人员,个个都用上了Frida以及其工具套件,生产力大大提高。Java层的Objection+Frida一梭子,已经非常快乐的替代了Xposed的位置,而且效率翻了很多倍。而在Native层,情况不太一样,JNItrace是一个非常棒的工具,让JNI操作一览无余。Frida Hook也依然优雅,几行代码就可以根据偏移地址Hook打印输出,但native代码稍微有些复杂的时候,还是觉得有些力不从心,但能不动态调试还是不想用IDA动态调试,因为觉得动态调试比Frida麻烦多了。

所以我就想能不能用frida做一个SO函数的批量Hook或者叫trace,减少一部分使用IDA动态调试的需求。结果发现frida-trace 就可以很好的做这件事,非常nice。

编写过程

想法很简单

  • 使用idapython编写脚本得到代码段中所有函数的偏移地址
  • 编写Frida脚本批量Hook

步骤二遇到了问题,批量Hook几百个函数,APP很容易崩溃,除此之外,打印效果也不算很好。

所以开始想办法优化,一是只打印汇编指令长度大于10条的函数,trace嘛,抓住主线就行了,如果在你的测试环境下还会崩溃,可以修改代码,进一步减少hook的函数数量。 而打印效果不好的问题,我偷了个懒,利用一波官方工具。

Frida-trace是Frida官方的trace工具,它一直在更新发展,越来越强大,但大家对它的关注度一直不太高,其实可以好好挖一下der。

下面例举几种用处

批量HOOK Java方法,支持正则表达式模糊匹配。

frida-trace -UF -j '*!*certificate*/isu'

Hook 所有静态注册的JNI函数

frida-trace -UF -i "Java_*"

Hook 未导出函数

frida-trace -UF -a "libjpeg.so!0x4793c"

我就是利用的最后一种,同时白嫖它的trace和排版。

frida-trace -UF -a "libjpeg.so!0x4793c" -a "libjpeg.so!0x227c" -a "libjpeg.so!0x9193" -a xxx

但是这样做的话,命令实在是太长了,windows上甚至会超过限定的命令行长度,还好Frida-trace提供了-O path 的方式传入一个脚本。除此之外,Frida-trace显示函数地址的方式是“sub_Hook地址”,因为Thumb模式下要+1的缘故,所以Frida trace中“sub_123C”在IDA中显示是“sub_123B”,对照ida分析时要注意一下。

y1s1,虽然实际代码只有了几十行,但效果还真挺好的,希望可以减轻大佬们在逆向分析过程中的工作量。

Owner
白龙O(∩_∩)O
A drop-in replacement for Django's runserver.

About A drop in replacement for Django's built-in runserver command. Features include: An extendable interface for handling things such as real-time l

David Cramer 1.3k Dec 15, 2022
Pyinstrument - a Python profiler. A profiler is a tool to help you optimize your code - make it faster.

Pyinstrument🚴 Call stack profiler for Python. Shows you why your code is slow!

Joe Rickerby 5k Jan 08, 2023
Debugger capable of attaching to and injecting code into python processes.

DISCLAIMER: This is not an official google project, this is just something I wrote while at Google. Pyringe What this is Pyringe is a python debugger

Google 1.6k Dec 15, 2022
一个小脚本,用于trace so中native函数的调用。

trace_natives 一个IDA小脚本,获取SO代码段中所有函数的偏移地址,再使用frida-trace 批量trace so函数的调用。 使用方法 1.将traceNatives.py丢进IDA plugins目录中 2.IDA中,Edit-Plugins-traceNatives IDA输

296 Dec 28, 2022
PINCE is a front-end/reverse engineering tool for the GNU Project Debugger (GDB), focused on games.

PINCE is a front-end/reverse engineering tool for the GNU Project Debugger (GDB), focused on games. However, it can be used for any reverse-engi

Korcan Karaokçu 1.5k Jan 01, 2023
🔥 Pyflame: A Ptracing Profiler For Python. This project is deprecated and not maintained.

Pyflame: A Ptracing Profiler For Python (This project is deprecated and not maintained.) Pyflame is a high performance profiling tool that generates f

Uber Archive 3k Jan 07, 2023
OpenCodeBlocks an open-source tool for modular visual programing in python

OpenCodeBlocks OpenCodeBlocks is an open-source tool for modular visual programing in python ! Although for now the tool is in Beta and features are c

Mathïs Fédérico 1.1k Jan 06, 2023
Graphical Python debugger which lets you easily view the values of all evaluated expressions

birdseye birdseye is a Python debugger which records the values of expressions in a function call and lets you easily view them after the function exi

Alex Hall 1.5k Dec 24, 2022
A powerful set of Python debugging tools, based on PySnooper

snoop snoop is a powerful set of Python debugging tools. It's primarily meant to be a more featureful and refined version of PySnooper. It also includ

Alex Hall 874 Jan 08, 2023
Trace all method entries and exits, the exit also prints the return value, if it is of basic type

Trace all method entries and exits, the exit also prints the return value, if it is of basic type. The apk must have set the android:debuggable="true" flag.

Kurt Nistelberger 7 Aug 10, 2022
Run-time type checker for Python

This library provides run-time type checking for functions defined with PEP 484 argument (and return) type annotations. Four principal ways to do type

Alex Grönholm 1.1k Jan 05, 2023
Silky smooth profiling for Django

Silk Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before prese

Jazzband 3.7k Jan 01, 2023
Inject code into running Python processes

pyrasite Tools for injecting arbitrary code into running Python processes. homepage: http://pyrasite.com documentation: http://pyrasite.rtfd.org downl

Luke Macken 2.7k Jan 08, 2023
A drop-in replacement for Django's runserver.

About A drop in replacement for Django's built-in runserver command. Features include: An extendable interface for handling things such as real-time l

David Cramer 1.3k Dec 15, 2022
Full featured multi arch/os debugger built on top of PyQt5 and frida

Full featured multi arch/os debugger built on top of PyQt5 and frida

iGio90 1.1k Dec 26, 2022
AryaBota: An app to teach Python coding via gradual programming and visual output

AryaBota An app to teach Python coding, that gradually allows students to transition from using commands similar to natural language, to more Pythonic

5 Feb 08, 2022
Trashdbg - TrashDBG the world's worse debugger

The world's worse debugger Over the course of multiple OALABS Twitch streams we

OALabs 21 Jun 17, 2022
printstack is a Python package that adds stack trace links to the builtin print function, so that editors such as PyCharm can link you to the source of the print call.

printstack is a Python package that adds stack trace links to the builtin print function, so that editors such as PyCharm can link to the source of the print call.

101 Aug 26, 2022
Code2flow generates call graphs for dynamic programming language. Code2flow supports Python, Javascript, Ruby, and PHP.

Code2flow generates call graphs for dynamic programming language. Code2flow supports Python, Javascript, Ruby, and PHP.

Scott Rogowski 3k Jan 01, 2023
Sentry is cross-platform application monitoring, with a focus on error reporting.

Users and logs provide clues. Sentry provides answers. What's Sentry? Sentry is a service that helps you monitor and fix crashes in realtime. The serv

Sentry 32.9k Dec 31, 2022