一个小脚本,用于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 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
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
Visual Interaction with Code - A portable visual debugger for python

VIC Visual Interaction with Code A simple tool for debugging and interacting with running python code. This tool is designed to make it easy to inspec

Nathan Blank 1 Nov 16, 2021
Hypothesis debugging with vscode

Hypothesis debugging with vscode

Oliver Mannion 0 Feb 09, 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
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 Dec 24, 2022
🍦 Never use print() to debug again.

IceCream -- Never use print() to debug again Do you ever use print() or log() to debug your code? Of course you do. IceCream, or ic for short, makes p

Ansgar Grunseid 6.5k Jan 07, 2023
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 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
Cyberbrain: Python debugging, redefined.

Cyberbrain1(电子脑) aims to free programmers from debugging.

laike9m 2.3k Jan 07, 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
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
Little helper to run Steam apps under Proton with a GDB debugger

protongdb A small little helper for running games with Proton and debugging with GDB Requirements At least Python 3.5 protontricks pip package and its

Joshie 21 Nov 27, 2022
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
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
EDB 以太坊单合约交易调试工具

EDB 以太坊单合约交易调试工具 Idea 在刷题的时候遇到一类JOP(Jump-Oriented-Programming)的题目,fuzz或者调试这类题目缺少简单易用的工具,由此开发了一个简单的调试工具EDB(The Ethereum Debugger),利用debug_traceTransact

16 May 21, 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
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
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
Visual profiler for Python

vprof vprof is a Python package providing rich and interactive visualizations for various Python program characteristics such as running time and memo

Nick Volynets 3.9k Jan 01, 2023