# Xamarin Apps

<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)，我们的独家[**NFT**](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>

这是博客文章<https://www.appknox.com/security/xamarin-reverse-engineering-a-guide-for-penetration-testers>的摘要

## **基本信息**

Xamarin 是一个为开发人员设计的**开源平台**，可使用 .NET 和 C# 框架**构建 iOS、Android 和 Windows 应用**。该平台提供访问众多工具和扩展，以高效创建现代应用程序。

### Xamarin 的架构

* 对于**Android**，Xamarin 通过 .NET 绑定与 Android 和 Java 命名空间集成，在 Mono 执行环境中与 Android Runtime (ART) 一起运行。托管可调用包装器 (MCW) 和 Android 可调用包装器 (ACW) 促进了 Mono 和 ART 之间的通信，两者都建立在 Linux 内核上。
* 对于**iOS**，应用程序在 Mono 运行时下运行，利用完全的 Ahead of Time (AOT) 编译将 C# .NET 代码转换为 ARM 汇编语言。此过程与 Objective-C Runtime 在类 UNIX 内核上运行。

### .NET 运行时和 Mono 框架

**.NET 框架**包括用于应用程序开发的程序集、类和命名空间，.NET 运行时管理代码执行。它提供平台独立性和向后兼容性。**Mono 框架**是 .NET 框架的开源版本，于 2005 年启动，旨在将 .NET 扩展到 Linux，现在得到 Microsoft 的支持，并由 Xamarin 领导。

### 反向工程 Xamarin 应用

#### 反编译 Xamarin 程序集

反编译将编译后的代码转换回源代码。在 Windows 中，Visual Studio 的模块窗口可以识别用于反编译的模块，从而直接访问第三方代码并提取源代码进行分析。

#### JIT vs AOT 编译

* **Android**支持即时 (JIT) 和提前 (AOT) 编译，具有混合 AOT 模式以获得最佳执行速度。完全 AOT 仅适用于企业许可证。
* **iOS**由于苹果对动态代码执行的限制，仅使用 AOT 编译。

### 从 APK/IPA 中提取 dll 文件

要访问 APK/IPA 中的程序集，请解压文件并浏览程序集目录。对于 Android，可以使用 [XamAsmUnZ](https://github.com/cihansol/XamAsmUnZ) 和 [xamarin-decompress](https://github.com/NickstaDB/xamarin-decompress) 等工具解压缩 dll 文件。

```bash
python3 xamarin-decompress.py -o /path/to/decompressed/apk
```

对于 Android 中的汇编 blob，[pyxamstore](https://github.com/jakev/pyxamstore) 可以对其进行解包。

```bash
pyxamstore unpack -d /path/to/decompressed/apk/assemblies/
```

iOS的dll文件可以轻松访问并进行反编译，揭示应用程序代码的重要部分，这些部分通常在不同平台上共享相同的基础。

### 动态分析

动态分析涉及检查SSL绑定并使用类似[Fridax](https://github.com/NorthwaveSecurity/fridax)的工具对Xamarin应用程序中的.NET二进制文件进行运行时修改。Frida脚本可用于绕过root检测或SSL绑定，增强分析能力。

其他有趣的Frida脚本：

* [**xamarin-antiroot**](https://codeshare.frida.re/@Gand3lf/xamarin-antiroot/)
* [**xamarin-root-detect-bypass**](https://codeshare.frida.re/@nuschpl/xamarin-root-detect-bypass/)
* [**Frida-xamarin-unpin**](https://github.com/GoSecure/frida-xamarin-unpin)

## 更多信息

* <https://www.appknox.com/security/xamarin-reverse-engineering-a-guide-for-penetration-testers>
* <https://thecobraden.com/posts/unpacking_xamarin_assembly_stores/>

<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的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**SUBSCRIPTION PLANS**](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/xamarin-apps.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.
