Debasish-Nayak-656/PhishShield

GitHub: Debasish-Nayak-656/PhishShield

基于规则引擎的实时钓鱼 URL 与邮件检测平台,提供可解释的风险评分与安全意识报告。

Stars: 0 | Forks: 0

``` ██████╗ ██╗ ██╗██╗███████╗██╗ ██╗ ██████╗ ██╗ ██╗ █████╗ ██████╗ ██████╗ ██╔══██╗██║ ██║██║██╔════╝██║ ██║██╔════╝ ██║ ██║██╔══██╗██╔══██╗██╔══██╗ ██████╔╝███████║██║███████╗███████║██║ ███╗██║ ██║███████║██████╔╝██║ ██║ ██╔═══╝ ██╔══██║██║╚════██║██╔══██║██║ ██║██║ ██║██╔══██║██╔══██╗██║ ██║ ██║ ██║ ██║██║███████║██║ ██║╚██████╔╝╚██████╔╝██║ ██║██║ ██║██████╔╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ``` ### ⚔ 实时钓鱼检测与防范系统 [![Python](https://img.shields.io/badge/Python-3.10+-3776ab?style=flat-square&logo=python&logoColor=white)](https://python.org) [![Flask](https://img.shields.io/badge/Flask-3.0-000000?style=flat-square&logo=flask)](https://flask.palletsprojects.com) [![JavaScript](https://img.shields.io/badge/JavaScript-ES2022-f7df1e?style=flat-square&logo=javascript&logoColor=black)](https://developer.mozilla.org/docs/Web/JavaScript) [![SQLite](https://img.shields.io/badge/SQLite-Database-003b57?style=flat-square&logo=sqlite)](https://sqlite.org) [![License](https://img.shields.io/badge/License-MIT-00cc88?style=flat-square)](LICENSE) [![Status](https://img.shields.io/badge/Status-Active-00cc88?style=flat-square)]() **无 AI。无黑盒。100% 可解释的基于规则的检测。** [在线演示](#-live-demo) · [功能](#-features) · [架构](#-architecture) · [安装说明](#-installation) · [API 文档](#-api-reference) · [举报犯罪](https://cybercrime.gov.in)
## 📸 预览 | URL 扫描器 | 邮件检测器 | 仪表板 | |:-----------:|:--------------:|:---------:| | 🔗 分析任何可疑 URL | 📧 粘贴邮件内容 | 📊 实时威胁统计 | | 12 条检测规则 | 8 项行为检查 | 近期扫描历史 | | 风险评分 + 解释 | 发件人验证 | 攻击类型趋势 | ## ✨ 功能 ### 🌐 URL 扫描器 核心引擎 —— 对每个提交的 URL 运行 **12 条顺序检测规则**: | 规则 | 检查项 | 风险权重 | |------|-------|-------------| | `R01` | URL 长度 > 75 个字符 | +15 分 | | `R02` | 使用 IP 地址代替域名 | +30 分 | | `R03` | URL 中包含 `@` 符号(重定向欺骗) | +25 分 | | `R04` | 超过 4 个子域名 | +15 分 | | `R05` | 域名中包含连字符 | +10 分 | | `R06` | 伪造的安全关键词(`https-`, `secure-`) | +20 分 | | `R07` | 路径中包含可疑关键词 | 最高 +30 分 | | `R08` | 路径中包含双斜杠 `//` | +10 分 | | `R09` | 非标准端口号 | +15 分 | | `R10` | 针对 15 个已知品牌的 Typosquatting | +25 分 | | `R11` | 使用 HTTP 而不是 HTTPS | +10 分 | | `R12` | 域名年龄 < 180 天 (WHOIS) | +15–30 分 | **风险等级:** ``` 0 – 29 → ✅ Safe (Green) 30 – 59 → ⚠️ Suspicious (Yellow) 60 – 100 → 🚨 Phishing (Red) ``` ### 📧 邮件钓鱼检测器 分析粘贴的邮件内容以检测: - **紧迫性策略** —— 20 多个触发短语("urgent"、"suspended"、"verify now") - **敏感数据请求** —— 检测对密码、OTP、Aadhaar、PAN、CVV 的索求 - **通用问候语** —— 使用 "Dear Customer" 而不是您的名字 - **可疑的嵌入 URL** —— href 中包含钓鱼关键词的链接 - **伪造发件人域名** —— 冒充企业的免费邮件提供商 - **滥用大写字母和感叹号** —— 施压策略 - **HTML 链接伪装** —— 显示文本 ≠ 实际 href ### 📊 仪表板 来自 SQLite 数据库的实时统计数据: - 已执行的扫描总数 - 钓鱼 / 可疑 / 安全的分类占比 - URL 与邮件扫描次数对比 - 包含风险标记的 5 条最新扫描历史 ### 🚨 印度本地举报指南 内置直达以下资源的链接: - [国家网络犯罪举报门户](https://cybercrime.gov.in) — MHA - **网络犯罪热线:1930** — 即时援助 - [CERT-In](https://www.cert-in.org.in) — 用于请求取下网站 - [I4C](https://www.i4c.mha.gov.in) — 协调中心 ## 🏗 架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ PHISHGUARD SYSTEM │ └─────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────┐ HTTP/REST ┌────────────────────────┐ │ FRONTEND │ ◄──────────────► │ BACKEND (Flask) │ │ │ │ │ │ index.html │ │ app.py │ │ style.css │ │ ├─ /api/scan/url │ │ script.js │ │ ├─ /api/scan/email │ │ │ │ ├─ /api/stats │ │ • Syne font │ │ └─ /api/health │ │ • Space Mono │ │ │ │ • Dark theme │ │ detector.py │ └─────────────────┘ │ ├─ 12 URL rules │ │ └─ WHOIS lookup │ │ │ │ email_detector.py │ │ ├─ Keyword engine │ │ └─ Pattern matching │ │ │ │ database.py │ │ └─ SQLAlchemy + SQLite │ └────────────────────────┘ ``` ## 📁 项目结构 ``` phishguard/ │ ├── 📂 backend/ │ ├── app.py # Flask application entry point │ ├── detector.py # URL phishing detection engine (12 rules) │ ├── email_detector.py # Email content analysis engine │ ├── database.py # SQLAlchemy models │ └── requirements.txt # Python dependencies │ ├── 📂 frontend/ │ ├── index.html # Main HTML (single-page app) │ ├── 📂 css/ │ │ └── style.css # Full dark-theme stylesheet │ └── 📂 js/ │ └── script.js # All frontend logic │ └── README.md # This file ``` ## 🚀 安装说明 ### 前置条件 | 工具 | 版本 | 下载 | |------|---------|----------| | Python | 3.10+ | [python.org](https://python.org) | | pip | 最新版 | 随 Python 一起提供 | | Git | 任意版本 | [git-scm.com](https://git-scm.com) | ### 步骤 1 — 克隆仓库 ``` git clone https://github.com/yourusername/phishguard.git cd phishguard ``` ### 步骤 2 — 配置后端 ``` # 导航到 backend cd backend # (推荐)创建一个虚拟环境 python -m venv venv # 激活它 # 在 Windows 上: venv\Scripts\activate # 在 macOS/Linux 上: source venv/bin/activate # 安装依赖 pip install -r requirements.txt ``` ### 步骤 3 — 启动 Flask 服务器 ``` python app.py ``` 您应该会看到: ``` * Running on http://127.0.0.1:5000 * PhishGuard API is live! ``` ### 步骤 4 — 启动前端 打开一个**新终端**并运行前端服务: ``` cd frontend # 选项 A:Python HTTP server(无需安装) python -m http.server 8080 # 选项 B:Node.js serve npx serve . # 选项 C:VS Code Live Server 扩展 # 只需右键单击 index.html → "Open with Live Server" ``` 然后打开:**[http://localhost:8080](http://localhost:8080)** ## 🔌 API 参考 基础 URL:`http://localhost:5000/api` ### `POST /scan/url` 分析 URL 的钓鱼指标。 **请求:** ``` { "url": "http://paypal-secure-login.xyz/verify?id=123" } ``` **响应:** ``` { "url": "http://paypal-secure-login.xyz/verify?id=123", "domain": "paypal-secure-login.xyz", "risk_score": 87, "risk_level": "HIGH", "verdict": "🚨 Likely Phishing", "color": "danger", "reasons": [ "Domain looks like it's impersonating 'paypal.com' (typosquatting)", "Domain contains security keyword 'secure-' — a common trick to appear trustworthy", "Domain is only 3 days old — very new domains are high-risk", "Suspicious keywords found: login, verify" ], "recommendations": [ "Do NOT click this link or enter any information", "Report it to cybercrime.gov.in or 1930 helpline", "If you already clicked, change your passwords immediately", "Check your bank accounts for unauthorized transactions" ], "checks_performed": 12, "analyzed_at": "2024-01-15T10:30:00.000Z" } ``` ### `POST /scan/email` 分析邮件内容中的钓鱼模式。 **请求:** ``` { "email": "From: support@paypa1.com\nSubject: URGENT: Your account is suspended!\n\nDear Customer, click here to verify..." } ``` **响应:** ``` { "risk_score": 72, "risk_level": "HIGH", "verdict": "🚨 Phishing Email Detected", "color": "danger", "reasons": [ "Urgency tactics detected: 'urgent', 'suspended', 'verify' — creates panic to bypass critical thinking", "Generic greeting used — real companies address you by name", "Suspicious sender domain — does not match a legitimate organization" ], "recommendations": [ "Do NOT click any links or download attachments", "Report to cybercrime.gov.in if you shared sensitive data" ], "links_found": 2, "analyzed_at": "2024-01-15T10:30:00.000Z" } ``` ### `GET /stats` 获取仪表板统计数据。 **响应:** ``` { "total_scans": 47, "phishing_detected": 23, "suspicious": 8, "safe": 16, "url_scans": 35, "email_scans": 12, "recent_scans": [ { "type": "url", "input": "http://amazon-prize-winner.tk...", "risk_level": "HIGH", "risk_score": 91, "timestamp": "2024-01-15 10:30" } ] } ``` ### `GET /health` 检查 API 是否正在运行。 **响应:** ``` { "status": "PhishGuard API is running", "version": "1.0.0" } ``` ## 🧪 测试用例 在扫描器中尝试这些 URL 以查看实际效果: ``` # 应该得分为 HIGH(phishing) http://paypal-secure-login.xyz/verify?user=test@gmail.com https://192.168.1.1/bank/login http://amazon-account-update.tk/signin@user # 应该得分为 MEDIUM(suspicious) https://login-microsoft.com/auth http://secure-banking-portal.net # 应该得分为 LOW(safe) https://google.com https://github.com/microsoft/vscode ``` ## 🎓 评分原理 PhishGuard 采用**加权累加评分模型** —— 无需机器学习,无需训练数据: ``` def calculate_score(url): score = 0 if len(url) > 75: score += 15 # Long URL if ip_in_domain(url): score += 30 # IP address if "@" in url: score += 25 # @ trick if subdomain_count > 4: score += 15 # Too many subdomains if "-" in domain: score += 10 # Hyphens if fake_https_kw(domain): score += 20 # fake-secure- etc if suspicious_words(url): score += 8×n # Keywords if "//" in path: score += 10 # Double slash if odd_port(url): score += 15 # Port number if typosquatting(domain): score += 25 # Brand abuse if not https: score += 10 # No encryption if new_domain(whois): score += 15–30 # Domain age return min(score, 100) ``` 每条规则都**可独立解释** —— 没有黑盒,便于在答辩中进行辩护。 ## 🔧 配置 您可以在 `detector.py` 中调整权重: ``` # detector.py — 调整这些值 URL_LENGTH_THRESHOLD = 75 # Characters URL_LENGTH_SCORE = 15 # Points IP_ADDRESS_SCORE = 30 # High weight — strong indicator AT_SYMBOL_SCORE = 25 SUBDOMAIN_SCORE = 15 TYPOSQUATTING_SCORE = 25 DOMAIN_AGE_NEW = 30 # < 30 days DOMAIN_AGE_RECENT = 15 # < 180 days ``` ## 🌱 未来增强计划 | 功能 | 状态 | 备注 | |---------|--------|-------| | 🔌 Google Safe Browsing API | 🔜 计划中 | 需要 API 密钥 | | 📱 移动端 PWA | 🔜 计划中 | 离线支持 | | 🧩 浏览器扩展 | 🔜 计划中 | Chrome/Firefox | | 📊 MongoDB 后端 | 🔜 计划中 | 替换 SQLite | | 🖼️ URL 屏幕截图预览 | 🔜 计划中 | Puppeteer | | 📨 邮件头解析 | 🔜 计划中 | 完整 RFC 5322 | | 🗃️ PhishTank 集成 | 🔜 计划中 | 免费 API | ## 🛡️ 免责声明 PhishGuard 是一个**教育性网络安全项目**,专为学术演示目的而构建。它采用基于规则的启发式方法,可能会产生误报/漏报。请勿将其作为您唯一的安全工具。请始终使用多层安全防护。 ## 📜 许可证 本项目基于 **MIT License** 授权 —— 详情请参阅 [LICENSE](LICENSE)。 ## 🤝 贡献 1. Fork 本仓库 2. 创建您的功能分支:`git checkout -b feature/AmazingFeature` 3. 提交您的更改:`git commit -m 'Add AmazingFeature'` 4. 推送到分支:`git push origin feature/AmazingFeature` 5. 发起一个 Pull Request
**⚔ PhishGuard** — 别轻易上钩。 为印度的网络安全意识防范而 💙 制作 [![举报网络犯罪](https://img.shields.io/badge/Report_Cybercrime-cybercrime.gov.in-red?style=flat-square)](https://cybercrime.gov.in) [![热线电话](https://img.shields.io/badge/Helpline-1930-orange?style=flat-square)]() [![CERT-In](https://img.shields.io/badge/CERT--In-cert--in.org.in-blue?style=flat-square)](https://cert-in.org.in)
标签:Flask, Python, 威胁情报, 安全, 开发者工具, 数据可视化, 无后门, 超时处理, 逆向工具, 钓鱼检测