dasabhijeet/LinkGuard-Application
GitHub: dasabhijeet/LinkGuard-Application
LinkGuard是一个自托管的URL威胁情报API,利用多评分器和AI摘要来检测和解释URL安全风险。
Stars: 1 | Forks: 0
# LinkGuard 应用
自托管的URL威胁情报API。基于数学的评分引擎,通过OpenRouter提供AI驱动的摘要。也可以使用其他LLM,但我选择它是为了简便。
未来的目标是在本地托管AI并使用此应用,从而避免将数据发送到第三方服务器。
本项目灵感来源于我早期的网络安全后端演示项目:https://github.com/dasabhijeet/Signal-Transfer-Pipeline
## 功能介绍
通过六个独立的评分器扫描URL,然后将结果发送给一个LLM(通过OpenRouter/免费层)以生成简明的英文安全摘要。
| 评分器 | 方法 | 检查内容 |
|------------|------------|------------------------------------------------------------|
| 熵值 | numpy数学 | 香农熵检测随机/混淆的URL |
| 同形字符 | 字符串操作 | 字符替换冒充品牌(例如paypa2.com) |
| 顶级域名 | 查询 | 高滥用风险的顶级域名(.tk, .xyz, .click) |
| 子域名 | 数学 | 深层嵌套子域名隐藏真实域名 |
| 关键词 | 字符串操作 | URL路径和查询中的钓鱼关键词密度 |
| 信誉度 | 数据库查询 | 来自CSV种子SQLite列表的域名信誉 |
**AI摘要** — 结果通过OpenRouter发送至 `openrouter/free`。一次HTTP POST请求。如果不可用,会优雅地回退。模型可能随时间变化,因此在运行实际项目前,请使用test_openrouter.py测试LLM API。根据我的测试,免费LLM用于安全摘要效果并不差,建议优先使用。
## 设置
```
# 安装依赖项
pip install fastapi uvicorn[standard] python-dotenv httpx numpy
# 配置
cp .env.example .env
# 编辑 .env — 添加你的 OPENROUTER_API_KEY
# 运行
python app.py
```
## API端点
除 `/health` 外,所有端点都需要请求头:`x-api-key: linkguard-secret-key`(可根据需求自定义此密钥,更多API安全改进将在未来版本中实现。)
| 方法 | 端点 | 描述 |
|--------|------------------------|--------------------------------------|
| POST | `/scan` | 扫描一个URL |
| GET | `/history?url=...` | 查询一个URL的历史扫描记录 |
| POST | `/history` | 通过请求体查询历史扫描记录 |
| GET | `/stats` | 总扫描数、风险计数、前10域名 |
| GET | `/metrics` | Prometheus兼容的纯文本格式(未来版本)|
| GET | `/health` | 健康检查,无需API密钥 |
### POST /scan — 响应示例
```
{
"url": "https://secure-login-verify-account.tk/paypal",
"risk_level": "MALICIOUS",
"total_score": 87,
"ai_summary": "This URL shows multiple high-risk signals including a high-abuse TLD and phishing keywords. It appears to impersonate PayPal. Avoid clicking this link.",
"breakdown": [
{ "scorer": "tld", "score": 20, "reason": "TLD '.tk' has high phishing abuse rate" },
{ "scorer": "keywords", "score": 25, "reason": "4 phishing keywords detected: verify, login, secure, account" },
{ "scorer": "reputation", "score": 40, "reason": "domain flagged as bad reputation" }
],
"scanned_at": "2026-05-17T12:00:00+00:00"
}
```
## 配置 (`.env`)
| 变量 | 默认值 | 描述 |
|------------------------|--------------------------------------|--------------------------------------|
| `DB_PATH` | `linkguard.db` | SQLite数据库路径 |
| `REPUTATION_CSV` | `domain_reputation.csv` | 域名信誉列表 |
| `OPENROUTER_API_KEY` | — | 您的OpenRouter API密钥 |
| `OPENROUTER_MODEL` | `openrouter/free` | 用于生成摘要的模型 |
| `API_KEY` | `linkguard-secret-key` | 所有端点使用的API密钥 |
| `SUSPICIOUS_THRESHOLD` | `30` | “可疑”风险的分数阈值 |
| `MALICIOUS_THRESHOLD` | `60` | “恶意”风险的分数阈值 |
| `HOST` | `127.0.0.1` | 服务器绑定地址 |
| `PORT` | `8000` | 服务器端口 |
## 项目结构
```
linkguard/
├── app.py # FastAPI + pipeline
├── utils/
│ ├── sqlite_utils.py # All DB operations
│ └── ai_summary.py # AI/LLM integration
├── scorers/
│ ├── entropy.py # Shannon entropy via numpy
│ ├── homoglyph.py # Brand impersonation detection
│ ├── subdomain.py # Subdomain depth scoring
│ ├── tld.py # TLD risk list
│ ├── keywords.py # Phishing keyword density
│ └── reputation.py # Domain reputation DB lookup
├── domain_reputation.csv # Editable reputation list
├── .env # Your config (gitignored)
├── requirements.txt
└── README.md
```
## 界面截图
### 1.1. 服务器启动
### 1.2. FastAPI Swagger文档
### 2. /scan 端点
### 3. /health 端点
### 4. /history?url=.... 端点
### 5. /stats 端点
### 6. /metrics 端点
### 1.2. FastAPI Swagger文档
### 2. /scan 端点
### 3. /health 端点
### 4. /history?url=.... 端点
### 5. /stats 端点
### 6. /metrics 端点
标签:AI摘要, AMSI绕过, API服务, AV绕过, DLL 劫持, DNS解析, FastAPI, OpenRouter, Python, SQLite, URL分析, URL安全, 人工智能, 大语言模型, 威胁情报, 威胁检测, 威胁评分, 开发者工具, 开源项目, 恶意链接, 数据本地化, 无后门, 本地部署, 用户模式Hook绕过, 网络安全, 自托管, 评分引擎, 运行时操纵, 逆向工具, 钓鱼检测, 隐私保护