# Mariana Trench | Security Focused Static Analysis Tool For Android And Java Applications

**URL:** <https://onehack.st/t/mariana-trench-security-focused-static-analysis-tool-for-android-and-java-applications/210053>\
**Category:** Tools & Scripts\
**Tags:** tools, hacking, android\
**Created:** [December 21, 2021, 11:56am UTC](https://onehack.st/t/mariana-trench-security-focused-static-analysis-tool-for-android-and-java-applications/210053 "2021-12-21T11:56:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoBody](https://onehack.st/user_avatar/onehack.st/nobody/32/163880_2.png) [@NoBody](https://onehack.st/u/NoBody)\
**Post date:** [December 21, 2021, 11:56am UTC](https://onehack.st/t/mariana-trench-security-focused-static-analysis-tool-for-android-and-java-applications/210053/1 "2021-12-21T11:56:22Z")

</div>

[![logo](https://github.com/facebook/mariana-trench/raw/main/logo.png?raw=true)](https://github.com/facebook/mariana-trench/blob/main/logo.png?raw=true)

[![MIT License](https://camo.githubusercontent.com/dd1c858e94a371529a0a4c359bc95f18f09ba4a5fc0e658950bcb1383ea40fc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174)](http://choosealicense.com/licenses/mit/) [![.github/workflows/tests.yml](https://github.com/facebook/mariana-trench/actions/workflows/tests.yml/badge.svg)](https://github.com/facebook/mariana-trench/actions/workflows/tests.yml)

Mariana Trench is a security focused static analysis platform targeting Android.

This guide will walk you through setting up Mariana Trench on your machine and get you to find your first remote code execution vulnerability in a small sample app. These instructions are also available at our [website](https://mariana-tren.ch/docs/getting-started).

## Prerequisites

Mariana Trench requires a recent version of [Python](https://www.python.org/downloads/). On MacOS you can get a current version through [homebrew](https://brew.sh/):

$ brew install python3

On a Debian flavored Linux (Ubuntu, Mint, Debian), you can use `apt-get`:

$ sudo apt-get install python3 python3-pip python3-venv

This guide also assumes you have the [Android SDK](https://developer.android.com/studio) installed and an environment variable `$ANDROID_SDK` pointed to the location of the SDK.

For the rest of this guide, we assume that you are working inside of a [virtual environment](https://docs.python.org/3/tutorial/venv.html). You can set this up with

$ python3 -m venv ~/.venvs/mariana-trench $ source ~/.venvs/mariana-trench/bin/activate (mariana-trench)$

The name of the virtual environment in front of your shell prompt indicates that the virtual environment is active.

## Installing Mariana Trench

Inside your virtual environment installing Mariana Trench is as easy as running

(mariana-trench)$ pip install mariana-trench

## Running Mariana Trench

We’ll use a small app that is part of our documentation. You can get it by running

(mariana-trench)$ git clone [https://github.com/facebook/mariana-trench](https://github.com/facebook/mariana-trench) (mariana-trench)$ cd mariana-trench/documentation/sample-app

We are now ready to run the analysis

(mariana-trench)$ mariana-trench \ –system-jar-configuration-path=$ANDROID\_SDK/platforms/android-30/android.jar \ –apk-path=sample-app-debug.apk \ –source-root-directory=app/src/main/java # … INFO Analyzed 68886 models in 4.04s. Found 4 issues! # …

The analysis has found 4 issues in our sample app. The output of the analysis is a set of specifications for each method of the application.

## Post Processing

The specifications themselves are not meant to be read by humans. We need an additional processing step in order to make the results more presentable. We do this with [SAPP](https://github.com/facebook/sapp) PyPi installed for us:

(mariana-trench)$ sapp --tool=mariana-trench analyze . (mariana-trench)$ sapp --database-name=sapp.db server --source-directory=app/src/main/java # … 2021-05-12 12:27:22,867 [INFO] \* Running on [http://localhost:5000/](http://localhost:5000/) (Press CTRL+C to quit)

The last line of the output tells us that SAPP started a local webserver that lets us look at the results. Open the link and you will see the 4 issues found by the analysis.

## Exploring Results

Let’s focus on the remote code execution issue found in the sample app. You can identify it by its issue code `1` (for all remote code executions) and the callable `void MainActivity.onCreate(Bundle)`. With only 4 issues to see it’s easy to identify the issue manually but once more rules run, the filter functionality at the top right of the page comes in handy.

[![Single Issue Display](https://github.com/facebook/mariana-trench/raw/main/documentation/website/static/img/issue.png?raw=true)](https://github.com/facebook/mariana-trench/blob/main/documentation/website/static/img/issue.png?raw=true)

The issue tells you that Mariana Trench found a remote code execution in `MainActivity.onCreate` where the data is coming from `Activity.getIntent` one call away, and flows into the constructor of `ProcessBuilder` 3 calls away. Click on “Traces” in the top right corner of the issue to see an example trace.

The trace surfaced by Mariana Trench consists of three parts.

The _source trace_ represents where the data is coming from. In our example, the trace is very short: `Activity.getIntent` is called in `MainActivity.onCreate` directly. [![Trace Source](https://github.com/facebook/mariana-trench/raw/main/documentation/website/static/img/trace_source.png?raw=true)](https://github.com/facebook/mariana-trench/blob/main/documentation/website/static/img/trace_source.png?raw=true)

The _trace root_ represents where the source trace meets the sink trace. In our example this is the activitie’s `onCreate` method. [![Trace Root](https://github.com/facebook/mariana-trench/raw/main/documentation/website/static/img/trace_root.png?raw=true)](https://github.com/facebook/mariana-trench/blob/main/documentation/website/static/img/trace_root.png?raw=true)

The final part of the trace is the _sink trace_: This is where the data from the source flows down into a sink. In our example from `onCreate`, to `onClick`, to `execute`, and finally into the constructor of `ProcessBuilder`. [![Trace Sink](https://github.com/facebook/mariana-trench/raw/main/documentation/website/static/img/trace_sink.png?raw=true)](https://github.com/facebook/mariana-trench/blob/main/documentation/website/static/img/trace_sink.png?raw=true)

## Configuring Mariana Trench

You might be asking yourself, “how does the tool know what is user controlled data, and what is a sink?”. This guide is meant to quickly get you started on a small app. We did not cover how to configure Mariana Trench. You can read more about that at our website under [Configuration](https://mariana-tren.ch/docs/configuration).

## Contributing

For an in-depth guide on building from source and development on Mariana Trench, see the [Developer’s Guide](https://mariana-tren.ch/docs/contribution) at our website.

## License

Mariana Trench is licensed under the MIT license.

## GitHub:

[https://github.com/facebook/mariana-trench](https://github.com/facebook/mariana-trench)
