nao1215/mobilepkg

GitHub: nao1215/mobilepkg

一站式移动应用安装包检查工具,无需 Android SDK 或 Xcode,即可在数秒内完成元数据提取、签名验证与安全风险发现。

Stars: 2 | Forks: 0

# mobilepkg [![MultiPlatformUnitTest](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/195d5ef0f6172226.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/test.yml) [![Coverage](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/c2bbd440ef172227.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/coverage.yml) [![Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/f88f2bb08c172228.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/build.yml) [![reviewdog](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/ba1be16904172229.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/reviewdog.yml) [![Go Reference](# mobilepkg [![MultiPlatformUnitTest](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/195d5ef0f6172226.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/test.yml) [![Coverage](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/c2bbd440ef172227.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/coverage.yml) [![Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/f88f2bb08c172228.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/build.yml) [![reviewdog](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/ba1be16904172229.svg)](https://github.com/nao1215/mobilepkg/actions/workflows/reviewdog.yml) [![Go Reference](https://pkg.go.dev/badge/github.com/nao1215/mobilepkg.svg)](https://pkg.go.dev/github.com/nao1215/mobilepkg) ![logo](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/fdbe2cbe40172231.png) mobilepkg 能够检查 APK、AAB、APKS、XAPK 和 IPA 文件,并将包的元数据及安全发现输出为 JSON、Markdown 或 RDJSONL 格式。它主要用于发布分类和 CI 检查。 它将安装包作为 zip 压缩包读取,在进程内解析 manifest 和 DEX 字节码,并在几秒钟内完成。无需 Android SDK、Xcode 或设备。支持在 Linux、Windows 和 macOS(Go 1.25+)上运行。 ## 范围 - 从 Android 包(APK、XAPK、APKS、AAB)中提取 Manifest 元数据、签名信息、权限、导出组件、Deep Link 和网络端点。 - 扫描基础 APK 和拆分 APK 中的 DEX 字节码,以查找硬编码的敏感信息、明文 HTTP URL、危险 API 调用以及不安全的 WebView 配置。 - 直接读取 XAPK 和 APKS 包——无需事先解压。 - 用于 `$GITHUB_STEP_SUMMARY` 和 Pull Request 评论的 Markdown 报告。 - 基线差异比对,用于跟踪不同版本之间权限、组件和版本的变更。 - CI 集成:当发现结果超出严重性阈值时,`--fail-on warn` 会以非零状态码退出。 ### 已知限制与常见误报 - 对于维护良好的生产级应用,mobilepkg 通常会报告 `allow_backup`、少量导出组件以及一些来自第三方库的危险 API 调用。源自库的 API 调用(例如使用 `Runtime.exec` 的崩溃报告器)会自动降级为 `warn/medium`。 - 从 DEX 字符串中发现的明文 URL 可能包含恰好使用 HTTP 的合法日志记录或配置端点。 - iOS IPA 检查涵盖 Entitlements、ATS 设置、代码签名证书、Provisioning Profile 过期时间、URL Schemes 和 Associated Domains。它不会扫描已编译的 Swift/ObjC 二进制文件以查找 API 调用或敏感信息。Android 的检查更为深入。 - WebView 参数跟踪是轻量级的:它仅检查紧邻其前的 `const/4` 或 `const/16` 指令。对于非平凡的参数流(例如,从字段加载的值或计算出的值)会回退到保守的报告方式。 | 格式 | 平台 | 描述 | |--------|----------|-------------| | APK | Android | 标准 Android 安装包 | | XAPK | Android | APKPure 扩展包 | | APKS | Android | Bundletool APK 集合 | | AAB | Android | Android App Bundle | | IPA | iOS | 标准 iOS 安装包 | ## 安装 ``` go install github.com/nao1215/mobilepkg/cmd/mobilepkg@latest # CLI go get github.com/nao1215/mobilepkg # library ``` ## 命令行界面 ### inspect — 检查移动安装包 ``` $ mobilepkg inspect app.apk # JSON output (default) $ mobilepkg inspect --format markdown app.apk # Markdown summary $ mobilepkg inspect --format markdown app.xapk # XAPK works the same way $ mobilepkg inspect --fail-on warn app.apk # CI: exit 1 if severity >= warn $ mobilepkg inspect --baseline prev.json app.apk # diff against previous result ``` #### Markdown 输出 `--format markdown` 输出会优先展示最具可操作性的信息——主要发现及严重性统计——然后再展开说明组件和端点的详细信息。它专为 `$GITHUB_STEP_SUMMARY`、Pull Request 评论和人工审查而设计。
示例:易受攻击的应用 (AndroGoat) 在一个故意设计的易受攻击的应用(如 [AndroGoat](https://github.com/satishpatnayak/AndroGoat))上,报告会突出显示 Debug 构建、硬编码的 AWS 密钥、通过 `Runtime.exec` 进行的命令注入以及不受保护的导出组件: ``` ## 主要发现 > [!WARNING] > 10 finding(s) at warning severity or above. | ID | Severity | Confidence | Message | |----|----------|------------|---------| | dex.api.java.lang.Runtime.exec... | error | high | Runtime.exec() called — potential command injection risk | | dex.secret.aws_key... | error | high | potential aws_key found in DEX string table | | manifest.debuggable | error | high | application is debuggable | | signing.debug_cert | error | high | signed with debug certificate | | dex.cleartext... | warn | medium | cleartext HTTP URL found in DEX strings: demo.testfire.net | | manifest.allow_backup | warn | high | application allows backup | | exported.provider... | warn | high | exported provider: ...ContentProviderActivity | ```
示例:正常应用 (F-Droid) 在一个维护良好的生产级应用(如 F-Droid)上,发现的问题严重性较低。源自库的 API 调用会以较低的严重性级别进行标记。Deep Link 和端点部分展示了应用注册的 URI 处理程序: ``` ## 主要发现 > [!WARNING] > 6 finding(s) at warning severity or above. | ID | Severity | Confidence | Message | |----|----------|------------|---------| | dex.api...Runtime.exec...compat.FileCompat | error | high | Runtime.exec() called (in app code) | | dex.api...Runtime.exec...acra... | warn | medium | Runtime.exec() called (in library) | | dex.cleartext.logback.qos.ch | warn | medium | cleartext HTTP URL found in DEX strings | | manifest.allow_backup | warn | high | application allows backup | ## Network Endpoints | Endpoint | Source | Confidence | |----------|--------|------------| | f-droid.org | intent_filter | high | | play.google.com | intent_filter | high | | market://details | intent_filter | high | ```
#### JSON 输出 默认的 JSON 输出是一个 `ReportFile`,包含 `schema_version`、`tool_version` 和 `result`:
JSON 示例 (AndroGoat) ``` { "schema_version": "1.0.0", "tool_version": "0.1.0", "result": { "platform": "android", "format": "apk", "identity": { "identifier": "owasp.sat.agoat", "display_name": "AndroGoat - Insecure App (Kotlin)" }, "version": { "marketing": "1.0", "build": "1" }, "debuggable": true, "allow_backup": true, "permissions": [ { "canonical": "camera", "raw_name": "android.permission.CAMERA", "source": "manifest" }, { "canonical": "network", "raw_name": "android.permission.INTERNET", "source": "manifest" } ], "exported_components": [ { "kind": "provider", "name": "owasp.sat.agoat.ContentProviderActivity", "exported": true }, { "kind": "receiver", "name": "owasp.sat.agoat.ShowDataReceiver", "exported": true } ], "signing": { "scheme": "v1+v2", "certificates": [{ "subject": "Android Debug", "issuer": "Android Debug" }] }, "findings": [ { "severity": "error", "id": "manifest.debuggable", "message": "application is debuggable" }, { "severity": "error", "id": "signing.debug_cert", "message": "signed with debug certificate" }, { "severity": "warn", "id": "manifest.allow_backup", "message": "application allows backup" } ], "secret_candidates": [], "diagnostics": [] } } ```
#### 基线差异比对与 CI 保存报告并将其用作下次运行的基线。`--baseline` 标志接受由上一次 `inspect` 运行生成的 `report.json` 文件: ``` # 保存今日结果 mobilepkg inspect app.apk > baseline.json # 在 CI 中与 baseline 进行比较 mobilepkg inspect --baseline baseline.json --fail-on warn app.apk ``` 当指定了 `--fail-on` 时,输出将包含一个带有 `passed`、`reasons` 和 `triggering_findings` 的 `verdict` 字段,如果违反了策略,命令将以退出码 1 退出。 ### compare — 比较两个安装包 ``` $ mobilepkg compare old.apk new.apk ``` 显示身份、版本和入口点的变更,以及新增/移除的权限、导出组件和网络端点。 ## 库 ### InspectFile — 一次调用,获取全部结果 ``` result, err := mobilepkg.InspectFile(ctx, "app.apk") if err != nil { log.Fatal(err) } fmt.Println(result.Identity.Identifier) // "com.example.app" fmt.Println(result.Debuggable) // true for _, f := range result.Findings { fmt.Printf("[%s] %s\n", f.Severity, f.Message) } ``` ### 检测覆盖范围 | 类别 | 发现项 | |----------|----------| | Manifest | `debuggable`、`allowBackup`、`usesCleartextTraffic`、`testOnly`、`profileableByShell` | | 网络安全配置 | Base-config 明文、按域名明文、嵌套 domain-config 继承、debug-overrides | | 签名 | Debug 证书、过期证书、仅 v1 签名、弱摘要算法 (MD5/SHA-1)、弱密钥长度 (RSA<2048, ECDSA<256)、自签名测试证书 | | Provisioning (iOS) | 过期的 Provisioning Profile | | 组件 | 带有 intent-filter 和 Deep Link 的导出 Activity/Service/Receiver/Provider。无权限组件会提升为 warn/error。标记可浏览的 Activity。提取 Provider authorities、readPermission、writePermission、grantUriPermissions。 | | 权限 | 危险权限 (CAMERA、SMS、LOCATION 等) | | iOS ATS | `NSAllowsArbitraryLoads`、不安全的例外域名 (`NSExceptionAllowsInsecureHTTPLoads`) | | iOS Entitlements | `get-task-allow`(Debug 构建)、URL Schemes、Associated Domains | | 敏感信息 | 基于正则表达式扫描 Manifest/Plist 元数据和 DEX 字符串表(AWS 密钥、GCP API 密钥、GitHub Token、私钥、Bearer Token、Firebase URL、通用 api_key/secret/credential 模式)。两个来源使用相同的模式列表。 | | DEX WebView | `setJavaScriptEnabled(true)`、`addJavascriptInterface`、`setAllowFileAccess(true)`、`setAllowUniversalAccessFromFileURLs(true)`、`setWebContentsDebuggingEnabled(true)`、`setMixedContentMode`、`SslErrorHandler.proceed` 绕过、`WebView.loadUrl("http://...")`。通过前置的 `const/4`/`const/16` 进行布尔参数跟踪。源自库的调用以较低的严重性报告。 | | DEX API | `Runtime.exec`、`ProcessBuilder`、`DexClassLoader`、`PathClassLoader`、`Method.invoke`、`SmsManager.sendTextMessage`、`DevicePolicyManager.resetPassword`、`Cipher.getInstance`。源自库的调用以较低的严重性报告。 | | DEX 明文 | 字符串表中的 `http://` URL(排除 localhost/schema/spec URL)。 | ### 失败条件 (CI) ``` verdict := mobilepkg.Check(result, mobilepkg.DefaultFailPolicy()) if !verdict.Passed { os.Exit(1) } ``` ### 基线差异比对 ``` result, _ := mobilepkg.InspectWithBaseline(ctx, "new.apk", prevResult) fmt.Println(result.Diff.VersionChanged) fmt.Println(result.Diff.AddedComponents) ``` ### 输出格式 ``` rf := mobilepkg.NewReportFile(result, "1.0.0") mobilepkg.WriteReportJSON(os.Stdout, rf) // JSON mobilepkg.WriteSummaryMarkdown(os.Stdout, rf) // Markdown mobilepkg.WriteRDJSONL(os.Stdout, result.Findings, "app.apk") // reviewdog ``` ## GitHub Actions ``` - run: mobilepkg inspect --fail-on warn app.apk > report.json - run: mobilepkg inspect --format markdown app.apk >> "$GITHUB_STEP_SUMMARY" ``` ## 测试数据 示例使用了 [AndroGoat](https://github.com/satishpatnayak/AndroGoat)([v2.0.1](https://github.com/satishpatnayak/AndroGoat/releases/tag/v2.0.1)),这是一个故意设计的易受攻击的 Android 应用。该 APK 位于 `testdata/no_commit/` 目录下,仅供本地测试使用,不会被提交到代码库。 ``` mkdir -p testdata/no_commit curl -L -o testdata/no_commit/AndroGoat.apk \ https://github.com/satishpatnayak/AndroGoat/releases/download/v2.0.1/AndroGoat.apk ``` ## 相关或受启发项目 - [shogo82148/androidbinary](https://github.com/shogo82148/androidbinary):使用 golang 编写的 Android 二进制文件解析器 - [nao1215/deapk(已公开归档)](https://github.com/nao1215/deapk):解析 Android 安装包,获取元数据及更多信息。 ## 许可证 [MIT License](LICENSE)
标签:AAB, Android安全分析, APKS, APK分析工具, DEX字节码扫描, EVTX分析, Go语言, IPA检查, XAPK, 云安全监控, 元数据提取, 包管理工具, 威胁建模, 安全合规, 安全扫描, 批量测试, 日志审计, 时序注入, 移动应用安全, 移动开发, 程序破解, 签名验证, 网络代理, 网络安全, 跨平台工具, 进程保护, 隐私保护, 静态分析