Xamarin 应用
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
基本信息
Xamarin 是一个开源平台,供开发者使用 .NET 和 C# 框架为 iOS、Android 和 Windows 构建应用。该平台提供许多工具和扩展以高效创建现代应用。
Xamarin 的架构
- 对于 Android,Xamarin 通过 .NET 绑定与 Android 和 Java 命名空间集成,在 Mono 执行环境中与 Android Runtime (ART) 一起运行。Managed Callable Wrappers (MCW) 和 Android Callable Wrappers (ACW) 负责 Mono 与 ART 之间的通信,两者都构建在 Linux 内核之上。
- 对于 iOS,应用运行在 Mono runtime 下,使用完整的 Ahead of Time (AOT) 编译将 C# .NET 代码转换为 ARM 汇编。这一过程与 Objective-C Runtime 一起在类 UNIX 内核上运行。
.NET Runtime 和 Mono 框架
.NET 框架 包含用于应用开发的程序集、类和命名空间,.NET Runtime 管理代码执行。它提供平台无关性和向后兼容性。Mono 框架 是 .NET 的一个开源实现,始于 2005 年,旨在将 .NET 扩展到 Linux,目前由 Microsoft 支持并由 Xamarin 领导。
反向工程 Xamarin 应用
Xamarin 程序集的反编译
反编译将已编译的代码还原为源代码。在 Windows 上,Visual Studio 的 Modules 窗口可以识别用于反编译的模块,允许直接访问第三方代码并提取源代码以便分析。
JIT vs AOT 编译
- Android 支持 Just-In-Time (JIT) 和 Ahead-Of-Time (AOT) 编译,并具有用于优化执行速度的 Hybrid AOT 模式。Full AOT 仅限于 Enterprise 许可证。
- iOS 由于 Apple 对动态代码执行的限制,仅使用 AOT 编译。
从 APK/IPA 中提取 dll 文件
要访问 APK/IPA 中的程序集,解压文件并浏览 assemblies 目录。对于 Android,像 XamAsmUnZ 和 xamarin-decompress 这样的工具可以解压 dll 文件。
python3 xamarin-decompress.py -o /path/to/decompressed/apk
在对 APK 进行反编译后,如果可以看到 unknown/assemblies/ 文件夹并且里面包含 .dll 文件,就可以直接使用 dnSpy 对这些 .dlls 进行分析。但是有时 unknown/assemblies/ 文件夹中包含 assemblies.blob 和 assemblies.manifest 文件。工具 pyxamstore 可以解包 Xamarin 应用中的 assemblies.blob 文件,从而获取 .NET 程序集以便进一步分析:
pyxamstore unpack -d /path/to/decompressed/apk/assemblies/
# After patching DLLs, rebuild the store
pyxamstore pack
一些近期的 Xamarin/MAUI 构建会在 /assemblies.blob 或 /resources/assemblies 中使用 XALZ 格式存储压缩的程序集。您可以使用 xamarout 库快速解压缩它们:
from xamarout import xalz
import os
for root, _, files in os.walk("."):
for f in files:
if open(os.path.join(root, f), 'rb').read(4) == b"XALZ":
xa = xalz.XamarinCompressedAssembly(os.path.join(root, f))
xa.write("decompressed/" + f)
iOS dll files are readily accessible for decompilation, revealing significant portions of the application code, which often shares a common base across different platforms.
AOT on iOS: managed IL is compiled into native
*.aotdata.*files. Patching the DLL alone will not change logic; you need to hook native stubs (e.g., with Frida) because the IL bodies are empty placeholders.
静态分析
一旦获取了 .dll,就可以使用像 dnSpy 或 ILSpy 这样的工具对 .Net 代码进行静态分析,这些工具允许修改应用的代码。这对于篡改应用以 bypass 保护机制非常有用。
注意,修改应用后需要重新打包并重新签名。
dnSpy 已归档;像 dnSpyEx 这样的维护分支仍然可以用于 .NET 8/MAUI 程序集,并在重新保存时保留调试符号。
动态分析
动态分析包括检查 SSL pinning,并使用像 Fridax 这样的工具对 Xamarin 应用中的 .NET 二进制进行 runtime 修改。可用的 Frida 脚本可以 bypass root detection 或 SSL pinning,从而增强分析能力。
其他有趣的 Frida 脚本:
Updated Frida-xamarin-unpin (Mono >=6) hooks System.Net.Http.HttpClient.SendAsync and swaps the handler to a permissive one, so it still works even when pinning is implemented in custom handlers. Run it after the app starts:
frida -U -l dist/xamarin-unpin.js com.target.app --no-pause
使用捆绑的 frida-mono-api 钩取托管方法的快速模板:
const mono = require('frida-mono-api');
Mono.ensureInitialized();
Mono.enumerateLoadedImages().forEach(i => console.log(i.name));
const klass = Mono.classFromName("Namespace", "Class");
const m = Mono.methodFromName(klass, "Method", 2);
Mono.intercept(m, { onEnter(args){ console.log(args[1].toInt32()); } });
重新签名
工具 Uber APK Signer 简化了使用相同密钥为多个 APK 签名的过程,并可在对应用进行修改后用于重新签名。
参考资料
- https://www.appknox.com/security/xamarin-reverse-engineering-a-guide-for-penetration-testers
- https://thecobraden.com/posts/unpacking_xamarin_assembly_stores/
- https://medium.com/@justmobilesec/introduction-to-the-exploitation-of-xamarin-apps-fde4619a51bf
- https://github.com/jakev/pyxamstore
- https://pypi.org/project/xamarout/
- https://github.com/GoSecure/frida-xamarin-unpin
- https://gist.github.com/Diefunction/e26fce039efcab57aac342a4b2d48ff6
- https://reverseengineering.stackexchange.com/questions/31716/deobfuscating-ios-dll-file-i-think-arm64
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。


