# Xamarin Apps {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} ## **κΈ°λ³Έ 정보** Xamarin은 κ°œλ°œμžκ°€ .NET 및 C# ν”„λ ˆμž„μ›Œν¬λ₯Ό μ‚¬μš©ν•˜μ—¬ **iOS, Android 및 Windows용 앱을 ꡬ좕**ν•  수 μžˆλ„λ‘ μ„€κ³„λœ **μ˜€ν”ˆ μ†ŒμŠ€ ν”Œλž«νΌ**μž…λ‹ˆλ‹€. 이 ν”Œλž«νΌμ€ ν˜„λŒ€μ μΈ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ 효율적으둜 μƒμ„±ν•˜κΈ° μœ„ν•œ μˆ˜λ§Žμ€ 도ꡬ와 ν™•μž₯ κΈ°λŠ₯에 λŒ€ν•œ μ•‘μ„ΈμŠ€λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€. ### Xamarin의 μ•„ν‚€ν…μ²˜ * **Android**의 경우, Xamarin은 .NET 바인딩을 톡해 Android 및 Java λ„€μž„μŠ€νŽ˜μ΄μŠ€μ™€ ν†΅ν•©λ˜μ–΄ Mono μ‹€ν–‰ ν™˜κ²½ λ‚΄μ—μ„œ Android Runtime (ART)와 ν•¨κ»˜ μž‘λ™ν•©λ‹ˆλ‹€. 관리 κ°€λŠ₯ν•œ 호좜 래퍼(MCW)와 Android 호좜 래퍼(ACW)λŠ” Mono와 ART κ°„μ˜ 톡신을 μš©μ΄ν•˜κ²Œ ν•˜λ©°, 두 가지 λͺ¨λ‘ Linux 컀널을 기반으둜 κ΅¬μΆ•λ˜μ—ˆμŠ΅λ‹ˆλ‹€. * **iOS**의 경우, μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ€ Mono λŸ°νƒ€μž„μ—μ„œ μ‹€ν–‰λ˜λ©°, C# .NET μ½”λ“œλ₯Ό ARM μ–΄μ…ˆλΈ”λ¦¬ μ–Έμ–΄λ‘œ λ³€ν™˜ν•˜κΈ° μœ„ν•΄ 전체 사전 컴파일(AOT) μ»΄νŒŒμΌμ„ ν™œμš©ν•©λ‹ˆλ‹€. 이 과정은 UNIX와 μœ μ‚¬ν•œ μ»€λ„μ—μ„œ Objective-C λŸ°νƒ€μž„κ³Ό ν•¨κ»˜ μ‹€ν–‰λ©λ‹ˆλ‹€. ### .NET λŸ°νƒ€μž„ 및 Mono ν”„λ ˆμž„μ›Œν¬ **.NET ν”„λ ˆμž„μ›Œν¬**λŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜ κ°œλ°œμ„ μœ„ν•œ μ–΄μ…ˆλΈ”λ¦¬, 클래슀 및 λ„€μž„μŠ€νŽ˜μ΄μŠ€λ₯Ό ν¬ν•¨ν•˜λ©°, .NET λŸ°νƒ€μž„μ€ μ½”λ“œ 싀행을 κ΄€λ¦¬ν•©λ‹ˆλ‹€. ν”Œλž«νΌ 독립성과 이전 λ²„μ „κ³Όμ˜ ν˜Έν™˜μ„±μ„ μ œκ³΅ν•©λ‹ˆλ‹€. **Mono ν”„λ ˆμž„μ›Œν¬**λŠ” 2005년에 μ‹œμž‘λœ .NET ν”„λ ˆμž„μ›Œν¬μ˜ μ˜€ν”ˆ μ†ŒμŠ€ λ²„μ „μœΌλ‘œ, Linux에 .NET을 ν™•μž₯ν•˜κΈ° μœ„ν•΄ μ‹œμž‘λ˜μ—ˆμœΌλ©°, ν˜„μž¬ Microsoft의 지원을 λ°›κ³  있으며 Xamarin이 μ£Όλ„ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. ### Xamarin μ•±μ˜ λ¦¬λ²„μŠ€ μ—”μ§€λ‹ˆμ–΄λ§ #### Xamarin μ–΄μ…ˆλΈ”λ¦¬μ˜ λ””μ»΄νŒŒμΌ λ””μ»΄νŒŒμΌμ€ 컴파일된 μ½”λ“œλ₯Ό λ‹€μ‹œ μ†ŒμŠ€ μ½”λ“œλ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€. Windowsμ—μ„œλŠ” Visual Studio의 λͺ¨λ“ˆ μ°½μ—μ„œ λ””μ»΄νŒŒμΌμ„ μœ„ν•œ λͺ¨λ“ˆμ„ 식별할 수 있으며, 이λ₯Ό 톡해 타사 μ½”λ“œμ— 직접 μ ‘κ·Όν•˜κ³  뢄석을 μœ„ν•œ μ†ŒμŠ€ μ½”λ“œλ₯Ό μΆ”μΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€. #### JIT vs AOT 컴파일 * **Android**λŠ” Just-In-Time (JIT) 및 Ahead-Of-Time (AOT) μ»΄νŒŒμΌμ„ μ§€μ›ν•˜λ©°, 졜적의 μ‹€ν–‰ 속도λ₯Ό μœ„ν•œ ν•˜μ΄λΈŒλ¦¬λ“œ AOT λͺ¨λ“œκ°€ μžˆμŠ΅λ‹ˆλ‹€. 전체 AOTλŠ” κΈ°μ—… λΌμ΄μ„ΌμŠ€μ—λ§Œ λ…μ μ μž…λ‹ˆλ‹€. * **iOS**λŠ” Apple의 동적 μ½”λ“œ μ‹€ν–‰ μ œν•œμœΌλ‘œ 인해 였직 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 ``` APKλ₯Ό λ””μ»΄νŒŒμΌν•œ 후에 unknown/assemblies/ 폴더와 κ·Έ μ•ˆμ— μžˆλŠ” `.dll` νŒŒμΌμ„ λ³Ό 수 μžˆλŠ” 경우, [**dnSpy**](https://github.com/dnSpy/dnSpy)λ₯Ό μ‚¬μš©ν•˜μ—¬ `.dll` νŒŒμΌμ„ 직접 뢄석할 수 μžˆμŠ΅λ‹ˆλ‹€.\ κ·ΈλŸ¬λ‚˜ λ•Œλ•Œλ‘œ unknown/assemblies/ 폴더 μ•ˆμ— `assemblies.blob` 및 `assemblies.manifest` 파일이 λ°œκ²¬λ©λ‹ˆλ‹€. 도ꡬ [pyxamstore](https://github.com/jakev/pyxamstore)λŠ” Xamarin μ•±μ—μ„œ `assemblies.blob` νŒŒμΌμ„ μ–ΈνŒ©ν•˜λŠ” 데 μ‚¬μš©λ  수 있으며, 이λ₯Ό 톡해 μΆ”κ°€ 뢄석을 μœ„ν•œ .NET μ–΄μ…ˆλΈ”λ¦¬μ— μ ‘κ·Όν•  수 μžˆμŠ΅λ‹ˆλ‹€: ```bash pyxamstore unpack -d /path/to/decompressed/apk/assemblies/ ``` iOS dll νŒŒμΌμ€ λ””μ»΄νŒŒμΌμ„ μœ„ν•΄ μ‰½κ²Œ μ ‘κ·Όν•  수 있으며, μ΄λŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ½”λ“œμ˜ 상당 뢀뢄을 λ“œλŸ¬λ‚΄λ©°, μ’…μ’… λ‹€μ–‘ν•œ ν”Œλž«νΌ 간에 곡톡 κΈ°λ°˜μ„ κ³΅μœ ν•©λ‹ˆλ‹€. ### 정적 뢄석 `.dll` νŒŒμΌμ„ 얻은 ν›„μ—λŠ” [**dnSpy**](https://github.com/dnSpy/dnSpy) **λ˜λŠ”** [**ILSpy**](https://github.com/icsharpcode/ILSpy)와 같은 도ꡬλ₯Ό μ‚¬μš©ν•˜μ—¬ .Net μ½”λ“œλ₯Ό μ •μ μœΌλ‘œ 뢄석할 수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ μ½”λ“œλ₯Ό μˆ˜μ •ν•  수 있게 ν•΄μ€λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 보호λ₯Ό μš°νšŒν•˜κΈ° μœ„ν•΄ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ λ³€μ‘°ν•˜λŠ” 데 맀우 μœ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.\ 앱을 μˆ˜μ •ν•œ ν›„μ—λŠ” λ‹€μ‹œ νŒ¨ν‚Ήν•˜κ³  λ‹€μ‹œ μ„œλͺ…ν•΄μ•Ό ν•œλ‹€λŠ” 점에 μœ μ˜ν•˜μ„Έμš”. ### 동적 뢄석 동적 뢄석은 SSL 핀닝을 ν™•μΈν•˜κ³  [Fridax](https://github.com/NorthwaveSecurity/fridax)와 같은 도ꡬλ₯Ό μ‚¬μš©ν•˜μ—¬ Xamarin μ•±μ˜ .NET λ°”μ΄λ„ˆλ¦¬λ₯Ό λŸ°νƒ€μž„μ—μ„œ μˆ˜μ •ν•˜λŠ” 것을 ν¬ν•¨ν•©λ‹ˆλ‹€. Frida μŠ€ν¬λ¦½νŠΈλŠ” 루트 탐지 λ˜λŠ” 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) ### μž¬μ„œλͺ… [Uber APK Signer](https://github.com/patrickfav/uber-apk-signer) λ„κ΅¬λŠ” λ™μΌν•œ ν‚€λ‘œ μ—¬λŸ¬ APK에 μ„œλͺ…ν•˜λŠ” 과정을 κ°„μ†Œν™”ν•˜λ©°, 변경이 μˆ˜ν–‰λœ ν›„ 앱을 μž¬μ„œλͺ…ν•˜λŠ” 데 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. ## μΆ”κ°€ 정보 * [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) * [https://thecobraden.com/posts/unpacking\_xamarin\_assembly\_stores/](https://thecobraden.com/posts/unpacking\_xamarin\_assembly\_stores/) * [https://medium.com/@justmobilesec/introduction-to-the-exploitation-of-xamarin-apps-fde4619a51bf](https://medium.com/@justmobilesec/introduction-to-the-exploitation-of-xamarin-apps-fde4619a51bf) {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}