Skip to main content

Mariana Trench

logo

MIT License .github/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.

Prerequisites

Mariana Trench requires a recent version of Python. On MacOS you can get a current version through homebrew:

$ 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 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. 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

Note: pip install is not currently supported for Apple silicon Macs, you can build from source using the instructions in the Developer's Guide.

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
(mariana-trench)$ cd mariana-trench/

We are now ready to run the analysis

(mariana-trench)$ mariana-trench \
  --system-jar-configuration-path=configuration/default_system_jar_paths.json \
  --model-generator-configuration-paths=configuration/default_generator_config.json \
  --lifecycles-paths=configuration/lifecycles.json \
  --rules-paths=configuration/rules.json \
  --apk-path=documentation/sample-app/app/build/outputs/apk/debug/app-debug.apk \
  --source-root-directory=documentation/sample-app/app/src/main/java \
  --model-generator-search-paths=configuration/model-generators/

# ...
INFO Analyzed 68937 models in 7.47s. Found 9 issues!
# ...

The analysis has found 9 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 PyPi installed for us:

(mariana-trench)$ sapp --tool=mariana-trench analyze .
(mariana-trench)$ sapp --database-name=sapp.db server --source-directory=documentation/sample-app/app/src/main/java
# ...
2021-05-12 12:27:22,867 [INFO]  * Running on http://localhost:13337/ (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

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

The trace root represents where the source trace meets the sink trace. In our example this is the activitie's onCreate method. Trace Root

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

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.

Contributing

For an in-depth guide on building from source and development on Mariana Trench, see the Developer's Guide at our website.

License

Mariana Trench is licensed under the MIT license.

Metadata

Release files for mariana-trench 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mariana-trench 1.0.8
File Size Uploaded Provenance
mariana_trench-1.0.8.tar.gz 8.2 MB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for mariana-trench 1.0.8
File Interpreter ABI Platform
mariana_trench-1.0.8-py3-none-manylinux1_x86_64.whl Python 3 none Linux glibc 2.5+ x86-64 Details
mariana_trench-1.0.8-py3-none-macosx_10_11_x86_64.whl Python 3 none macOS 10.11+ x86-64 Details

Total release size: 22.7 MB

Release files / mariana_trench-1.0.8.tar.gz

Download URL mariana_trench-1.0.8.tar.gz
Size 8.2 MB
Tags Source
SHA-256 checksum
How to use checksums
1dd40d372f6b55f2cb67eab2cc88cf1ba78c30c4e84512c114d486651220a6cc
BLAKE2b-256 checksum
How to use checksums
72164f31e8b54c833c629d01795f23097e817331b600b03a45c804b7269b2d17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / mariana_trench-1.0.8-py3-none-manylinux1_x86_64.whl

Download URL mariana_trench-1.0.8-py3-none-manylinux1_x86_64.whl
Size 8.3 MB
Tags Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a5d79b4224fc0e573c209263e551254fa4093dbd3f8ec5b3efe56761eef26539
BLAKE2b-256 checksum
How to use checksums
8c0512e95d6ad9d5cdacb1adaf6703cfc2499a5461ef3eaca5af95803fcc676f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / mariana_trench-1.0.8-py3-none-macosx_10_11_x86_64.whl

Download URL mariana_trench-1.0.8-py3-none-macosx_10_11_x86_64.whl
Size 6.2 MB
Tags Python 3 macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
ebd506112ee519664f7c80e1d4f66fc028f8708f372ccf039d04e43efbd19f21
BLAKE2b-256 checksum
How to use checksums
54be5820340bc31f8a62d9899b2da27d7f4a00f0d2cce85cc6c818e604c1a465
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for mariana-trench 1.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page