一个小脚本,用于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
一个小脚本,用于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
Voltron is an extensible debugger UI toolkit written in Python.

Voltron is an extensible debugger UI toolkit written in Python. It aims to improve the user experience of various debuggers (LLDB, GDB, VDB an

snare 5.9k Dec 30, 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
Sane color handling of osx's accent and highlight color from the commandline

osx-colors Sane command line color customisation for osx, no more fiddling about with defaults, internal apple color constants and rgb color codes Say

Clint Plummer 8 Nov 17, 2022
🔥 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
An improbable web debugger through WebSockets

wdb - Web Debugger Description wdb is a full featured web debugger based on a client-server architecture. The wdb server which is responsible of manag

Kozea 1.6k Dec 09, 2022
Tracing instruction in lldb debugger.Just a python-script for lldb.

lldb-trace Tracing instruction in lldb debugger. just a python-script for lldb. How to use it? Break at an address where you want to begin tracing. Im

156 Jan 01, 2023
A simple rubber duck debugger

Rubber Duck Debugger I found myself many times asking a question on StackOverflow or to one of my colleagues just for finding the solution simply by d

1 Nov 10, 2021
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
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
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
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
pdb++, a drop-in replacement for pdb (the Python debugger)

pdb++, a drop-in replacement for pdb What is it? This module is an extension of the pdb module of the standard library. It is meant to be fully compat

1k Jan 02, 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 31, 2022
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
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
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
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
An x86 old-debug-like program.

An x86 old-debug-like program.

Pablo Niklas 1 Jan 10, 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