一个小脚本,用于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
Hdbg - Historical Debugger

hdbg - Historical Debugger This is in no way a finished product. Do not use this

Fivreld 2 Jan 02, 2022
Never use print for debugging again

PySnooper - Never use print for debugging again PySnooper is a poor man's debugger. If you've used Bash, it's like set -x for Python, except it's fanc

Ram Rachum 15.5k 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
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
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
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
GDB plugin for streaming defmt messages over RTT from e.g. JLinkGDBServer

Defmt RTT plugin from GDB This small plugin runs defmt-print on the RTT stream produced by JLinkGDBServer, so that you can see the defmt logs in the G

Gaute Hope 1 Dec 30, 2021
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
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
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
Arghonaut is an interactive interpreter, visualizer, and debugger for Argh! and Aargh!

Arghonaut Arghonaut is an interactive interpreter, visualizer, and debugger for Argh! and Aargh!, which are Befunge-like esoteric programming language

Aaron Friesen 2 Dec 10, 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
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
🔥 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
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
Auto-detecting the n+1 queries problem in Python

nplusone nplusone is a library for detecting the n+1 queries problem in Python ORMs, including SQLAlchemy, Peewee, and the Django ORM. The Problem Man

Joshua Carp 837 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
Parsing ELF and DWARF in Python

pyelftools pyelftools is a pure-Python library for parsing and analyzing ELF files and DWARF debugging information. See the User's guide for more deta

Eli Bendersky 1.6k Jan 04, 2023
Full-screen console debugger for Python

PuDB: a console-based visual debugger for Python Its goal is to provide all the niceties of modern GUI-based debuggers in a more lightweight and keybo

Andreas Klöckner 2.6k Jan 01, 2023
EDB 以太坊单合约交易调试工具

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

16 May 21, 2022