x-glacier/kali-pentest / kali-pentest-zh
kali-pentest-zh
Flagged通过 SSH 或 Docker 使用 Kali Linux CLI 工具执行授权渗透测试。 覆盖:信息收集、漏洞分析、嗅探与欺骗、Web/API 渗透、漏洞利用、密码攻击、无线、云原生安全、RFID/NFC、VoIP/ICS、逆向工程、取证分析、后渗透/C2、报告生成。
references/exploitation/tools/msfconsole.md
View on GitHub# msfconsole
- **Category**: Exploitation / Framework Console
- **Risk Level**: 🔴 Critical
---
## 描述
msfconsole 是 Metasploit Framework 的主要命令行接口,也是世界上使用最广泛的开源渗透测试框架。它提供交互式控制台,用于运行漏洞利用模块、管理会话、进行漏洞研究和自动化后渗透工作流。支持模块浏览、目标扫描、数据库支持的主机/服务跟踪,以及通过资源脚本实现自动化。
## 安装
```bash
# Kali Linux 预装
sudo apt install metasploit-framework
```
## 参数说明
| 参数 | 说明 |
|------|------|
| `-E <env>` / `--environment` | 设置 Rails 环境(默认为 RAIL_ENV 或 'production') |
| `-M <dir>` / `--migration-path` | 指定包含额外数据库迁移的目录 |
| `-n` / `--no-database` | 禁用数据库支持 |
| `-y <path>` / `--yaml` | 指定包含数据库设置的 YAML 文件 |
| `-c <file>` | 加载指定配置文件 |
| `-v` / `-V` / `--version` | 显示版本 |
| `--[no-]defer-module-loads` | 延迟模块加载,除非明确请求 |
| `-m <dir>` / `--module-path` | 加载额外模块路径 |
| `-a` / `--ask` | 退出前询问确认,或接受 'exit -y' |
| `-H <file>` / `--history-file` | 将命令历史保存到指定文件 |
| `-l <logger>` / `--logger` | 指定日志记录器(TimestampColorlessFlatfile、Flatfile、Stderr、Stdout、StdoutWithoutTimestamps) |
| `--[no-]readline` | 启用/禁用 readline 支持 |
| `-L` / `--real-readline` | 使用系统 Readline 库替代 RbReadline |
| `-o <file>` / `--output` | 输出到指定文件 |
| `-p <plugin>` / `--plugin` | 启动时加载插件 |
| `-q` / `--quiet` | 启动时不打印 banner |
| `-r <file>` / `--resource` | 执行指定资源脚本文件(- 表示 stdin) |
| `-x <cmd>` / `--execute-command` | 执行指定控制台命令(多条用 ; 分隔) |
| `-h` / `--help` | 显示帮助信息 |
## 常用命令
### 场景 1:快速启动并执行命令
```bash
# 静默模式(无 banner)
msfconsole -q
# 直接执行命令
msfconsole -x "use exploit/multi/handler; set PAYLOAD windows/meterpreter/reverse_tcp; set LHOST 0.0.0.0; set LPORT 4444; run"
```
### 场景 2:资源脚本自动化
```bash
# 运行资源脚本
msfconsole -r autorun.rc
# 用分号分隔多条命令
msfconsole -x "db_status; workspace -a pentest; db_nmap -sV 192.168.1.0/24"
```
### 场景 3:数据库选项
```bash
# 不使用数据库启动
msfconsole -n
# 使用自定义数据库配置
msfconsole -y /path/to/database.yml
```
### 场景 4:自定义模块加载
```bash
# 加载额外模块路径
msfconsole -m /home/user/custom_modules
# 延迟模块加载以加快启动
msfconsole --defer-module-loads
```
### 常用交互命令
| Command | Description |
|---------|-------------|
| `search <term>` | 搜索模块 |
| `use <module>` | 选择模块 |
| `show options` | 显示模块选项 |
| `set <option> <value>` | 设置模块选项 |
| `run` / `exploit` | 执行选定模块 |
| `sessions` | 列出活动会话 |
| `sessions -i <id>` | 与会话交互 |
| `db_nmap` | 运行 nmap 并将结果存入数据库 |
| `workspace` | 管理工作区 |
| `vulns` | 列出发现的漏洞 |
| `hosts` | 列出发现的主机 |
| `services` | 列出发现的服务 |
## 注意事项
1. msfconsole 主要是交互式工具;CLI 参数控制启动行为。
2. 资源脚本(`.rc` 文件)可实现复杂工作流的自动化。
3. 数据库支持(PostgreSQL)可持久存储扫描结果和会话。
4. 脚本化/自动化使用时加 `-q` 抑制 ASCII banner。
---
## 官方参考
- [Metasploit Framework (GitHub)](https://github.com/rapid7/metasploit-framework)
- [Metasploit Documentation](https://docs.metasploit.com/)
- [Running Modules (Using Metasploit)](https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html)
- [Database Support](https://docs.metasploit.com/docs/using-metasploit/intermediate/metasploit-database-support.html)
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 |