Home | Android Bugs | CTFs








$Discovering code paths in APKs Pt1.





I've been tinkering and brainstorming some new project ideas within the reverse engineering space. One of the ideas involves automating dynamic analysis using Appium for the purpose of vulnerablity discovery. Rather than randomly fuzzing through apps, I thought it might be a good idea to inform my dynamic analysis' interactions through static analyses generated by Mercator. The raw outputs for Mercator include two NetworkX-formatted graphs in JSON files: a full graph of the analyzed application's classes, and a subgraph containing just the Android components' classes (activities, providers, receivers, services). The edges of the graphs represent method XREFs that Androguard was able to find from between classes. I wanted to be able write some simple NetworkX functions that can calculate shortest paths betweeacn Android components so that during dynamic analysis I can ensure test coverage of "hard to reach" components (i.e. a service that can only be activated if a specific activity is started first) (side note: determining inputs for required forms and such should be doable through Appium, but is a problem to be explored later).

I eventually plan to integrate the following into the Mercator D3 graph GUI, but for now it is exists as a standalone script that reads the Mercator component graph json. I tested using the krep banking malware apk (package: krep.itmtd.ywtjexf. md5: 02e231f85558f37da6802142440736f6). Nothing too crazy, just a random binary I pulled from my stash. The below script uses NetworkX and the generated component graph to determine the path between two components: UampleUverlayUhowUctivity, the Main Activity of the app, and MasterInterceptor, a malicious service)

Using the Mercator GUI, I can see that within the onCreate funciton of UampleUverlayUhowUctivity, there is a startService call which creates a new instance of MasterInterceptor service. Therefore, NetworkX should be able to determine a shortest path (of length 1) from UampleUverlayUhowUctivity to MasterInterceptor. This is a very simple example case, and will scale in usefulness with more complex cases involving deeply embedded components:





The ugly graph generated by Matplotlib looks like this, confirming (the red nodes) a shortest path of 1 (onCreate) was found. The next steps will be to get this integrated into Mercator, and optionally save outputs to inform the dynamic analysis engine. Finally, I'm sure there are other useful algorithms to apply, so exploring those would be a good idea as well. Future ideas include:



The graph json output, script, and matplotlib representation can be found here.

Note: similar networkx artifacts could probably be pulled from a newer version of Androguard using analysis.py.