Skip to main content

A security focused static analysis platform targeting Android.

Project description

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

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/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 analyis 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=app/src/main/java
# ...
2021-05-12 12:27:22,867 [INFO]  * Running on 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 analyis.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mariana-trench-1.0.tar.gz (4.7 MB view details)

Uploaded Source

Built Distributions

mariana_trench-1.0-py3-none-macosx_10_11_x86_64.whl (3.4 MB view details)

Uploaded Python 3 macOS 10.11+ x86-64

File details

Details for the file mariana-trench-1.0.tar.gz.

File metadata

  • Download URL: mariana-trench-1.0.tar.gz
  • Upload date:
  • Size: 4.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mariana-trench-1.0.tar.gz
Algorithm Hash digest
SHA256 42533386737e131c9cd513f557a8c1351ffcd30c7efc9b02d6e5acc09a718e71
MD5 a4ce373d5c7b75af1cc72d69d7364013
BLAKE2b-256 227b96b842e53e168cf5bd35ca974b24299f9fdc975ef59e27532e555b2c17b7

See more details on using hashes here.

File details

Details for the file mariana_trench-1.0-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: mariana_trench-1.0-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mariana_trench-1.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 222ba5f07bd08483acce3fcb2f761a97940650bfede359aea7557cdadadc2ba1
MD5 6d34e94b80b7eaba950fddc3e4bd89c0
BLAKE2b-256 5b66d7d4f3090ab44e40bf12bf520b77b54f4990baaf4df91deffb532985b34f

See more details on using hashes here.

File details

Details for the file mariana_trench-1.0-py3-none-macosx_10_11_x86_64.whl.

File metadata

  • Download URL: mariana_trench-1.0-py3-none-macosx_10_11_x86_64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: Python 3, macOS 10.11+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mariana_trench-1.0-py3-none-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 d23c581154f4f8b70f4c055b6cf7563ed1dc2484d3227e6b69023b987325159d
MD5 af46d01ebfcc112b43edaaa252289a12
BLAKE2b-256 93778db64b01b3f974860c1a557968a8869acc2d696d38745b9d86696eb36cd4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page