安卓安全分析器
MCP服务器用于Android应用程序源代码的静态安全分析。在Cloudflare Workers上作为远程MCP服务器通过Streamable HTTP运行。
它做什么
分析Android项目源文件-- 不建设项目 --并返回结构化安全报告。分析包括:
- 清单分析 --导出组件、危险权限、明文流量、调试标志、备份设置、SDK版本
- Gradle/构建配置 --发布构建错误配置、过时的SDK、可疑的依赖关系、硬编码的秘密
- 源代码(Java/Kotlin) --不安全的WebView、SSL/TLS旁路、弱加密、SQL注入模式、进程执行、不安全的文件存储、PendingIntent问题
- XML配置 --网络安全配置缺陷,文件提供程序路径过宽
- 秘密扫描 -API密钥、令牌、密码、私钥、云证书、高熵字符串
所有分析都是基于正则表达式/模式的,并在Workers运行时本地运行,不需要外部工具、Java或Android SDK。
建筑
POST /mcp ──► McpServer (JSON-RPC 2.0) ──► Tool Router
│
┌───────────────────────────────┘
▼
Orchestrator
│
┌─────────┼─────────┬─────────────┬──────────────┐
▼ ▼ ▼ ▼ ▼
Manifest Gradle Source Code XML Config Secret
Analyzer Analyzer Analyzer Analyzer Scanner
│ │ │ │ │
└─────────┴─────────┴─────────────┴──────────────┘
│
▼
Scoring + Deduplication ──► AnalysisReport关键设计决策:
- 无状态--没有会话,没有持久对象
- 最小化MCP JSON-RPC 2.0实现(无大量SDK依赖)
- 具有可扩展规则注册表的数据驱动规则引擎
- 具有统一Finding类型的独立分析仪
- 通过以下方式进行轻量级XML解析
fast-xml-parser - 通过以下方式进行输入验证
zod - 捆绑包大小:约66KB gzip压缩
MCP工具
| 工具 | 说明 |
|---|---|
analyze_android_project | 项目文件的全面安全分析 |
list_android_security_checks | 列出所有已实施的安全规则 |
explain_finding | 对特定规则的详细解释 |
health | 服务器状态和规则引擎统计信息 |
安装
托管服务器(建议用于Cline/MCP客户端): 无需本地安装。服务器运行在:
https://android-security-analyzer.ako-labs.workers.dev/mcp
将此URL添加到MCP客户端配置中(请参阅 从MCP客户端连接 在......下面
地方发展:
npm install发展
npm run dev这将启动本地Wrangler开发服务器。MCP端点位于 http://localhost:8787/mcp.
部署
npm run deploy部署到Cloudflare Workers。需要 wrangler 身份验证(npx wrangler login).
测试
npm test # Run all tests
npm run test:watch # Watch mode
npm run typecheck # TypeScript type checking本地MCP测试
初始化连接
Unix:
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'Windows(PowerShell):
(Invoke-WebRequest -Method Post -Uri "http://localhost:8787/mcp" -ContentType "application/json" -Body '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' -UseBasicParsing).Content列出可用工具
Unix:
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'Windows(PowerShell):答案来了 result.tools;要将列表视为JSON,请使用原始答案:
(Invoke-WebRequest -Method Post -Uri "http://localhost:8787/mcp" -ContentType "application/json" -Body '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' -UseBasicParsing).Content或通过对象: (Invoke-RestMethod ...).result.tools | ConvertTo-Json -Depth 5
检查健康状况
Unix:
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"health","arguments":{}}}'Windows(PowerShell):
(Invoke-WebRequest -Method Post -Uri "http://localhost:8787/mcp" -ContentType "application/json" -Body '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"health","arguments":{}}}' -UseBasicParsing).Content运行分析(最小示例)
Unix:
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "analyze_android_project",
"arguments": {
"projectName": "TestApp",
"files": [
{
"path": "app/src/main/AndroidManifest.xml",
"content": ""
}
]
}
}
}'Windows(PowerShell):
$body = @{
jsonrpc = "2.0"
id = 4
method = "tools/call"
params = @{
name = "analyze_android_project"
arguments = @{
projectName = "TestApp"
files = @(
@{
path = "app/src/main/AndroidManifest.xml"
content = ""
}
)
}
}
} | ConvertTo-Json -Depth 10
(Invoke-WebRequest -Method Post -Uri "http://localhost:8787/mcp" -ContentType "application/json" -Body $body -UseBasicParsing).Content从MCP客户端连接
添加到MCP客户端配置中:
{
"mcpServers": {
"android-security-analyzer": {
"url": "http://localhost:8787/mcp"
}
}
}对于生产(托管):
{
"mcpServers": {
"android-security-analyzer": {
"url": "https://android-security-analyzer.ako-labs.workers.dev/mcp"
}
}
}安全规则
分析器在5个类别中实施了53条安全规则:
| 类别 | 前缀 | 规则 | 示例 |
|---|---|---|---|
| 清单 | MAN-\* | 17 | 可调试、允许备份、导出组件、权限 |
| Gradle | GRD-\* | 9 | 发布配置、SDK版本、依赖关系、秘密 |
| 来源 | SRC-\* | 17 | WebView、SSL/TLS、加密、注入、文件存储 |
| XML配置 | XML-\* | 4 | 网络安全配置,文件提供程序路径 |
| 机密 | SEC-\* | 7 | API密钥、令牌、密码、云凭据 |
每个发现包括:
- 稳定规则ID
- 严重性(严重/高/中/低/信息)和置信度(高/中、低)
- 文件路径和行号(可确定时)
- 证据摘录
- CWE和OWASP移动十大映射
- 可采取行动的建议
评分
根据严重程度计算风险评分(0-100):
- 关键:9分
- 高:6分
- 中等:3分
- 低:1分
- 信息:0分
原始总和按照预期的最大值50点进行归一化。
局限性
- 不是SAST的替代品 --基于模式/正则表达式的启发式方法,而不是完整的AST/数据流分析
- 无需构建 --分析原始源代码,因此构建时转换不可见
- 可能出现误报 --特别是对于秘密扫描和一些代码模式
- 工人限制 --128MB内存限制、CPU时间限制、无文件系统访问
- 无APK/AAB分析 --仅源代码
- 无程序间分析 --模式是按文件匹配的,而不是跨调用图匹配的
项目结构
src/
├── index.ts # Worker entry point
├── server/
│ ├── mcp.ts # MCP JSON-RPC 2.0 handler
│ └── tools/ # MCP tool implementations
│ ├── analyzeAndroidProject.ts
│ ├── listAndroidSecurityChecks.ts
│ ├── explainFinding.ts
│ └── health.ts
├── core/
│ ├── types.ts # TypeScript types & Zod schemas
│ ├── scoring.ts # Risk score computation
│ ├── registry.ts # Rule registry
│ └── orchestrator.ts # Analysis orchestrator
├── analyzers/
│ ├── manifestAnalyzer.ts
│ ├── gradleAnalyzer.ts
│ ├── sourceAnalyzer.ts
│ ├── xmlConfigAnalyzer.ts
│ └── secretScanner.ts
├── parsers/
│ ├── xml.ts # XML parser wrapper
│ ├── gradle.ts # Gradle file parser
│ ├── source.ts # Source code pattern matcher
│ └── files.ts # File classifier
├── rules/
│ ├── manifestRules.ts
│ ├── gradleRules.ts
│ ├── sourceRules.ts
│ ├── xmlRules.ts
│ └── secretRules.ts
├── mappings/
│ ├── cwe.ts # CWE descriptions
│ └── owaspMobile.ts # OWASP Mobile Top 10
└── utils/
├── lines.ts # Line number utilities
├── paths.ts # Path classification
└── text.ts # Text utilities
test/
├── fixtures/ # Sample Android project files
├── unit/ # Unit tests per module
└── integration/ # Full analysis integration tests添加新规则
- 在相应的文件中定义规则
src/rules/ - 在相应的分析仪中添加检测逻辑
src/analyzers/ - 在中添加CWE映射
src/mappings/cwe.ts如有需要 - 添加测试用例
- 该规则通过以下方式自动注册
src/core/registry.ts
许可证
麻省理工学院
