# Android Task Hijacking

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

**Try Hard Security Group**

<figure><img src="/files/Kw46fTSYxPIOMyKySfL5" alt=""><figcaption></figcaption></figure>

{% embed url="<https://discord.gg/tryhardsecurity>" %}

***

## 任务、后退栈和前台活动

在Android中，**任务**本质上是用户与之交互以完成特定工作的一组活动，这些活动在**后退栈**中组织。该堆栈根据打开活动的时间顺序对活动进行排序，最近的活动显示在顶部作为**前台活动**。在任何时刻，只有这个活动在屏幕上可见，使其成为**前台任务**的一部分。

以下是活动转换的简要说明：

* **活动1**开始作为前台中唯一的活动。
* 启动**活动2**将**活动1**推送到后退栈，将**活动2**带到前台。
* 启动**活动3**将**活动1**和**活动2**进一步推到堆栈后面，现在**活动3**在前面。
* 关闭**活动3**将**活动2**带回前台，展示了Android简化的任务导航机制。

![https://developer.android.com/images/fundamentals/diagram\_backstack.png](/files/TJ2anQX5TUPuJIDROu7U)

## 任务亲和性攻击

### 任务亲和性和启动模式概述

在Android应用程序中，**任务亲和性**指定活动的首选任务，通常与应用程序的包名称对齐。这种设置对于创建用于演示攻击的概念验证（PoC）应用程序至关重要。

### 启动模式

`launchMode`属性指导任务内活动实例的处理。**singleTask**模式对于此攻击至关重要，根据现有活动实例和任务亲和性匹配，规定了三种情况。攻击的关键在于攻击者的应用程序能够模仿目标应用程序的任务亲和性，误导Android系统启动攻击者的应用程序而不是预期的目标应用程序。

### 详细的攻击步骤

1. **恶意应用程序安装**：受害者在其设备上安装攻击者的应用程序。
2. **初始激活**：受害者首先打开恶意应用程序，为攻击做准备。
3. **目标应用程序启动尝试**：受害者尝试打开目标应用程序。
4. **劫持执行**：由于匹配的任务亲和性，恶意应用程序被启动代替目标应用程序。
5. **欺骗**：恶意应用程序呈现一个伪造的登录屏幕，类似于目标应用程序，欺骗用户输入敏感信息。

要实施此攻击，请参考GitHub上的Task Hijacking Strandhogg存储库：[Task Hijacking Strandhogg](https://github.com/az0mb13/Task_Hijacking_Strandhogg)。

### 预防措施

为防止此类攻击，开发人员可以将`taskAffinity`设置为空字符串，并选择`singleInstance`启动模式，确保其应用程序与其他应用程序隔离。自定义`onBackPressed()`函数可以提供额外的保护，防止任务劫持。

## **参考资料**

* [**https://blog.dixitaditya.com/android-task-hijacking/**](https://blog.dixitaditya.com/android-task-hijacking/)
* [**https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html**](https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html)

**Try Hard Security Group**

<figure><img src="/files/Kw46fTSYxPIOMyKySfL5" alt=""><figcaption></figcaption></figure>

{% embed url="<https://discord.gg/tryhardsecurity>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/mobile-pentesting/android-app-pentesting/android-task-hijacking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
