Happy120312/YARA-Malware-Scanner

GitHub: Happy120312/YARA-Malware-Scanner

一个基于 Python 和 YARA 规则的恶意软件检测扫描器,通过自定义特征码匹配来识别文件中的恶意模式,主要用于网络安全教学演示。

Stars: 0 | Forks: 0

# 🛡️ YARA 恶意软件检测扫描器 一个基于 Python 的 **YARA 规则扫描器**,利用自定义的 YARA 特征码检测文件中的恶意模式。本项目作为网络安全大学课程设计而开发,旨在演示安全工具如何通过模式匹配来识别威胁。 ## 📸 截图 ### 🖥️ 扫描器输出 ![扫描器输出](https://raw.githubusercontent.com/Happy120312/YARA-Malware-Scanner/master/output.png) ### 🏗️ 架构 ![架构图](https://raw.githubusercontent.com/Happy120312/YARA-Malware-Scanner/master/architecture.png) ## ✨ 功能 - 🔍 **基于模式的检测** — 使用 YARA 规则扫描文件中的恶意特征码 - 📁 **目录扫描** — 递归扫描整个目录 - 📄 **单文件扫描** — 按需扫描单个文件 - 🎨 **颜色区分输出** — 绿色(安全),红色(恶意软件),洋红色(规则详情) - 📋 **详细报告** — 显示匹配的规则名称、描述和严重程度 - ⚙️ **自定义规则** — 轻松添加您自己的 YARA 检测规则 - 🧪 **包含测试文件** — 附带用于测试的安全样本文件和恶意样本文件 ## 🛠️ 技术栈 | 技术 | 用途 | |------------|---------| | Python 3 | 核心语言 | | yara-python | YARA 规则编译与匹配 | | colorama | 彩色终端输出 | | argparse | CLI 参数解析 | ## 🚀 快速开始 ### 前置条件 - 已安装 Python 3.8+ - pip 包管理器 ### 安装说明 ``` # Clone 仓库 git clone https://github.com/Happy120312/YARA-Malware-Scanner.git cd YARA-Malware-Scanner # 安装依赖 pip install -r requirements.txt ``` ### 使用方法 ``` # 扫描当前目录 (默认) python scanner.py # 扫描特定目录 python scanner.py --target /path/to/scan # 使用自定义 YARA rules python scanner.py --rules my_rules.yar --target /path/to/scan # 扫描单个文件 python scanner.py --target suspicious_document.pdf ``` ## 📂 项目结构 ``` YARA-Malware-Scanner/ ├── scanner.py # Main scanner engine ├── requirements.txt # Python dependencies ├── README.md # Documentation ├── output.png # Scanner terminal output screenshot ├── architecture.png # Project architecture diagram ├── detect.yar # YARA detection rules ├── clean_file.txt # ✅ Benign test file (no matches) ├── malicious_file.bin # 🚨 Contains mock malware payload └── suspicious_file.txt # ⚠️ Contains simulated data leak ``` ## 📜 YARA 规则 本项目包含 2 个自定义检测规则: | 规则 | 严重程度 | 检测内容 | |------|----------|---------| | `Detect_Dummy_Malware` | 🔴 高 | 模拟恶意软件 payload 特征码 | | `Detect_Confidential_Leak` | 🟡 中 | 模拟数据泄露模式 | ### 添加自定义规则 在仓库文件夹中创建一个 `.yar` 文件: ``` rule My_Custom_Rule { meta: description = "Detects custom malicious pattern" author = "Your Name" severity = "High" strings: $pattern = "MALICIOUS_STRING" condition: $pattern } ``` ## 🔄 工作原理 ``` ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ │ YARA Rules │────▶│ Python Scanner │────▶│ Target Files │ │ (detect.yar) │ │ (scanner.py) │ │ (current dir) │ └─────────────────┘ └──────────────────┘ └─────────────────┘ │ ▼ ┌──────────────────────┐ │ Scan Results │ │ ✅ CLEAN / 🚨 ALARM │ └──────────────────────┘ ``` 1. **编译** — 从 `.yar` 文件编译 YARA 规则 2. **扫描** — 每个文件都会与所有已编译的规则进行匹配 3. **报告** — 以颜色区分严重程度的方式显示结果 ## 📊 示例输出 ``` [*] Compiling YARA rules from 'detect.yar'... [+] Rules compiled successfully. === Starting Scan on directory '.' === [+] CLEAN: .\clean_file.txt [!] ALARM: .\malicious_file.bin -> Rule matched: Detect_Dummy_Malware Description: Detects a mock malware payload for testing purposes [!] ALARM: .\suspicious_file.txt -> Rule matched: Detect_Confidential_Leak Description: Detects a test string simulating a data leak === Scan Complete === Total files scanned: 3 Total files flagged: 2 ``` ## ⚠️ 免责声明 本项目**仅供教育目的**而构建,是大学网络安全课程的一部分。测试文件包含的是模拟/虚拟数据,并非真实的恶意软件。该工具旨在演示现实世界中的防病毒和安全产品中使用的基于特征码的威胁检测概念。 ## 👨‍💻 作者 **Happy Soni** — [GitHub](https://github.com/Happy120312) *"了解敌人的工具,以构建更好的防御。"* 🔐
标签:DNS 反向解析, IP 地址批量处理, Python, YARA, 云资产可视化, 无后门, 逆向工具