Package: mariana-trench
Mariana TrenchMariana 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 ourwebsite.PrerequisitesMariana Trench requires a recent version ofPython. On MacOS you can get a current version throughhomebrew:$brewinstallpython3On a Debian flavored Linux (Ubuntu, Mint, Debian), you can useapt-get:$sudoapt-getinstallpython3python3-pippython3-venvThis guide also assumes you have theAndroid SDKinstalled and an environment variable$ANDROID_SDKpointed to the location of the SDK.For the rest of this guide, we assume that you are working inside of avirtual environment. You can set this up with$python3-mvenv~/.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 TrenchInside your virtual environment installing Mariana Trench is as easy as running(mariana-trench)$pipinstallmariana-trenchNote: pip install is not currently supported for Apple silicon Macs, you can build from source using the instructions in theDeveloper's Guide.Running Mariana TrenchWe'll use a small app that is part of our documentation. You can get it by running(mariana-trench)$gitclonehttps://github.com/facebook/mariana-trench(mariana-trench)$cdmariana-trench/We are now ready to run the analysis(mariana-trench)$mariana-trench\--system-jar-configuration-path=$ANDROID_SDK/platforms/android-32/android.jar\--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/# ...INFOAnalyzed68937modelsin7.47s.Found9issues!# ...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 ProcessingThe 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 withSAPPPyPi installed for us:(mariana-trench)$sapp--tool=mariana-trenchanalyze.(mariana-trench)$sapp--database-name=sapp.dbserver--source-directory=documentation/sample-app/app/src/main/java# ...2021-05-1212:27:22,867[INFO]*Runningonhttp://localhost:13337/(PressCTRL+Ctoquit)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 ResultsLet's focus on the remote code execution issue found in the sample app. You can identify it by its issue code1(for all remote code executions) and the callablevoid 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.The issue tells you that Mariana Trench found a remote code execution inMainActivity.onCreatewhere the data is coming fromActivity.getIntentone call away, and flows into the constructor ofProcessBuilder3 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.Thesource tracerepresents where the data is coming from. In our example, the trace is very short:Activity.getIntentis called inMainActivity.onCreatedirectly.Thetrace rootrepresents where the source trace meets the sink trace. In our example this is the activitie'sonCreatemethod.The final part of the trace is thesink trace: This is where the data from the source flows down into a sink. In our example fromonCreate, toonClick, toexecute, and finally into the constructor ofProcessBuilder.Configuring Mariana TrenchYou 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 underConfiguration.ContributingFor an in-depth guide on building from source and development on Mariana Trench, see theDeveloper's Guideat our website.LicenseMariana Trench is licensed under the MIT license.