psychomad/gama

GitHub: psychomad/gama

一套面向 Android 灰帽软件的分析方法论与工具集,通过静态分析、ML 异常评分和 Frida 动态 Hook 识别常规扫描器难以发现的隐私规避行为。

Stars: 0 | Forks: 0

# GAMA **Greyware Analysis and Mitigation Approach** *一种以分析师为先的 Android greyware(灰帽软件)调查方法论与工具集* [![Framework](https://img.shields.io/badge/GAMA-Framework-1A3A5C?style=flat-square)](https://github.com/psychomad/gama-framework) [![Intel](https://img.shields.io/badge/GAMA-Intel-C0392B?style=flat-square)](https://github.com/psychomad/gama-intel) [![Deep](https://img.shields.io/badge/GAMA-Deep-3C3489?style=flat-square)](https://github.com/psychomad/gama-deep) [![License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](LICENSE)
## 什么是 GAMA? GAMA 是一套用于识别 Android 应用中 **greyware** 行为的方法论和工具集 —— 旨在解决标准自动化扫描器无法覆盖的、介于合法软件与恶意软件之间的灰色地带。 标准扫描器寻找的是特征码。而 GAMA 寻找的是**行为模式**:应用如何路由数据、通过哪些通道规避网络监控,以及 SDK 在发起任何出站请求之前如何相互通信。 ## GAMA 解决的问题 现代 Android 应用普遍使用广告和分析 SDK,收集的数据远超其隐私政策声明的范围。这种收集行为通过标准监控工具不可见的通道进行: - **自定义 URI scheme** (`mv://`, `global://`, `applovin://`) —— 数据在 WebView 的 `shouldOverrideUrlLoading` 中传递,发生在任何网络调用之前 - **编码字符串** —— 隐藏在字节码中 Base64/十六进制格式的端点和 URI - **后台持久化** —— 在应用强制停止后仍能存活的 WorkManager 和 JobScheduler 任务 - **域前置 (Domain fronting)** —— 通过 CDN 路由流量,其中 SNI 与实际目的地不匹配 这些不是恶意软件技术。它们是 greyware —— 旨在最大化数据收集同时规避隐私控制的刻意设计选择。 ## 生态系统 ``` APK │ ├─► GAMA-Intel ──────────────────── Automated static analysis │ │ URI scanner 31 findings on Airport Empire Idle │ │ SDK fingerprint 11 SDKs identified │ │ Manifest analysis STIX 2.1 report │ │ Encoded string decoder │ └─► workspace/ │ ├── findings.jsonl │ ├── uri_scan.json │ ├── sdk_map.json │ └── report.stix.json │ ├─► GAMA-Deep ───────────────────── ML anomaly scoring (Rust) │ │ Static features (128-dim) Anomaly score 0–100 │ │ Smali embeddings (256-dim) Channel contributions │ │ Network sequences (256-dim) Train on your own dataset │ └─► workspace/deep/gama_deep.json │ └─► GAMA Framework ──────────────── Analyst workspace (CLI) │ Phase 0: Hypothesis 7-phase methodology │ Phase 1: Static review Finding classification │ Phase 3: Frida dynamic Enforcement rules │ Phase 5: Classification Class A/B/C/D │ Phase 6: Enforcement rules └─► workspace/findings.jsonl ``` | 工具 | 类型 | 职责 | |------|------|------| | [**GAMA Framework**](https://github.com/psychomad/gama-framework) | 交互式 CLI (Python) | 分析师工作区 —— 7 阶段结构化方法论 | | [**GAMA-Intel**](https://github.com/psychomad/gama-intel) | Pipeline (Python) | 自动化静态分析,STIX 2.1 报告生成 | | [**GAMA-Deep**](https://github.com/psychomad/gama-deep) | ML 引擎 (Rust) | 三通道异常评分 | | **GAMA-Community** *(即将推出)* | 知识库 | 共享已确认的发现,基于 PR 的治理 | ## 快速开始 ### 1. 安装依赖 ``` # Java (apktool 和 jadx 必需) sudo apt install -y default-jre # apktool sudo wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool \ -O /usr/local/bin/apktool sudo wget https://github.com/iBotPeaches/Apktool/releases/download/v2.10.0/apktool_2.10.0.jar \ -O /usr/local/bin/apktool.jar sudo sed -i 's|exec java -jar|exec java -Xmx2g -jar|' /usr/local/bin/apktool sudo chmod +x /usr/local/bin/apktool # jadx JADX_VER=$(curl -s https://api.github.com/repos/skylot/jadx/releases/latest \ | python3 -c "import sys,json; print(json.load(sys.stdin)['tag_name'].lstrip('v'))") wget https://github.com/skylot/jadx/releases/download/v${JADX_VER}/jadx-${JADX_VER}.zip -O /tmp/jadx.zip sudo mkdir -p /opt/jadx && sudo unzip -q /tmp/jadx.zip -d /opt/jadx sudo ln -sf /opt/jadx/bin/jadx /usr/local/bin/jadx ``` ### 2. 克隆工具 ``` git clone https://github.com/psychomad/gama-framework git clone https://github.com/psychomad/gama-intel git clone https://github.com/psychomad/gama-deep ``` ### 3. 构建 GAMA-Deep (Rust) ``` cd gama-deep cargo build --release sudo cp target/release/gama-deep /usr/local/bin/ ``` ### 4. 安装 Python 依赖 ``` cd gama-intel pip install -r requirements.txt ``` ## 使用示例 ### 单个 APK 的静态分析 ``` cd gama-intel python3 -m gama_intel.cli analyse app.apk --skip-dynamic --skip-network ``` ### 复用现有的 apktool 输出(针对大型 APK 更快) ``` python3 -m gama_intel.cli analyse app.apk \ --import-apktool path/to/apktool_out/ \ --skip-dynamic --skip-network ``` ### ML 评分 ``` # 使用 GAMA-Deep 分析工作区 gama-deep analyse gama-intel/workspace/20260315_170023_com-app/ # 标签和训练 echo '{"class": "C"}' > workspace/20260315_.../deep/label.json gama-deep train gama-intel/workspace/ --epochs 50 ``` ### 交互式分析师会话 ``` cd gama-framework python3 main.py # → 创建工作区 # → 阶段 0:文档假设 # → 阶段 1:运行静态分析 # → 阶段 5:分类发现 A/B/C/D # → 阶段 6:生成执行规则 ``` ### Frida 动态分析 (GAMA-T001) ``` # 运行时 Hook URI scheme IPC 通道 cat > /tmp/gama_t001.js << 'EOF' Java.perform(function() { var WebViewClient = Java.use("android.webkit.WebViewClient"); WebViewClient.shouldOverrideUrlLoading.overload( "android.webkit.WebView", "java.lang.String" ).implementation = function(view, url) { var scheme = url.split("://")[0]; if (!["https","http","file","content","data"].includes(scheme)) { console.log(JSON.stringify({ ts: new Date().toISOString(), technique: "GAMA-T001", scheme: scheme, url: url.substring(0, 200) })); } return this.shouldOverrideUrlLoading(view, url); }; }); EOF frida -U -n com.example.app -l /tmp/gama_t001.js ``` ## 分类系统 | 类别 | 定义 | 示例 | |-------|------------|---------| | **A** | 运营性 —— 与声明的目的相称 | 分析 SDK 收集会话数据,并在隐私政策中披露 | | **B** | 不成比例 —— 收集超出声明的数据 | 广告 SDK 收集隐私政策中未提及的设备指纹 | | **C** | 隐蔽性 —— 使用规避手段(URI 绕过、编码、JNI) | `mv://` 通过 WebView IPC 路由数据,对 VPN 监控不可见 | | **D** | 欺骗性 —— 直接违背隐私政策 | 用户购买“无广告”层级后,跟踪依然活跃 | ## GAMA 技术目录 | ID | 名称 | ATT&CK Mobile | 检测 | |----|------|---------------|-----------| | GAMA-T001 | 自定义 URI scheme IPC 绕过 | T1637.002 (提议) | URI 扫描器 + Frida WebView hook | | GAMA-T002 | 安装后静默载荷 | T1407 | 大小增量 + 动态下载 hook | | GAMA-T003 | 后台任务持久化 | T1624.003 (提议) | WorkManager hook + 终止后 DNS | | GAMA-T004 | 通过 CDN 进行域前置 | T1665 | Zeek 中的 SNI 与目标 IP 关联分析 | | GAMA-T005 | JNI 策略绕过 | 提议 | Native 库熵 + JNI 符号分析 | | GAMA-T006 | 高级付费层级视觉假象 | 提议 | 付费层级激活后的运行时捕获 | | GAMA-T007 | 编码字符串混淆 | T1406 | smali 字符串上的 Base64/十六进制解码器 | ## 案例研究:Airport Empire Idle **应用:** com.SekGames.AirportEmpireIdle v0.7.0 — 140MB 放置类游戏 **GAMA-Intel 结果:** ``` Findings: 31 By technique: GAMA-T001: 30, GAMA-T007: 1 SDKs: 11 identified (Mintegral, AppLovin, Unity, Adjust, Firebase...) Encoded hits: 21 Base64/hex strings decoded ``` **主要发现:** | URI Scheme | 评分 | 证据 | 分类 | |------------|-------|----------|----------------| | `mv://` | 12 | 4 次出现,smali_classes9,WebView 处理器共存 | **Class-C** | | `mraid://` | 12 | 7 个文件中出现 18 次,跟踪上下文:event | Class-B | | `applovin://` | 12 | 6 次出现,跟踪上下文:event, ad | Class-B | | `tcp://` | 11 | WebView 上下文中出现 1 次 —— 异常 | Class-C 候选 | | `global://` | 8 | 2 个文件中出现 99 次 —— 高频总线 | 待动态分析 | **训练后的 GAMA-Deep 评分:** ``` { "anomaly_score": 51.0, "static_contribution": 0.23, "smali_contribution": 0.77, "network_contribution": 0.0, "gama_technique": "GAMA-T005" } ``` **`mv://` 发现成为了 CENT-2026-001** —— GAMA Community 知识库中的首个条目。 ## 社区模块 GAMA-Deep 支持社区扩展模块。只需将 Python 文件放入 `~/.gama/modules/`: ``` class MyModule: name = "my-module" version = "1.0.0" input_spec = ["static/uri_scan.json"] def analyse(self, workspace_path: Path) -> list: # Return list of finding dicts return [] ``` GAMA-Intel 会在分析时自动加载所有模块。无需配置。 **社区模块的思路:** - Exodus Privacy 跟踪器数据库查询 - VirusTotal APK 哈希查询 - GDPR 同意字符串验证器 - 隐私政策 NLP 分析器 - CVE/NVD 依赖项检查器 ## 路线图 - [x] GAMA Framework v1.0 — 7 阶段方法论 CLI - [x] GAMA-Intel v1.0 — 自动化静态分析 pipeline - [x] GAMA-Deep v0.1 — ML 异常评分 (Rust, 仅 CPU) - [x] CENT-2026-001 — 首个已确认的社区发现 - [ ] GAMA-Community v0.1 — GitHub 上的公共知识库 - [ ] GAMA-Deep v0.2 — 完整的反向传播训练 - [ ] 针对所有 GAMA 技术的 Frida 脚本库 - [ ] 网络分析集成 (Zeek + 终止后检测) ## 作者 **CenturiaLabs / ClickSafe UAE** [audit.centurialabs.pl](https://audit.centurialabs.pl) [github.com/psychomad](https://github.com/psychomad) ## 许可证 MIT — 详见 [LICENSE](LICENSE)
标签:Android 安全, APK 分析, Cloudflare, GAMA, JS文件枚举, MITRE ATT&CK, SDK 行为分析, URI Scheme 漏洞, 云安全监控, 可视化界面, 命令控制, 域前置检测, 威胁情报, 开发者工具, 数据采集, 灰软件分析, 网络安全, 行为模式识别, 逆向工具, 隐私保护, 隐私合规检测, 隐私泄露, 静态分析