ethicaladitya/yara-rules

GitHub: ethicaladitya/yara-rules

专门针对 WordPress 和 PHP 恶意软件检测而汇集的综合 YARA 规则集,覆盖后门、Webshell 及混淆代码等广泛威胁。

Stars: 0 | Forks: 0

# WordPress 与 PHP 恶意软件 YARA 规则 [![许可证:混合开源](https://img.shields.io/badge/License-Open%20Source-blue.svg)](#license) [![规则](https://img.shields.io/badge/Rules-38%2C000%2B-red.svg)](#rule-sets) [![WordPress](https://img.shields.io/badge/Platform-WordPress-21759B.svg)](#) ## 为什么建立此仓库 WordPress 驱动了超过 43% 的网站,这使其成为恶意软件注入的首要目标 CMS。 攻击者经常通过存在漏洞的插件、主题和文件上传端点入侵网站——植入**PHP 后门、Webshell、SEO 垃圾注入器和凭证窃取器**,这些恶意程序很难被标准杀毒软件检测到。 本仓库汇集了专门针对 **PHP 和 WordPress 恶意软件检测** 进行优化的最全面的开源 YARA 规则集,使其易于在任何扫描流水线中使用。 ## 这些规则能检测什么 | 类别 | 示例 | |---|---| | **PHP 后门** | eval/base64 链、gzinflate 载荷、ROT13 混淆、十六进制编码执行 | | **Webshells** | c99、r57、WSO、FilesMan、b374k 及 3,000 多种自定义变种 | | **远程代码执行** | 带有用户输入的 `system()`、`exec()`、`passthru()`、`shell_exec()` | | **WordPress 专属恶意软件** | 非法管理员注入、`wp_options` 后门、cron 注入、插件隐藏 | | **文件释放器** | 向 `.php` 文件写入的 `file_put_contents`、`move_uploaded_file` webshell 上传 | | **凭证窃取** | `wp-config.php` 读取器、`curl` 数据渗出、WP 密钥的 `getenv()` | | **隐藏 Iframe 与 JS 注入** | `document.write(unescape())`、内联 `eval()` 脚本标签 | | **SEO 垃圾注入器** | 隐藏链接注入、通过 `wp_redirect` 进行重定向操纵 | | **混淆代码** | 多层编码链、同形异义变量名、字符串重组器 | | **C2 信标** | 由 Cookie 键控的存活检查、硬编码的 C2 域名、base64 数据渗出 | ## 规则集 | 目录 | 文件 | 来源 | 许可证 | 覆盖范围 | |---|---|---|---|---| | `php/` | `rfxn.yara` | [RFxN](https://www.rfxn.com/) | 个人/非商业免费使用 | 约 38,000 条 PHP 恶意软件签名 | | `php/` | `php-malware-finder.yar` | [jvoisin/php-malware-finder](https://github.com/jvoisin/php-malware-finder) | MIT | 15 条语义 PHP 启发式规则 | | `php/` | `whitelist.yar` | [jvoisin/php-malware-finder](https://github.com/jvoisin/php-malware-finder) | MIT | php-malware-finder 所需的白名单 | | `webshells/` | `thor-webshells.yar` | [Neo23x0/signature-base](https://github.com/Neo23x0/signature-base) | Apache 2.0 | 3,286+ webshell 模式 | | `ai_generated/` | `*.yar` | 本仓库 | MIT | 从已确认的恶意软件检测中自动生成 | **总覆盖范围:40,000+ 恶意软件签名和启发式规则。** ## 快速开始 ### 前置条件 ``` # Ubuntu / Debian apt install yara # macOS brew install yara # Python binding (用于脚本化扫描) pip install yara-python ``` ### 扫描 WordPress 安装目录 ``` # Clone 此 repository git clone https://github.com/ethicaladitya/yara-rules.git cd yara-rules # 扫描 WordPress 目录中的所有 PHP 文件 yara php/rfxn.yara /var/www/html/wordpress/ -r --tag php # Check for known webshells yara webshells/thor-webshells.yar /var/www/html/wordpress/ -r # 运行 php-malware-finder 语义规则 yara php/php-malware-finder.yar /var/www/html/wordpress/ -r ``` ### 使用 Python 扫描 ``` import yara from pathlib import Path rules_dir = Path("yara-rules") # 加载所有 rule sets rule_sets = [ yara.compile(str(rules_dir / "php" / "rfxn.yara")), yara.compile(str(rules_dir / "php" / "php-malware-finder.yar")), yara.compile(str(rules_dir / "webshells" / "thor-webshells.yar")), ] # 扫描文件 target = "/var/www/html/wp-content/uploads/suspicious.php" for rules in rule_sets: matches = rules.match(target) for match in matches: print(f"[{match.rule}] Matched: {target}") ``` ### 扫描整个 WordPress 站点 (Bash) ``` #!/usr/bin/env bash # scan-wordpress.sh — 扫描所有 PHP/JS 文件并报告命中 RULES_DIR="./yara-rules" SITE_DIR="${1:-/var/www/html}" REPORT="scan-report-$(date +%Y%m%d-%H%M%S).txt" echo "Scanning: $SITE_DIR" echo "Report: $REPORT" find "$SITE_DIR" -type f \( -name "*.php" -o -name "*.js" -o -name "*.phtml" \) | while read -r file; do for rulefile in "$RULES_DIR"/php/*.yar "$RULES_DIR"/php/*.yara \ "$RULES_DIR"/webshells/*.yar \ "$RULES_DIR"/ai_generated/*.yar; do [[ -f "$rulefile" ]] || continue result=$(yara "$rulefile" "$file" 2>/dev/null) [[ -n "$result" ]] && echo "$result" >> "$REPORT" done done echo "" echo "Scan complete. Hits: $(wc -l < "$REPORT" 2>/dev/null || echo 0)" ``` ## 仓库结构 ``` yara-rules/ ├── README.md ├── LICENSE ├── php/ │ ├── rfxn.yara # ~38,000 PHP malware signatures (RFxN) │ ├── php-malware-finder.yar # Semantic PHP heuristics (jvoisin, MIT) │ └── whitelist.yar # Required whitelist for php-malware-finder ├── webshells/ │ └── thor-webshells.yar # 3,286+ webshell patterns (Neo23x0, Apache 2.0) └── ai_generated/ ├── README.md # Describes auto-generated rules └── *.yar # Rules generated from confirmed detections ``` ## 保持规则更新 随着新恶意软件变种的出现,社区规则集应定期更新。 ``` # 刷新所有 community rules curl -fsSL https://www.rfxn.com/downloads/rfxn.yara -o php/rfxn.yara curl -fsSL https://raw.githubusercontent.com/jvoisin/php-malware-finder/master/data/php.yar -o php/php-malware-finder.yar curl -fsSL https://raw.githubusercontent.com/jvoisin/php-malware-finder/master/data/whitelist.yar -o php/whitelist.yar curl -fsSL https://raw.githubusercontent.com/Neo23x0/signature-base/master/yara/thor-webshells.yar -o webshells/thor-webshells.yar ``` 或者使用内置的更新脚本(如果适用于您的工具链)。 ## AI 生成的规则 (`ai_generated/`) `ai_generated/` 目录包含从已确认的恶意软件样本中提取的 YARA 规则。 每条规则都使用源文件的哈希值命名以防止冲突,并包含元数据: ``` rule AI_shell_php_a1b2c3d4 : ai_generated critical { meta: description = "PHP Obfuscated Backdoor — eval/base64 + system() chain" verdict = "CONFIRMED MALICIOUS" category = "Remote Code Execution Shell" severity = "Critical" generated_at = "2026-04-14T10:00:00+00:00" ai_generated = true strings: $s0 = "eval(base64_decode" nocase ascii wide $s1 = "system($_POST" nocase ascii wide condition: any of them } ``` 当触发规则的原文件随后被评估为误报时,该目录中的规则将被撤回(删除)。 ## 集成示例 ### WP-CLI 插件 ``` # 扫描 WordPress uploads 目录 (常见的恶意软件存放位置) yara php/rfxn.yara wp-content/uploads/ -r 2>/dev/null | grep -v "^$" ``` ### cPanel / WHM 钩子 将此添加到您的病毒扫描流水线中,或作为补充规则源与 Imunify360 / ConfigServer Exploit Scanner 集成。 ### CI/CD 流水线 (GitHub Actions) ``` - name: YARA Malware Scan run: | sudo apt-get install -y yara git clone https://github.com/ethicaladitya/yara-rules.git /tmp/yara-rules find ./wp-content -name "*.php" -exec yara /tmp/yara-rules/php/rfxn.yara {} \; | tee scan-results.txt [ ! -s scan-results.txt ] || (echo "Malware detected!" && exit 1) ``` ## 常见的 WordPress 恶意软件位置 在扫描 WordPress 站点时,请优先扫描这些目录: ``` wp-content/uploads/ # No PHP should ever exist here wp-content/plugins/ # Vulnerable or injected plugins wp-content/themes/ # Theme file injection wp-content/mu-plugins/ # Must-use plugins (often used for persistence) wp-config.php # Credential theft target .htaccess # Redirect injection wp-includes/ # Core file replacement ``` ## 相关资源 - [YARA 文档](https://yara.readthedocs.io/) - [WordPress 安全手册](https://developer.wordpress.org/apis/security/) - [Sucuri SiteCheck](https://sitecheck.sucuri.net/) — 免费的远程扫描器 - [WPScan 漏洞数据库](https://wpscan.com/wordpress-security-scanner) - [VirusTotal YARA Hunting](https://www.virustotal.com/) ## 许可证 | 组件 | 许可证 | |---|---| | `php/rfxn.yara` | 个人/非商业用途 — 详见 [rfxn.com](https://www.rfxn.com/) | | `php/php-malware-finder.yar`、`php/whitelist.yar` | [MIT](https://github.com/jvoisin/php-malware-finder/blob/master/LICENSE) | | `webshells/thor-webshells.yar` | [Apache 2.0](https://github.com/Neo23x0/signature-base/blob/master/LICENSE) | | `ai_generated/*.yar` | [MIT](LICENSE) | | 脚本与文档 | [MIT](LICENSE) | ## 免责声明 这些规则仅用于**防御性安全目的**——恶意软件检测、事件响应和安全研究。 在扫描非您所有的系统之前,请务必获取适当的授权。
标签:C2通信, CISA项目, CMS安全, DNS 反向解析, DNS 解析, IP 地址批量处理, JavaScript, OpenVAS, PHP, SEO垃圾邮件, Webshell, WordPress, YARA, 云资产可视化, 凭据窃取, 后门, 安全扫描, 应用安全, 开源规则集, 恶意脚本, 文件上传漏洞, 时序注入, 混淆代码, 编程工具, 网站安全, 远程代码执行, 逆向工具