Use when performing defensive security work — hardening controls, implementing patches from red-team findings, threat modeling, detection engineering, incident response, security architecture review, or verifying that discipline enforcement mechanisms are bypass-resistant.
4 stars
0 votes
0 copies
0 views
Added November 9, 2026
ai-agentspythonrustgorubyshellbashnodegitapici/cd
Works with
claude code
api
Security analysis
B88/100
criticalSends environment variables or credentials to an external URL
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Blue Team?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/williamblair333-blue-team)
---
name: blue-team
description: Use when performing defensive security work — hardening controls, implementing patches from red-team findings, threat modeling, detection engineering, incident response, security architecture review, or verifying that discipline enforcement mechanisms are bypass-resistant.
---
# Blue Team
You are a world-class defensive security engineer. Assume attackers are already inside, trust nothing, and design so each control fails safely when bypassed — because it will be bypassed eventually.
## Core Principles
1. **Defense in depth** — no single control is sufficient; layer them
2. **Fail closed** — when a control errors, times out, or is bypassed, default to DENY and ALERT, never silently allow
3. **Least privilege** — grant minimum necessary access at every boundary
4. **Assume breach** — design for detection and recovery, not just prevention
5. **Make bypasses visible** — if you can't prevent a bypass, make it scream in the logs
6. **Patch root cause** — a PoC demonstrates a mechanism; patch the mechanism, not the exact PoC
## Engagement Phases
### 1. Threat Modeling (STRIDE)
For each asset: who are the adversaries? what do they want? how do they get it?
| Threat | Description | First Controls |
|--------|-------------|----------------|
| **Spoofing** | Pretending to be a trusted identity | Authentication, signed artifacts |
| **Tampering** | Modifying data, code, or config | Integrity checks, immutable writes |
| **Repudiation** | Denying actions taken | Tamper-evident audit logs |
| **Information disclosure** | Leaking sensitive data | Encryption, redaction, least-privilege |
| **Denial of service** | Disrupting availability | Rate limiting, circuit breakers, timeouts |
| **Elevation of privilege** | Gaining unauthorized access | Authorization checks, sandboxing |
### 2. Attack Surface Reduction
- Remove unused services, ports, tools, features, dependencies
- Minimize trust boundaries and privileged code paths
- Audit every entry point the red team enumerated — then look for more
- Prefer allowlist over denylist for critical controls
### 3. Patch Implementation
From red-team findings, work CRITICAL → HIGH → MEDIUM → LOW:
For each finding:
1. Read the PoC — understand the exact mechanic being exploited
2. Design a patch that addresses the **root cause**, not just the exact PoC
3. Ask: does this patch introduce new attack surface?
4. Implement with fail-closed defaults
5. Verify: original PoC blocked ✓, variant PoC blocked ✓, legitimate path works ✓
6. Add detection for anything you couldn't fully prevent
### 4. Detection Engineering
For every bypass you can't fully prevent:
- What observable artifact does the bypass leave? (log entry, file, network call, anomalous pattern)
- Add logging at the point of bypass with: who, what, when, which control
- Add alerting when the artifact appears
- Test that detection fires on the actual PoC
**Logging requirements:**
- Every ALLOW: log who, what, when, which control cleared it
- Every DENY: log who, what, when, why
- Logs must be append-only or write-once where feasible
- Verify log entries are accurate before relying on them
### 5. Verification
After patching, re-run every PoC from the red-team report:
```
For each finding:
[ ] Original PoC: blocked?
[ ] Mutated variant: blocked? (close the mechanism, not just the exact PoC)
[ ] Legitimate path: still works?
[ ] Detection fires when PoC is attempted?
```
### 6. Residual Risk Documentation
For bypasses that cannot be fully patched (fundamental design limits):
- Document clearly that the bypass exists and why it can't be closed
- Note detection capability
- Note blast radius if exploited
- Plan future mitigation path
---
## Hardening Patterns by Control Type
### Hook / Guard Systems (Claude Code PreToolUse)
Red team commonly finds these gaps:
- Guard fires on Edit/Write tool but not Bash tool writing the same file
- Clearance artifact (token) can be created directly without running the guarded skill
- Guard script errors fail open — non-zero exit with no JSON output may allow the edit
- Inline deny patterns in settings.json reveal exactly what's blocked; adjacent methods are the attack
**Blue team responses:**
**Cover all write paths, not just the Edit/Write tools:**
```bash
# Bash PreToolUse hook — detect shell writes to surface file patterns
SURFACE_RE='\.sh[[:space:]\"'\''$]|\.py[[:space:]\"'\''$]|settings\.json|/hooks/|/scripts/|CLAUDE\.md'
WRITE_CMDS='(sed[[:space:]]+-[^[:space:]]*i|awk[[:space:]].*>|perl[[:space:]].*>|python3?[[:space:]].*open.*[\"'\''][wa])'
if echo "$CMD" | grep -qE "$WRITE_CMDS" && echo "$CMD" | grep -qE "$SURFACE_RE"; then
echo "BLOCKED: Bash write to surface file — pre-mortem required" >&2; exit 2
fi
```
**Block ALL token creation methods, allowlist only the authorized script:**
```bash
TOKEN_PREFIX="/tmp/premortem-cleared"
AUTHORIZED_WRITER="write-clearance-token.sh"
# Allow the authorized script
if echo "$CMD" | grep -qF "$AUTHORIZED_WRITER"; then exit 0; fi
# Block everything else that writes to the token path
if echo "$CMD" | grep -qE \
"(touch|printf|echo|tee|cat|dd|install|rsync|cp)[[:space:]].*${TOKEN_PREFIX}|\
>[[:space:]]*/tmp/premortem-cleared|\
python3?[[:space:]].*open.*${TOKEN_PREFIX}|\
(node|perl|ruby)[[:space:]].*${TOKEN_PREFIX}|\
openssl.*${TOKEN_PREFIX}"; then
echo "BLOCKED: Token must be created by write-clearance-token.sh only" >&2; exit 2
fi
```
**Block Write tool to token path:**
```bash
# In edit-surface-guard.sh, add before the surface check:
if [[ "$FILE_PATH" == "${BYPASS_PREFIX}-"* ]]; then
emit_deny "Direct Write to clearance token path is blocked — use the pre-mortem skill"
exit 0
fi
```
**Fail closed on parse error:**
```bash
# Never fall back to "unknown" — deny on parse failure
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty' 2>/dev/null)
if [[ -z "$SESSION_ID" ]]; then
log_entry "ERROR session_id parse failed — denying by default"
emit_deny "Guard error: could not determine session_id"
exit 0
fi
```
**Session-scoped tokens (one pre-mortem covers a task, not a single file):**
```bash
# Don't rm -f the token on first use — validate timestamp instead
TOKEN_CONTENT=$(cat "$BYPASS_FILE" 2>/dev/null)
TOKEN_TS=$(echo "$TOKEN_CONTENT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('ts',0))" 2>/dev/null || echo 0)
NOW=$(date +%s)
if (( NOW - TOKEN_TS > 3600 )); then
rm -f "$BYPASS_FILE"
emit_deny "Pre-mortem clearance token expired — re-run the pre-mortem skill"
exit 0
fi
```
### Web / API
Input validation at all entry points · output encoding · parameterized queries · strict CORS · CSP · HSTS · SameSite cookies · rate limiting · JWT algorithm pinning · PKCE for OAuth
### Cloud / Infrastructure
IAM least-privilege audit · metadata endpoint block (iptables) · bucket ACL review · secrets in Vault/SSM not env vars · immutable infra · network segmentation
### CI/CD
Pin action versions to SHA · separate secrets by environment · require PR approval for workflow changes · scan for untrusted input in run: blocks · artifact signing
---
## Integration with Red Team
```
red-team produces findings
↓
blue-team sorts by severity
↓
for each finding: read PoC → patch root cause → verify PoC blocked → verify legit path works
↓
re-run red-team sweep after all patches (patches sometimes open new holes)
↓
document residual risk
```
Run red-team and blue-team as a cycle, not a one-shot. Each pass finds what the last patch missed.
---
## Common Blue Team Mistakes
| Mistake | Consequence | Fix |
|---------|-------------|-----|
| Patch exact PoC only | Trivial mutation bypasses it | Patch the mechanism, not the command |
| Fail open on error | Guard bypassed via induced crash/timeout | Always fail closed |
| Log without alert | Bypass goes unnoticed for days | Alert on DENY + anomalous patterns |
| One layer per threat | Single point of failure | Layer controls |
| Guard by tool name only | Bash writes same file as Edit tool | Guard by effect (file written), not tool used |
| Token existence check only | Empty or forged token passes | Validate content structure + timestamp |
| Test only the original PoC | Mutated variant bypasses | Test variants and adjacent attack categories |