AlbertoEJ/Email-Analyzer

GitHub: AlbertoEJ/Email-Analyzer

一款集成 SPF/DKIM/DMARC 验证、URL 扫描和 AI 内容分析的全栈 Gmail 安全工具,用于检测钓鱼邮件和社会工程学威胁。

Stars: 0 | Forks: 0

# Email Security Analyzer [阅读西班牙语版](README.es.md) ![React](https://img.shields.io/badge/React-19-61DAFB?logo=react&logoColor=black) ![TypeScript](https://img.shields.io/badge/TypeScript-5.7-3178C6?logo=typescript&logoColor=white) ![Tailwind CSS](https://img.shields.io/badge/Tailwind_CSS-3.4-06B6D4?logo=tailwindcss&logoColor=white) ![Express](https://img.shields.io/badge/Express-4-000000?logo=express&logoColor=white) ![Prisma](https://img.shields.io/badge/Prisma-SQLite-2D3748?logo=prisma&logoColor=white) ![Gmail API](https://img.shields.io/badge/Gmail_API-v1-EA4335?logo=gmail&logoColor=white) 一个通过 Gmail 进行邮件安全分析的全栈应用程序。它使用多种分析引擎(headers、URL、LLM 驱动的内容、附件)来检测钓鱼、社会工程学和其他威胁。 大学毕业论文项目 ## 架构 ``` email-analyzer/ ├── backend/ # REST API (Express + Prisma + SQLite) │ ├── src/ │ │ ├── config/ # Environment variables, database │ │ ├── controllers/ # Endpoints (emails, dashboard, reports, auth) │ │ ├── middleware/ # Auth, error handling, rate limiting │ │ ├── routes/ # Route definitions │ │ ├── services/ # Business logic │ │ │ ├── analyzer.service.ts # Main orchestrator │ │ │ ├── header-analyzer.service.ts # SPF/DKIM/DMARC │ │ │ ├── url-analyzer.service.ts # Safe Browsing + VirusTotal │ │ │ ├── content-analyzer.service.ts # LLM via OpenRouter │ │ │ ├── attachment-analyzer.service.ts # Attachment analysis │ │ │ ├── threat-scorer.service.ts # Composite scoring │ │ │ ├── scan-progress.service.ts # Real-time progress │ │ │ ├── gmail.service.ts # Gmail API client │ │ │ └── scheduler.service.ts # Automated scans (cron) │ │ └── utils/ # Email parser, logger │ └── prisma/ # Schema and migrations └── frontend/ # SPA (React + Vite + Tailwind) └── src/ ├── api/ # HTTP client (Axios) ├── components/ # UI components │ ├── layout/ # Sidebar, Header (responsive) │ ├── dashboard/ # Cards, charts (Recharts) │ ├── emails/ # List, detail, filters, progress │ └── analysis/ # Analysis type views ├── hooks/ # React Query hooks ├── pages/ # Main pages └── context/ # AuthContext (Google OAuth) ``` ## 功能特性 ### 多层安全分析 - **Headers (SPF/DKIM/DMARC)** — 发件人身份验证 - **URL** — 通过 Google Safe Browsing 和 VirusTotal 进行验证 - **Content (LLM)** — 基于 AI 的钓鱼和社会工程学检测 - **Attachments** — 通过 VirusTotal 进行可疑文件类型和哈希分析 ### 综合威胁评分 每封邮件根据加权组件获得 0 到 100 的评分: | 组件 | 权重 | |------------|--------| | Headers | 20% | | URL | 30% | | Content | 30% | | Attachments| 20% | 等级:`safe` (0-15) | `low` (16-35) | `medium` (36-55) | `high` (56-75) | `critical` (76-100) ### 实时扫描进度 - 扫描在后台运行(非阻塞 UI) - 每 1 秒轮询显示:进度条、当前邮件、重试次数、发现的威胁 - 针对 429/502/503 错误的自动指数退避重试 ### 交互式仪表板 - 汇总卡片(总邮件数、威胁数、平均分、上次扫描) - 威胁趋势图(30 天) - 威胁等级分布(饼图) ### 响应式 UI - 桌面端:固定侧边栏 + 邮件表格 - 移动端:汉堡菜单 + 邮件卡片 ### 其他功能 - Google OAuth 2.0 身份验证 - 计划自动扫描(可配置 cron) - JSON 报告导出 - 邮件过滤和搜索 - 分页 ## 前置条件 - **Node.js** >= 18 - **npm** >= 9 - 启用了 Gmail API 的 Google Cloud 账号 - 已配置 OAuth 2.0 凭证 ### API Keys(可选但推荐) | 服务 | 用途 | |------|------| | [Google Safe Browsing](https://developers.google.com/safe-browsing) | 恶意 URL 验证 | | [VirusTotal](https://www.virustotal.com/gui/my-apikey) | URL 和附件哈希分析 | | [OpenRouter](https://openrouter.ai/keys) | LLM 驱动的内容分析 | ## 安装 ``` # 克隆仓库 git clone https://github.com/AlbertoEJ/Email-Analyzer.git cd Email-Analyzer # 安装依赖 (带 workspaces 的 monorepo) npm install # 配置环境变量 cp backend/.env.example backend/.env # 使用你的凭证编辑 backend/.env (见下一节) # 创建数据库并运行 migrations npm run db:migrate # 以开发模式启动 (backend + frontend 同时运行) npm run dev ``` 后端运行在 `http://localhost:3001`,前端运行在 `http://localhost:5173`。 ## 环境变量 创建 `backend/.env` 文件并填入: ``` # 服务器 PORT=3001 NODE_ENV=development FRONTEND_URL=http://localhost:5173 # Google OAuth 2.0 (必填) GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=your-client-secret GOOGLE_REDIRECT_URI=http://localhost:3001/api/auth/callback # OAuth token 加密密钥 (64 个十六进制字符) # 生成方式: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))" ENCRYPTION_KEY=your-64-char-hex-key # Google Safe Browsing API (可选) SAFE_BROWSING_API_KEY= # VirusTotal API (可选) VIRUSTOTAL_API_KEY= # OpenRouter - LLM 内容分析 (可选) OPENROUTER_API_KEY= OPENROUTER_MODEL=meta-llama/llama-3.2-3b-instruct:free # 定时扫描 cron 表达式 (默认: 每 6 小时) SCAN_CRON=0 */6 * * * ``` ## 可用脚本 | 命令 | 描述 | |------|------| | `npm run dev` | 启动后端和前端(开发模式) | | `npm run dev:backend` | 仅后端 | | `npm run dev:frontend` | 仅前端 | | `npm run build` | 生产环境构建 | | `npm run db:migrate` | 运行 Prisma 迁移 | | `npm run db:generate` | 重新生成 Prisma 客户端 | ## 技术栈 ### 后端 - **Express** — HTTP 服务器 - **Prisma** — ORM (SQLite) - **googleapis** — 官方 Gmail API 客户端 - **OpenAI SDK** — OpenRouter (LLM) 通信 - **Zod** — 环境变量验证 - **Pino** — 结构化日志 - **node-cron** — 计划扫描 - **Cheerio** — 邮件 HTML 解析 - **Helmet** — 安全 Headers - **express-rate-limit** — 滥用防护 ### 前端 - **React 19** — UI 库 - **Vite** — 打包器和开发服务器 - **Tailwind CSS** — 实用优先的样式 - **TanStack React Query** — 服务端状态管理 - **React Router** — SPA 导航 - **Recharts** — 交互式图表 - **Lucide React** — 图标 - **Axios** — HTTP 客户端 - **date-fns** — 日期格式化 ## Google Cloud 设置 1. 前往 [Google Cloud Console](https://console.cloud.google.com/) 2. 创建一个新项目 3. 启用 **Gmail API** 4. 配置 **OAuth consent screen** (类型: External) - 添加 scope: `https://www.googleapis.com/auth/gmail.readonly` 5. 创建 **OAuth 2.0 credentials** (类型: Web Application) - 授权重定向 URI: `http://localhost:3001/api/auth/callback` 6. 复制 Client ID 和 Client Secret 到你的 `.env` 文件中 ## 许可证 本项目基于 [AGPL-3.0](LICENSE) 许可证授权。
标签:Ask搜索, DLL 劫持, ESC8, Express, Gmail API, Gmail 安全, Google Safe Browsing, LLM, MITM代理, OpenRouter, Prisma, React, REST API, SPF/DKIM/DMARC 校验, SQLite, Syscalls, TypeScript, Unmanaged PE, URL 扫描, VirusTotal, 人工智能, 内容分析, 大语言模型, 威胁分析, 威胁评分, 安全插件, 毕业设计, 用户模式Hook绕过, 社会工程学, 网络安全, 自动化侦查工具, 自动化攻击, 邮件安全, 钓鱼检测, 附件分析, 隐私保护