Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .claude/hooks/loop-detector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
# Loop Detection Hook for blhackbox
# Inspired by PentAGI's Reflector agent — detects repeated tool calls
# and injects warnings to prevent infinite loops.
#
# This hook runs on PreToolUse events. It tracks tool calls in a session
# log file and detects when the same tool+args combination is called
# repeatedly, which indicates the AI is stuck in a loop.

set -euo pipefail

# Session tracking directory
TRACK_DIR="${CLAUDE_PROJECT_DIR:-.}/.claude/loop-tracker"
mkdir -p "$TRACK_DIR"

# Session file — keyed by PID of the parent process (Claude Code session)
SESSION_FILE="$TRACK_DIR/session-$PPID.jsonl"

# Read the tool call from stdin (JSON with tool_name and tool_input)
INPUT=$(cat)

TOOL_NAME=$(echo "$INPUT" | python3 -c "
import sys, json, hashlib
try:
data = json.load(sys.stdin)
name = data.get('tool_name', '')
inp = json.dumps(data.get('tool_input', {}), sort_keys=True)
args_hash = hashlib.md5(inp.encode()).hexdigest()[:12]
print(f'{name}|{args_hash}')
except Exception:
print('unknown|000000000000')
" 2>/dev/null) || exit 0

# Parse tool name and args hash
TOOL="${TOOL_NAME%%|*}"
HASH="${TOOL_NAME##*|}"

# Skip non-MCP tools (Bash, Read, Write, Edit, etc. are normal to repeat)
case "$TOOL" in
Bash|Read|Write|Edit|Glob|Grep|Agent|WebSearch|WebFetch|TodoWrite)
exit 0
;;
esac

# Log this call
echo "${TOOL}|${HASH}|$(date +%s)" >> "$SESSION_FILE"

# Count identical calls (same tool + same args hash)
REPEAT_COUNT=$(grep -c "^${TOOL}|${HASH}|" "$SESSION_FILE" 2>/dev/null || echo "0")

# Count total MCP tool calls in this session
TOTAL_CALLS=$(wc -l < "$SESSION_FILE" 2>/dev/null || echo "0")

# Detect repeated identical calls (threshold: 3)
if [ "$REPEAT_COUNT" -ge 4 ]; then
# Output a warning message that Claude Code will see
cat << EOF
{"decision": "block", "reason": "LOOP DETECTED: You have called '${TOOL}' with identical arguments ${REPEAT_COUNT} times. This indicates you are stuck in a loop. Stop and reassess your approach:\n\n1. Why did the previous calls fail or produce insufficient results?\n2. Is there an alternative tool or different arguments you should try?\n3. Should you move on to the next phase of your engagement?\n\nDo NOT retry the same call. Try a different approach or skip this step."}
EOF
exit 0
fi

# Warn at 3 identical calls (approaching threshold)
if [ "$REPEAT_COUNT" -eq 3 ]; then
cat << EOF
{"decision": "allow", "message": "WARNING: You have called '${TOOL}' with the same arguments 3 times. If this call doesn't produce the result you need, change your approach on the next attempt. Do not repeat the same call more than once more."}
EOF
exit 0
fi

# Warn when total calls are high (approaching session limits)
if [ "$TOTAL_CALLS" -eq 50 ]; then
cat << EOF
{"decision": "allow", "message": "SESSION CHECKPOINT: You have made 50 MCP tool calls in this session. Consider whether you have enough findings to begin aggregation. If you are still in early phases, continue — but start planning your wrap-up."}
EOF
exit 0
fi

if [ "$TOTAL_CALLS" -eq 80 ]; then
cat << EOF
{"decision": "allow", "message": "SESSION WARNING: 80 MCP tool calls used. Begin wrapping up findings. Call get_payload_schema() and aggregate_results() soon to ensure your work is captured before the session ends."}
EOF
exit 0
fi

# Default: allow the call silently
exit 0
11 changes: 11 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
}
]
}
],
"PreToolUse": [
{
"matcher": "mcp__.*",
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/loop-detector.sh"
}
]
}
]
}
}
20 changes: 20 additions & 0 deletions .claude/skills/api-security/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Then gather optional details interactively:
> **Before you start:**
> 1. Ensure all MCP servers are healthy — run `make health`
> 2. Verify authorization is active — run `make inject-verification`
> 3. Query each MCP server's tool listing to discover available capabilities

---

Expand Down Expand Up @@ -110,3 +111,22 @@ Write to `output/reports/`:
- **For IDOR/BOLA, show both users' data** — prove cross-user access
- Findings without PoC must be downgraded to "info" severity
- Populate `poc_steps`, `poc_payload`, and `evidence` fields in every `VulnerabilityEntry`


## MCP Tool Quick Reference

### Kali MCP — Exploit Search
- `searchsploit <service> <version>` — Search ExploitDB for known exploits
- `msfconsole -qx "search <service>; exit"` — Search Metasploit modules
- For complex exploitation requiring custom code, use the `/exploit-dev` skill

### WireMCP — Traffic Analysis
- `capture_packets(interface="eth0", duration=30, filter="host <TARGET>")` — Capture during exploitation
- `extract_credentials(file_path="<pcap>")` — Find cleartext credentials in traffic
- `follow_stream(file_path="<pcap>", stream_number=0)` — Inspect TCP conversations
- `get_statistics(file_path="<pcap>")` — Protocol distribution overview

### Screenshot MCP — Evidence Capture
- `take_screenshot(url="http://<TARGET>/<page>")` — Full page screenshot for PoC
- `take_element_screenshot(url="<url>", selector="<css>")` — Capture specific DOM elements (XSS payloads, error messages)
- `annotate_screenshot(screenshot_path="<path>", annotations='[{"type":"text","x":10,"y":10,"text":"VULN: <desc>","color":"red","size":18}]')` — Label evidence
19 changes: 19 additions & 0 deletions .claude/skills/bug-bounty/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,22 @@ Write to `output/reports/`:
- **A report that says "SQLi found" gets N/A. "SQLi exploited, extracted user table" gets a bounty.**
- PoC must be independently reproducible by the program's security team
- Populate `poc_steps`, `poc_payload`, and `evidence` fields in every `VulnerabilityEntry`


## MCP Tool Quick Reference

### Kali MCP — Exploit Search
- `searchsploit <service> <version>` — Search ExploitDB for known exploits
- `msfconsole -qx "search <service>; exit"` — Search Metasploit modules
- For complex exploitation requiring custom code, use the `/exploit-dev` skill

### WireMCP — Traffic Analysis
- `capture_packets(interface="eth0", duration=30, filter="host <TARGET>")` — Capture during exploitation
- `extract_credentials(file_path="<pcap>")` — Find cleartext credentials in traffic
- `follow_stream(file_path="<pcap>", stream_number=0)` — Inspect TCP conversations
- `get_statistics(file_path="<pcap>")` — Protocol distribution overview

### Screenshot MCP — Evidence Capture
- `take_screenshot(url="http://<TARGET>/<page>")` — Full page screenshot for PoC
- `take_element_screenshot(url="<url>", selector="<css>")` — Capture specific DOM elements (XSS payloads, error messages)
- `annotate_screenshot(screenshot_path="<path>", annotations='[{"type":"text","x":10,"y":10,"text":"VULN: <desc>","color":"red","size":18}]')` — Label evidence
Loading
Loading