# Bypass Biometric Authentication (Android)

<details>

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

* 您在**网络安全公司**工作吗？ 想要看到您的**公司在HackTricks中做广告**吗？ 或者您想要访问**PEASS的最新版本或下载PDF格式的HackTricks**吗？ 请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 发现我们的独家[NFTs收藏品**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群**](https://discord.gg/hRep4RUj7f) 或[**电报群**](https://t.me/peass) 或在**Twitter**上关注我 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks)**和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud)**提交PR来分享您的黑客技巧**。

</details>

## **方法1 – 无需使用加密对象绕过**

重点在于\_onAuthenticationSucceeded\_回调，在认证过程中至关重要。WithSecure的研究人员开发了一个[Frida脚本](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass.js)，可以绕过\_onAuthenticationSucceeded(...)中的空CrytoObject\_。该脚本在方法调用时强制自动绕过指纹认证。以下是一个简化的代码片段，演示了在Android指纹上下文中的绕过，完整应用程序可在[GitHub](https://github.com/St3v3nsS/InsecureBanking)上找到。

```javascript
biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
Toast.makeText(MainActivity.this,"Success",Toast.LENGTH_LONG).show();
}
});
```

运行Frida脚本的命令：

```bash
frida -U -f com.generic.insecurebankingfingerprint --no-pause -l fingerprint-bypass.js
```

## **方法2 – 异常处理方法**

另一个由WithSecure开发的[Frida脚本](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass-via-exception-handling.js)解决了绕过不安全的加密对象使用的问题。该脚本调用\_onAuthenticationSucceeded\_时使用一个未经指纹授权的\_CryptoObject\_。如果应用程序尝试使用不同的密码对象，将触发异常。该脚本准备调用\_onAuthenticationSucceeded\_并处理\_Cipher\_类中的\_javax.crypto.IllegalBlockSizeException\_，确保应用程序使用的后续对象使用新密钥加密。

运行Frida脚本的命令：

```bash
frida -U -f com.generic.insecurebankingfingerprint --no-pause -l fingerprint-bypass-via-exception-handling.js
```

在达到指纹屏幕并启动`authenticate()`时，在Frida控制台中键入`bypass()`以激活绕过：

```
Spawning com.generic.insecurebankingfingerprint...
[Android Emulator 5554::com.generic.insecurebankingfingerprint]-> Hooking BiometricPrompt.authenticate()...
Hooking BiometricPrompt.authenticate2()...
Hooking FingerprintManager.authenticate()...
[Android Emulator 5554::com.generic.insecurebankingfingerprint]-> bypass()
```

## **方法 3 – 仪器化框架**

仪器化框架如Xposed或Frida可用于在运行时钩入应用程序方法。对于指纹认证，这些框架可以：

1. **模拟认证回调**：通过钩入`BiometricPrompt.AuthenticationCallback`的`onAuthenticationSucceeded`、`onAuthenticationFailed`或`onAuthenticationError`方法，您可以控制指纹认证过程的结果。
2. **绕过SSL Pinning**：这允许攻击者拦截和修改客户端与服务器之间的流量，可能改变认证过程或窃取敏感数据。

Frida的示例命令：

```bash
frida -U -l script-to-bypass-authentication.js --no-pause -f com.generic.in
```

## **方法 4 – 逆向工程 & 代码修改**

类似 `APKTool`、`dex2jar` 和 `JD-GUI` 的逆向工程工具可用于反编译 Android 应用程序，阅读其源代码，并了解其身份验证机制。一般步骤包括：

1. **反编译 APK**：将 APK 文件转换为更易读的格式（如 Java 代码）。
2. **分析代码**：查找指纹身份验证的实现，并识别潜在的弱点（如备用机制或不正确的验证检查）。
3. **重新编译 APK**：在修改代码以绕过指纹身份验证后，重新编译、签名并安装应用程序到设备进行测试。

## **方法 5 – 使用自定义身份验证工具**

有专门设计用于测试和绕过身份验证机制的工具和脚本。例如：

1. **MAGISK 模块**：MAGISK 是一款用于 Android 的工具，允许用户对其设备进行 root，并添加可修改或欺骗硬件级信息（包括指纹）的模块。
2. **自定义脚本**：可以编写脚本与 Android 调试桥（ADB）交互，或直接与应用程序后端交互以模拟或绕过指纹身份验证。

## 参考资料

* <https://securitycafe.ro/2022/09/05/mobile-pentesting-101-bypassing-biometric-authentication/>


---

# 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/bypass-biometric-authentication-android.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.
