Skip to content

Commit cd6d1d3

Browse files
authored
Merge pull request #1860 from HackTricks-wiki/research_update_src_mobile-pentesting_xamarin-apps_20260205_023626
Research Update Enhanced src/mobile-pentesting/xamarin-apps....
2 parents d66b406 + 0f49ba1 commit cd6d1d3

1 file changed

Lines changed: 43 additions & 7 deletions

File tree

src/mobile-pentesting/xamarin-apps.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,37 @@ To access the assemblies in an APK/IPA, unzip the file and explore the assemblie
3434
python3 xamarin-decompress.py -o /path/to/decompressed/apk
3535
```
3636

37-
In cases where after decompiling the APK it's possible to see the unknown/assemblies/ folder with the `.dll` files inside it, so it's posible to use [**dnSpy**](https://github.com/dnSpy/dnSpy) directly over the `.dlls` to analyze them.\
38-
However, sometimes, it's found the `assemblies.blob` and `assemblies.manifest` files inside the unknown/assemblies/ folder. The tool [pyxamstore](https://github.com/jakev/pyxamstore) can be used for unpacking the `assemblies.blob` file in Xamarin apps, allowing access to the .NET assemblies for further analysis:
37+
In cases where after decompiling the APK it's possible to see the unknown/assemblies/ folder with the `.dll` files inside it, it's possible to use [**dnSpy**](https://github.com/dnSpy/dnSpy) directly over the `.dlls` to analyze them. However, sometimes the `assemblies.blob` and `assemblies.manifest` files are inside the unknown/assemblies/ folder. The tool [pyxamstore](https://github.com/jakev/pyxamstore) can unpack the `assemblies.blob` file in Xamarin apps, allowing access to the .NET assemblies for further analysis:
3938

4039
```bash
4140
pyxamstore unpack -d /path/to/decompressed/apk/assemblies/
41+
# After patching DLLs, rebuild the store
42+
pyxamstore pack
43+
```
44+
45+
Some recent Xamarin/MAUI builds store compressed assemblies using the **XALZ** format inside `/assemblies.blob` or `/resources/assemblies`. You can quickly decompress them with the [xamarout](https://pypi.org/project/xamarout/) library:
46+
47+
```python
48+
from xamarout import xalz
49+
import os
50+
for root, _, files in os.walk("."):
51+
for f in files:
52+
if open(os.path.join(root, f), 'rb').read(4) == b"XALZ":
53+
xa = xalz.XamarinCompressedAssembly(os.path.join(root, f))
54+
xa.write("decompressed/" + f)
4255
```
4356

4457
iOS dll files are readily accessible for decompilation, revealing significant portions of the application code, which often shares a common base across different platforms.
4558

59+
> **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.
60+
4661
### Static Analysis
4762

48-
Once the `.dll`s are obtained it's possible to analyze the .Net code statically using tools such as [**dnSpy**](https://github.com/dnSpy/dnSpy) **or** [**ILSpy**](https://github.com/icsharpcode/ILSpy) **t**hat will allow to modify the code of the app. This can be super useful to tamper the application to bypass protections for example.\
63+
Once the `.dll`s are obtained it's possible to analyze the .Net code statically using tools such as [**dnSpy**](https://github.com/dnSpy/dnSpy) or [**ILSpy**](https://github.com/icsharpcode/ILSpy) that will allow modifying the code of the app. This can be super useful to tamper the application to bypass protections for example.\
4964
Note that after modifying the app you will need to pack it back again and sign it again.
5065

66+
> dnSpy is archived; maintained forks like **dnSpyEx** keep working with .NET 8/MAUI assemblies and preserve debug symbols when re-saving.
67+
5168
### Dynamic Analysis
5269

5370
Dynamic analysis involves checking for SSL pinning and using tools like [Fridax](https://github.com/NorthwaveSecurity/fridax) for runtime modifications of the .NET binary in Xamarin apps. Frida scripts are available to bypass root detection or SSL pinning, enhancing analysis capabilities.
@@ -58,17 +75,36 @@ Other interesting Frida scripts:
5875
- [**xamarin-root-detect-bypass**](https://codeshare.frida.re/@nuschpl/xamarin-root-detect-bypass/)
5976
- [**Frida-xamarin-unpin**](https://github.com/GoSecure/frida-xamarin-unpin)
6077

78+
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:
79+
80+
```bash
81+
frida -U -l dist/xamarin-unpin.js com.target.app --no-pause
82+
```
83+
84+
Quick template to hook managed methods with the bundled `frida-mono-api`:
85+
86+
```javascript
87+
const mono = require('frida-mono-api');
88+
Mono.ensureInitialized();
89+
Mono.enumerateLoadedImages().forEach(i => console.log(i.name));
90+
const klass = Mono.classFromName("Namespace", "Class");
91+
const m = Mono.methodFromName(klass, "Method", 2);
92+
Mono.intercept(m, { onEnter(args){ console.log(args[1].toInt32()); } });
93+
```
94+
6195
### Resigning
6296

6397
The tool [Uber APK Signer](https://github.com/patrickfav/uber-apk-signer) simplifies signing multiple APKs with the same key, and can be used to resign an app after changes have been performed to it.
6498

65-
## Further information
99+
## References
66100

67101
- [https://www.appknox.com/security/xamarin-reverse-engineering-a-guide-for-penetration-testers](https://www.appknox.com/security/xamarin-reverse-engineering-a-guide-for-penetration-testers)
68102
- [https://thecobraden.com/posts/unpacking_xamarin_assembly_stores/](https://thecobraden.com/posts/unpacking_xamarin_assembly_stores/)
69103
- [https://medium.com/@justmobilesec/introduction-to-the-exploitation-of-xamarin-apps-fde4619a51bf](https://medium.com/@justmobilesec/introduction-to-the-exploitation-of-xamarin-apps-fde4619a51bf)
104+
- [https://github.com/jakev/pyxamstore](https://github.com/jakev/pyxamstore)
105+
- [https://pypi.org/project/xamarout/](https://pypi.org/project/xamarout/)
106+
- [https://github.com/GoSecure/frida-xamarin-unpin](https://github.com/GoSecure/frida-xamarin-unpin)
107+
- [https://gist.github.com/Diefunction/e26fce039efcab57aac342a4b2d48ff6](https://gist.github.com/Diefunction/e26fce039efcab57aac342a4b2d48ff6)
108+
- [https://reverseengineering.stackexchange.com/questions/31716/deobfuscating-ios-dll-file-i-think-arm64](https://reverseengineering.stackexchange.com/questions/31716/deobfuscating-ios-dll-file-i-think-arm64)
70109

71110
{{#include ../banners/hacktricks-training.md}}
72-
73-
74-

0 commit comments

Comments
 (0)