x-glacier/kali-pentest / kali-pentest-zh
kali-pentest-zh
Flagged通过 SSH 或 Docker 使用 Kali Linux CLI 工具执行授权渗透测试。 覆盖:信息收集、漏洞分析、嗅探与欺骗、Web/API 渗透、漏洞利用、密码攻击、无线、云原生安全、RFID/NFC、VoIP/ICS、逆向工程、取证分析、后渗透/C2、报告生成。
references/forensics/tools/yara.md
View on GitHub# YARA
- **Category**: Forensics / Malware Analysis
- **Risk Level**: 🟢 Low
---
## 描述
YARA 是一款面向恶意软件研究人员的模式匹配工具。它通过匹配 YARA 规则中定义的二进制模式、字符串和条件来识别和分类恶意软件样本。规则可匹配十六进制序列、文本字符串、正则表达式和复杂布尔条件。广泛应用于事件响应、威胁狩猎和取证分流。
## 安装
```bash
sudo apt install yara
```
## 参数说明
| 参数 | 说明 |
|------|------|
| `-r` | 递归扫描目录 |
| `-s` | 打印匹配的字符串 |
| `-n` | 仅打印未满足的规则(取反) |
| `-c` | 仅打印匹配数量 |
| `-t <tag>` | 仅运行指定标签的规则 |
| `-i <identifier>` | 仅打印名为 IDENTIFIER 的规则 |
| `-p <threads>` | 线程数 |
| `-w` | 禁用警告 |
| `-m` | 打印元数据 |
| `-e` | 打印命名空间 |
| `-d <var>=<value>` | 定义外部变量 |
| `-x <module>=<file>` | 将文件内容作为额外数据传递给模块 |
| `-C` | 加载预编译规则 |
| `-f`, `--fast-scan` | 快速匹配模式(快速跳过不匹配的文件) |
## 常用命令
### 场景 1:使用规则扫描文件
```bash
# 使用单个规则文件扫描
yara rules.yar suspicious_file.exe
# 使用多个规则文件扫描
yara rule1.yar rule2.yar target_directory/
# 递归目录扫描
yara -r rules.yar /tmp/malware_samples/
```
### 场景 2:显示匹配详情
```bash
# 打印匹配的字符串及偏移量
yara -s rules.yar sample.bin
# 打印匹配规则的元数据
yara -m rules.yar sample.bin
# 仅计数匹配
yara -c rules.yar sample.bin
```
### 场景 3:编写自定义规则
```bash
# 创建简单的 YARA 规则
cat > /tmp/detect_webshell.yar << 'RULE'
rule PHP_Webshell {
meta:
description = "Detects common PHP webshell patterns"
severity = "high"
strings:
$s1 = "eval(base64_decode" ascii
$s2 = "system($_" ascii
$s3 = "passthru(" ascii
$s4 = "shell_exec(" ascii
condition:
any of them
}
RULE
# 使用自定义规则扫描 Web 根目录
yara -r /tmp/detect_webshell.yar /var/www/
```
### 场景 4:使用社区规则进行威胁狩猎
```bash
# 下载 YARA 规则集
git clone https://github.com/Yara-Rules/rules.git /opt/yara-rules
# 使用社区规则扫描磁盘镜像挂载点
yara -r /opt/yara-rules/malware/*.yar /mnt/evidence/
# 按标签过滤
yara -r -t ransomware /opt/yara-rules/malware/*.yar /mnt/evidence/
```
### 场景 5:使用编译规则以提升性能
```bash
# 编译规则以加快重复使用速度(由 yarac 完成)
yarac rules_dir/*.yar /tmp/compiled_rules
# 使用编译后的规则扫描
yara -C /tmp/compiled_rules /tmp/samples/
```
## 注意事项
1. YARA 规则是恶意软件识别的行业标准,被大多数 SIEM 和 EDR 平台支持
2. 使用 `-p` 可跨 CPU 核心并行扫描大型证据集
3. 社区规则集(YARA-Rules、Florian Roth 的 signature-base)提供数千个预构建检测规则
4. 可结合 `find` 进行定向扫描:`find /mnt -name '*.exe' -exec yara rules.yar {} \;`
5. YARA 模块(PE、ELF、math、hash)支持高级条件,如导入表匹配和熵值检查
---
## 官方参考
- [YARA Documentation](https://yara.readthedocs.io/)
- [YARA (GitHub)](https://github.com/VirusTotal/yara)
- [yara — Kali Tools](https://www.kali.org/tools/yara/)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |