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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๊ธฐ๋ณธ ์ ๋ณด
Xamarin์ ์คํ ์์ค ํ๋ซํผ์ผ๋ก, ๊ฐ๋ฐ์๊ฐ .NET ๋ฐ C# ํ๋ ์์ํฌ๋ฅผ ์ฌ์ฉํด iOS, Android, Windows์ฉ ์ฑ์ ๊ฐ๋ฐํ๋๋ก ์ค๊ณ๋์์ต๋๋ค. ์ด ํ๋ซํผ์ ํ๋์ ์ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ํจ์จ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ ๋ค์ํ ๋๊ตฌ์ ํ์ฅ ๊ธฐ๋ฅ์ ๋ํ ์ ๊ทผ์ ์ ๊ณตํฉ๋๋ค.
Xamarin์ ์ํคํ ์ฒ
- For Android, Xamarin์ .NET ๋ฐ์ธ๋ฉ์ ํตํด Android ๋ฐ Java ๋ค์์คํ์ด์ค์ ํตํฉ๋๋ฉฐ, Mono ์คํ ํ๊ฒฝ์์ Android Runtime (ART)์ ํจ๊ป ๋์ํฉ๋๋ค. Managed Callable Wrappers (MCW)์ Android Callable Wrappers (ACW)๋ Mono์ ART ๊ฐ์ ํต์ ์ ์ค๊ฐํ๋ฉฐ, ๋ ๋ค Linux ์ปค๋ ์์์ ๋์ํฉ๋๋ค.
- For iOS, ์ ํ๋ฆฌ์ผ์ด์ ์ Mono ๋ฐํ์ ํ์์ ์คํ๋๋ฉฐ, ์ ์ฒด Ahead of Time (AOT) ์ปดํ์ผ์ ํตํด C# .NET ์ฝ๋๋ฅผ ARM ์ด์ ๋ธ๋ฆฌ๋ก ๋ณํํฉ๋๋ค. ์ด ๊ณผ์ ์ Objective-C Runtime๊ณผ ํจ๊ป UNIX ๊ณ์ด ์ปค๋์์ ๋์ํฉ๋๋ค.
.NET Runtime and Mono Framework
.NET framework๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ํ assemblies, classes, namespaces ๋ฑ์ ํฌํจํ๋ฉฐ, .NET Runtime์ด ์ฝ๋ ์คํ์ ๊ด๋ฆฌํฉ๋๋ค. ์ด๋ ํ๋ซํผ ๋ ๋ฆฝ์ฑ๊ณผ ํ์ ํธํ์ฑ์ ์ ๊ณตํฉ๋๋ค. Mono Framework๋ .NET framework์ ์คํ ์์ค ๊ตฌํ์ผ๋ก, 2005๋ ์ .NET์ Linux๋ก ํ์ฅํ๊ธฐ ์ํด ์์๋์๊ณ ํ์ฌ Microsoft์ ์ง์์ ๋ฐ์ผ๋ฉฐ Xamarin์ด ์ฃผ๋ํ๊ณ ์์ต๋๋ค.
Reverse Engineering Xamarin Apps
Decompilation of Xamarin Assemblies
Decompilation์ ์ปดํ์ผ๋ ์ฝ๋๋ฅผ ์์ค ์ฝ๋๋ก ๋๋๋ฆฌ๋ ๊ณผ์ ์ ๋๋ค. Windows์์๋ Visual Studio์ Modules window๋ฅผ ํตํด ๋์ปดํ์ผ ๋์ ๋ชจ๋์ ์๋ณํ ์ ์์ผ๋ฉฐ, ์ด๋ฅผ ํตํด ์๋ํํฐ ์ฝ๋์ ์ง์ ์ ๊ทผํ๊ณ ๋ถ์์ ์ํด ์์ค ์ฝ๋๋ฅผ ์ถ์ถํ ์ ์์ต๋๋ค.
JIT vs AOT Compilation
- Android๋ Just-In-Time (JIT) ๋ฐ Ahead-Of-Time (AOT) ์ปดํ์ผ์ ์ง์ํ๋ฉฐ, ์คํ ์๋ ์ต์ ํ๋ฅผ ์ํด Hybrid AOT ๋ชจ๋๋ฅผ ์ ๊ณตํฉ๋๋ค. Full AOT๋ Enterprise ๋ผ์ด์ ์ค์์๋ง ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
- iOS๋ Apple์ ๋์ ์ฝ๋ ์คํ ์ ํ ๋๋ฌธ์ AOT ์ปดํ์ผ๋ง ์ฌ์ฉํฉ๋๋ค.
APK/IPA์์ dll ํ์ผ ์ถ์ถ
APK/IPA์ ํฌํจ๋ assemblies์ ์ ๊ทผํ๋ ค๋ฉด ํ์ผ์ ์์ถ ํด์ (unzip)ํ ํ assemblies ๋๋ ํฐ๋ฆฌ๋ฅผ ํ์ํ์ธ์. Android์ ๊ฒฝ์ฐ XamAsmUnZ ๋ฐ xamarin-decompress ๊ฐ์ ๋๊ตฌ๋ก dll ํ์ผ์ ์์ถ์ ํ ์ ์์ต๋๋ค.
python3 xamarin-decompress.py -o /path/to/decompressed/apk
APK๋ฅผ decompileํ ํ unknown/assemblies/ ํด๋ ์์ .dll ํ์ผ๋ค์ด ๋ณด์ด๋ ๊ฒฝ์ฐ, dnSpy๋ฅผ ์ฌ์ฉํด .dlls๋ฅผ ์ง์ ๋ถ์ํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ฒฝ์ฐ์ ๋ฐ๋ผ unknown/assemblies/ ํด๋์ assemblies.blob ๋ฐ assemblies.manifest ํ์ผ์ด ๋ค์ด์์ ์ ์์ต๋๋ค. pyxamstore ๋๊ตฌ๋ Xamarin apps์์ assemblies.blob ํ์ผ์ unpackํ์ฌ .NET assemblies์ ์ ๊ทผํด ์ถ๊ฐ ๋ถ์์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค:
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์ ๋ค์ดํฐ๋ธ
*.aotdata.*ํ์ผ๋ก ์ปดํ์ผ๋ฉ๋๋ค. DLL๋ง ํจ์นํด์๋ ๋ก์ง์ด ๋ณ๊ฒฝ๋์ง ์์ต๋๋ค; IL ๋ณธ๋ฌธ์ด ๋น ํ๋ ์ด์คํ๋์ด๋ฏ๋ก ๋ค์ดํฐ๋ธ ์คํ ์ ํํนํด์ผ ํฉ๋๋ค(์: Frida ์ฌ์ฉ).
์ ์ ๋ถ์
ํ ๋ฒ .dlls๋ฅผ ํ๋ณดํ๋ฉด dnSpy ๋๋ ILSpy ๊ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํด .Net ์ฝ๋๋ฅผ ์ ์ ์ผ๋ก ๋ถ์ํ ์ ์์ผ๋ฉฐ, ์ด๋ฅผ ํตํด ์ฑ ์ฝ๋๋ฅผ ์์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ณดํธ๋ฅผ ์ฐํํ๊ธฐ ์ํด ์ ํ๋ฆฌ์ผ์ด์
์ ๋ณ์กฐํ ๋ ๋งค์ฐ ์ ์ฉํฉ๋๋ค.
์์ ํ์๋ ์ฑ์ ๋ค์ ํจํค์งํ๊ณ ๋ค์ ์๋ช
ํด์ผ ํ๋ค๋ ์ ์ ์ ์ํ์ธ์.
dnSpy๋ ์์นด์ด๋ธ๋์์ผ๋ฉฐ; dnSpyEx ๊ฐ์ ์ ์ง๋๋ ํฌํฌ๋ .NET 8/MAUI ์ด์ ๋ธ๋ฆฌ์ ํจ๊ป ๊ณ์ ์๋ํ๋ฉฐ ๋ค์ ์ ์ฅํ ๋ ๋๋ฒ๊ทธ ์ฌ๋ณผ์ ๋ณด์กดํฉ๋๋ค.
๋์ ๋ถ์
๋์ ๋ถ์์ SSL pinning ํ์ธ๊ณผ Xamarin ์ฑ์ .NET ๋ฐ์ด๋๋ฆฌ๋ฅผ ๋ฐํ์์ ์์ ํ๊ธฐ ์ํด Fridax ๊ฐ์ ๋๊ตฌ ์ฌ์ฉ์ ํฌํจํฉ๋๋ค. Frida ์คํฌ๋ฆฝํธ๋ root detection ๋๋ SSL pinning์ ๋ฐ์ดํจ์คํ๊ธฐ ์ํด ์ฌ์ฉ ๊ฐ๋ฅํ๋ฉฐ, ๋ถ์ ๋ฅ๋ ฅ์ ํฅ์์ํต๋๋ค.
Other interesting Frida scripts:
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


