一个小脚本,用于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
Hunter is a flexible code tracing toolkit.

Overview docs tests package Hunter is a flexible code tracing toolkit, not for measuring coverage, but for debugging, logging, inspection and other ne

Ionel Cristian Mărieș 705 Dec 08, 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
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 08, 2023
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Dec 29, 2022
Trace any Python program, anywhere!

lptrace lptrace is strace for Python programs. It lets you see in real-time what functions a Python program is running. It's particularly useful to de

Karim Hamidou 687 Nov 20, 2022
A toolbar overlay for debugging Flask applications

Flask Debug-toolbar This is a port of the excellent django-debug-toolbar for Flask applications. Installation Installing is simple with pip: $ pip ins

863 Dec 29, 2022
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
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
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Dec 31, 2022
Sweeter debugging and benchmarking Python programs.

Do you ever use print() or log() to debug your code? If so, ycecream, or y for short, will make printing debug information a lot sweeter. And on top o

42 Dec 12, 2022
The official code of LM-Debugger, an interactive tool for inspection and intervention in transformer-based language models.

LM-Debugger is an open-source interactive tool for inspection and intervention in transformer-based language models. This repository includes the code

Mor Geva 110 Dec 28, 2022
Integration of IPython pdb

IPython pdb Use ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better i

Godefroid Chapelle 1.7k Jan 07, 2023
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
Automated bug/error reporting for napari

napari-error-monitor Want to help out napari? Install this plugin! This plugin will automatically send error reports to napari (via sentry.io) wheneve

Talley Lambert 2 Sep 15, 2022
A web-based visualization and debugging platform for NuPIC

Cerebro 2 A web-based visualization and debugging platform for NuPIC. Usage Set up cerebro2.server to export your model state. Then, run: cd static py

Numenta 24 Oct 13, 2021
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
Middleware that Prints the number of DB queries to the runserver console.

Django Querycount Inspired by this post by David Szotten, this project gives you a middleware that prints DB query counts in Django's runserver consol

Brad Montgomery 332 Dec 23, 2022
(OLD REPO) Line-by-line profiling for Python - Current repo ->

line_profiler and kernprof line_profiler is a module for doing line-by-line profiling of functions. kernprof is a convenient script for running either

Robert Kern 3.6k Jan 06, 2023
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