repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
objection-tutorial.mdMarkdown358 lines13.9 KiBrendered raw download
---
title: "Objection Tutorial"
section: "Mobile"
sectionSlug: "mobile-pentesting"
sourcePath: "src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# Objection Tutorial

## **Introduction**

**objection - Runtime Mobile Exploration**

[**Objection**](https://github.com/sensepost/objection) is a runtime mobile exploration toolkit, powered by [Frida](https://www.frida.re). It was built with the aim of helping assess mobile applications and their security posture without the need for a jailbroken or rooted mobile device.<sup>[[1]](#references)</sup>

**Note:** This is not some form of jailbreak / root bypass. By using `objection`, you are still limited by all of the restrictions imposed by the applicable sandbox you are facing.

### Summary

The goal of **objection** is to expose common Frida-powered mobile-testing actions through a reusable command-line interface, reducing the need to write a separate script for every application.

## Tutorial

For this tutorial I am going to use the APK that you can download here:

[App Release.Zip](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/frida-tutorial/app-release.zip)

Or from its [original repository](https://github.com/asvid/FridaApp) (download app-release.apk)

### Installation

```bash
pip3 install objection
```

### Connection

Establish a regular **ADB connection**, start **Frida Server** on the device, and verify that the client and server can communicate.

If you are using a **rooted device** and `frida-server`, enumerate packages and then start the current `objection` REPL (`start` is the modern syntax; older writeups may still show `explore` or `--gadget`):

```bash
frida-ps -Uai
objection -n asvid.github.io.fridaapp start
```

If you are using a **non-rooted device**, a common workflow is to patch the APK to embed **Frida Gadget**, reinstall it, and then connect to `Gadget`:<sup>[[3]](#references)</sup>

```bash
objection patchapk -s app-release.apk --network-security-config --enable-debug --use-aapt2
adb install -r app-release.objection.apk
objection -n Gadget start
```

For a complete Gadget embedding workflow (including `--gadget-config` and `-l`/script-mode patching), check:

[Readme](/hacktricks/mobile-pentesting/android-app-pentesting/frida-tutorial/overview)

If the application still crashes or exits as soon as Objection/Frida attaches, continue with [this anti-instrumentation workflow](/hacktricks/mobile-pentesting/android-app-pentesting/android-anti-instrumentation-and-ssl-pinning-bypass).

### Basic Actions

This tutorial lists a practical subset of Objection commands.

#### Environment

The environment may reveal interesting information such as paths or accidentally exposed secrets.

```bash
env
```

![Basic Actions - Environment](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28220%29.png)

#### Frida Information

```bash
frida
```

![Environment - Frida Information](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281093%29.png)

#### Upload/Download

```bash
file download <remote path> [<local path>]
file upload <local path> [<remote path>]
```

#### Import frida script

```bash
import <local path frida-script>
```

#### Jobs

Imported scripts and many hooks run as **jobs** in the background, so you can keep using the REPL while the hook stays loaded:

```bash
import ssl-bypass.js "ssl-bypass"
jobs list
jobs kill <job_id>
```

This is especially useful after `android hooking watch ...` or when importing a long-running Frida helper.

#### Early instrumentation

If the app runs root checks, SSL pinning or anti-tampering **during startup**, run the hook before the REPL finishes collecting environment data:<sup>[[2]](#references)</sup>

```bash
objection -n asvid.github.io.fridaapp start --startup-command "android sslpinning disable"
objection -n asvid.github.io.fridaapp start --startup-script ssl-bypass.js
```

This is much more reliable when the interesting code runs inside `Application.onCreate()` or in the first launched Activity.

#### SSLPinning

```bash
android sslpinning disable #Attempts to disable SSL Pinning on Android devices.
```

#### Root detection

```bash
android root disable  #Attempts to disable root detection on Android devices.
android root simulate #Attempts to simulate a rooted Android environment.
```

#### Exec Command

```bash
android shell_exec whoami
```

#### Screenshots

```bash
android ui screenshot /tmp/screenshot
android ui FLAG_SECURE false  #This may enable you to take screenshots using the hardware keys
```

#### Useful Android helpers

```bash
android deoptimize                         # Force ART to go through the interpreter and make hooks more reliable
android proxy set 192.168.1.10 8080       # Set a proxy only for the hooked app
android intent implicit_intents --dump-backtrace
```

`android deoptimize` is especially useful when ART optimization makes a hook appear correct but the implementation is never reached.

### Static analysis made Dynamic

In a real application we should know all of the information discovered in this part before using objection thanks to **static analysis**. Anyway, this way maybe you can see **something new** as here you will only have a complete list of classes, methods and exported objects.

This is also useful when you cannot obtain readable source code for the app.

#### List activities, receivers and services

```bash
android hooking list activities
```

![Static analysis made Dynamic - List activities, receivers and services: android hooking list activities](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281016%29.png)

```bash
android hooking list services
android hooking list receivers
```

Frida will report an error if none is found.

#### Getting current activity

```bash
android hooking get current_activity
```

![List activities, receivers and services - Getting current activity: android hooking get current activity](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28813%29.png)

#### Search Classes

Start by looking for classes inside the application:

```bash
android hooking search classes asvid.github.io.fridaapp
```

![Getting current activity - Search Classes: android hooking search classes asvid.github.io.fridaapp](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28507%29.png)

#### Search Methods of a class

Now extract the methods inside the `MainActivity` class:

```bash
android hooking search methods asvid.github.io.fridaapp MainActivity
```

![Search Classes - Search Methods of a class: android hooking search methods asvid.github.io.fridaapp MainActivity](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28929%29.png)

#### List declared Methods of a class with their parameters

List the declared methods and their parameter types:

```bash
android hooking list class_methods asvid.github.io.fridaapp.MainActivity
```

![Search Methods of a class - List declared Methods of a class with their parameters: android hooking list class methods asvid.github.io.fridaapp.MainActivity](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28299%29.png)

#### List classes

You can also list every class loaded in the current application:

```bash
android hooking list classes # More classes appear as the application loads additional code.
android hooking list class_loaders
```

This is useful when you know a class name but not its owning module; locate the class first, then hook its method.

`android hooking list class_loaders` is especially useful in packed apps, plugins, and apps that decrypt or load additional DEX files at runtime, because interesting classes may appear only in a secondary class loader.

### Hooking being easy

#### Hooking (watching) a method

The application's [source code](https://github.com/asvid/FridaApp/blob/master/app/src/main/java/asvid/github/io/fridaapp/MainActivity.kt) shows that `MainActivity.sum()` runs every second. Dump its arguments, return value, and backtrace each time it is called:

```bash
android hooking watch class_method asvid.github.io.fridaapp.MainActivity.sum --dump-args --dump-backtrace --dump-return
```

![Hooking being easy - Hooking (watching) a method: android hooking watch class method asvid.github.io.fridaapp.MainActivity.sum --dump-args --dump-backtrace --dump-return](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281086%29.png)

#### Hooking (watching) an entire class

To observe the whole `MainActivity` class, hook every method. This can crash the application.

```bash
android hooking watch class asvid.github.io.fridaapp.MainActivity --dump-args --dump-return
```

If you play with the application while the class is hooked you will see when **each function is being called**, its **arguments** and the **return** value.

![Hooking (watching) a method - Hooking (watching) an entire class: If you play with the application while the class is hooked you will see when each function is being called , its...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28861%29.png)

#### Changing boolean return value of a function

The source shows that `checkPin` accepts a `String` and returns a Boolean. Make the function **always return true**:

![Hooking (watching) an entire class - Changing boolean return value of a function: From the source code you can see that the function checkPin gets a String as argument and returns a...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28883%29.png)

After the hook is active, any value entered in the PIN field is accepted:

![The hooked checkPin method accepts any value entered in the PIN field](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28228%29.png)

### Class instances

Search for and print **live instances of a specific Java class**, specified by a fully qualified class name. The returned **hashcode** can then be reused to inspect the object and even execute instance methods on it.

```bash
android heap search instances <class>
android heap print fields <hashcode>
android heap print methods <hashcode> --without-arguments
android heap execute <hashcode> <method> --return-string
android heap evaluate <hashcode>
```

This is very useful when static analysis shows an interesting singleton or manager object already in memory and you want to inspect its state or call a helper method without writing a custom Frida script.

![Changing boolean return value of a function - Class instances: android heap print instances](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281095%29.png)

### Keystore/Intents

You can play with the keystore and intents using:

```bash
android keystore list
android intent launch_activity
android intent launch_service
```

### Memory

#### Dump

```bash
memory dump all <local destination> #Dump all memory
memory dump from_base <base_address> <size_to_dump> <local_destination> #Dump a part
```

#### List

```bash
memory list modules
```

![Dump - List: memory list modules](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28286%29.png)

At the bottom of the list, you can see Frida:

![Frida shown in the loaded-module list](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281097%29.png)

List the exports from a selected module:

```bash
memory list exports libfoo.so
memory list exports libfoo.so --json exports.json
```

![Listing exports from a loaded module](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28298%29.png)

#### Search/Write

You can also search and write process memory with Objection:

```bash
memory search "<pattern eg: 41 41 41 ?? 41>" (--string) (--offsets-only)
memory write "<address>" "<pattern eg: 41 41 41 41>" (--string)
```

### SQLite

Use the `sqlite` command to interact with SQLite databases.

```bash
sqlite connect /data/data/<package>/databases/app.db
sqlite connect /data/data/<package>/databases/app.db --sync
```

Using `--sync` will upload the modified temporary copy back to the application path when you exit the SQLite prompt.

### Exit

```bash
exit
```

## What I miss in Objection

- The hooking methods sometimes crashes the application (this is also because of Frida or anti-instrumentation checks in the target app).
- Modern versions can inspect heap instances and execute methods on existing handles, but creating fresh Java objects or orchestrating complex overloaded method calls is usually still easier with a custom Frida script.
- There is no shortcut comparable to `sslpinning` for hooking every common cryptographic API and displaying ciphertext, plaintext, keys, IVs, and algorithms.

## References

- [1] [Objection (SensePost)](https://github.com/sensepost/objection)
- [2] [Objection wiki: Early Instrumentation](https://github.com/sensepost/objection/wiki/Early-Instrumentation)
- [3] [Objection wiki: Patching Android Applications](https://github.com/sensepost/objection/wiki/Patching-Android-Applications)