Imported from yunmengya/PHP_AUDIT_SKILLS (
SKILL.md). Install upstream withnpx skills add yunmengya/PHP_AUDIT_SKILLS. Copyright stays with the author.
PHP Code Audit โ Main Orchestrator
Trigger command: /php-audit-skills $ARGUMENTS
You are the PHP code audit main orchestrator. Receive target source code path, directly spawn leaf Agents to execute the full audit pipeline. No intermediate dispatch layers.
Resource Paths
All skill resources are located in the skill root directory (referred to as SKILL_DIR, the directory containing this SKILL.md).
shared/โ Shared knowledge base (anti-hallucination rules, sink definitions, data contracts, etc.)shared/php_specific_patterns.mdโ PHP-specific attack patterns (Phase-4 experts + Phase-2 context-extractor)shared/attack_chains.mdโ Attack chain patterns (Phase-4.5 attack-graph-builder + correlation-engine)shared/lessons_learned.mdโ Field experience library (L3 on-demand reference)shared/known_cves.mdโ PHP ecosystem CVE quick reference (Phase-2 dep_scanner + Phase-4 experts)
teams/team1~5/โ Agent instruction files for each phaseschemas/โ JSON Schema files (referenced byshared/data_contracts.md, used when agents need to validate output format)templates/โ Docker/Nginx templatestools/โ PHP helper tool scriptstools/sink_finder.phpโ AST Sink scanner. Usage:php sink_finder.php <target_dir>(Phase-2 ast-scanner)tools/trace_filter.phpโ Xdebug Trace filter. Usage:php trace_filter.php <trace_file> [sink1,sink2,...](Phase-3 trace-dispatcher/trace-worker)tools/payload_encoder.phpโ Payload encoder. Usage:php payload_encoder.php <payload> <encoding_type>(Phase-4 expert agents)tools/waf_detector.phpโ WAF/filter fingerprinting. Usage:php waf_detector.php <base_url> [cookie](Phase-4 expert agents)tools/jwt_tester.phpโ JWT security tester. Usage:php jwt_tester.php <token> [public_key_file](Phase-4 authz_auditor/crypto_auditor โ tests Algorithm None / RS256โHS256 confusion / weak key brute-force)tools/type_juggling_tester.phpโ PHP type juggling tester. Usage:php type_juggling_tester.php <target_url> [param_name] [cookie](Phase-4 authz_auditor โ tests loose comparison vulnerabilities)tools/redirect_checker.phpโ Open redirect checker. Usage:php redirect_checker.php <target_url> [redirect_param] [cookie](Phase-4 ssrf_auditor/authz_auditor โ tests 302 Location controllability)tools/validate_shared.phpโ Shared resource validator. Usage:php tools/validate_shared.php [shared_dir](dev/maintenance โ validates PHP/JSON code blocks in shared/*.md)tools/audit_monitor.shโ Real-time audit progress dashboard. Usage:bash tools/audit_monitor.sh <work_dir>(Phase-4 orchestrator โ displays agent status, timing, progress)tools/quality_report_gen.shโ Quality report generator. Usage:bash tools/quality_report_gen.sh <work_dir>(Phase-4.5/5 โ generates QC summary report)tools/vuln_intel.shโ Dependency vulnerability scanner (no API key required). Usage:bash tools/vuln_intel.sh <composer.lock> [output_dir](Phase-4 Mini-Researcher โ queries OSV.dev, cve.circl.lu for Packagist package vulnerabilities)
Skills Directory Overview
| Directory | Skill IDs | Count | Description |
|---|---|---|---|
skills/auditors/ |
S-040~S-060 (-A/-B) | 42+1 | 21 auditor types ร 2 stages (analyze + attack) + index |
skills/auth/ |
S-038a~S-038i | 9+1 | Authentication simulation sub-skills + index |
skills/correlation/ |
S-070~S-074 | 5+1 | Cross-auditor correlation rules + index |
skills/infrastructure/ |
S-002~S-007 | 4+1 | Workspace, checkpoint, recovery, timeout + index |
skills/qc/ |
S-080~S-085 | 6+1 | Per-phase quality checkers + index |
skills/report/ |
S-090a~S-090g | 7+1 | Report chapter writers + index |
skills/routes/ |
S-030a~S-030h | 8+1 | Route analysis sub-skills + index |
skills/scanners/ |
S-020~S-026 | 7+1 | Scanner tool wrappers + index |
skills/shared/ |
S-100~S-108 | 9+1 | Cross-cutting auditor protocols + index |
skills/trace/ |
S-036a~S-037h | 14+1 | Trace analysis sub-skills + index |
Total: 111 skill files + 10 index files = 121 files
Fill-in Template Standard
Every skill follows the fill-in template format:
Identity โ Input Contract โ ๐จ CRITICAL Rules โ Fill-in Procedure (tables) โ Output Contract โ โ
/โ Examples โ Error Handling
This minimizes model dependency: the model fills predefined fields rather than generating free-form content.
Input Parameters
$ARGUMENTS: Absolute path to the target PHP project source code
Execution Flow
Step 1: Environment Prerequisites Check
Docker check:
docker --version
docker compose version
docker ps >/dev/null 2>&1 # Verify daemon is running, not just installed
df -h /var/lib/docker 2>/dev/null || df -h /tmp
- Docker not installed โ prompt user to install Docker Desktop or Docker Engine
- Docker daemon not running โ prompt user to start Docker (
systemctl start dockeror open Docker Desktop) - docker compose not installed โ prompt user to install docker-compose-plugin
- Disk space < 5GB โ warn insufficient space
tmux hint (optional): If user is not running in tmux, print "ๅปบ่ฎฎๅจ tmux ไผ่ฏไธญ่ฟ่ก (Recommended: run in tmux session for split-pane view)๏ผShift+Up/Down ๅๆข teammate ่งๅพ๏ผ". tmux panes are auto-managed by the Claude Code Agent Teams framework, no manual intervention needed.
Step 2: Target Path Validation
- Verify
$ARGUMENTSpath exists - Verify path contains
.phpfiles (recursive search, excluding vendor/) - Path missing or no .php files โ abort and prompt user
Step 3: Create Working Directory & Initialize Infrastructure
๐ Full specification:
skills/infrastructure/workspace_init.md(S-002)
Execute all steps from skills/infrastructure/workspace_init.md:
- Sanitize PROJECT_NAME from $ARGUMENTS
- Create
$WORK_DIRwith 12 subdirectories (.audit_state/,exploits/,ๆฅๅ/,PoC่ๆฌ/,ไฟฎๅค่กฅไธ/, etc.) - Initialize memory and graph databases via
audit_db.sh - Initialize state machine: write "INIT" to
current_phase - Generate
gate_check.sh(validates file existence, JSON syntax, UTF-8 encoding, schema spot-checks, and JSON Schema validation againstschemas/*.schema.json)- Gate schema validation: for each gate artifact, run
python3 -c "import json,jsonschema; jsonschema.validate(json.load(open('FILE')),json.load(open('SCHEMA')))"โ FAIL if validation error - If
python3orjsonschemaunavailable, fall back to required-field spot-checks viajq
- Gate schema validation: for each gate artifact, run
- Generate
phase_transition.sh(enforces EXPECTED_CURRENT โ NEXT_PHASE transitions)
Step 4: Resume Detection & Checkpoint Management
๐ Full specification:
skills/infrastructure/checkpoint_manager.md(S-003)
Checkpoint format: see schemas/checkpoint.schema.json. Core fields: completed, current, mode, phase_timings, framework, total_sinks, confirmed_vulns, agent_states, phases.
ALL checkpoint.json writes MUST use atomic write pattern (write to .tmp then mv). See S-003 Procedure A.
Agent status enum: spawned โ running โ passed / failed / retrying / degraded / timed_out
Execute S-003 procedures:
- Resume Detection (Procedure D): Check for prior checkpoint.json โ ask user โ Resume Protocol (Procedure E)
- Incremental Audit (Procedure F): Git diff โ if <10 changed files โ offer incremental mode
Step 5: Load Shared Resources
Read shared resource files from shared/ and teams/qc/ (path prefix: ${SKILL_DIR}/), inject into each agent's prompt.
L1 MUST-inject (all agents): anti_hallucination.md, data_contracts.md, evidence_contract.md
L2 Role-based inject: sink_definitions.md, php_specific_patterns.md, payload_templates.md, waf_bypass.md, framework_patterns.md, attack_chains.md, known_cves.md, docker_snapshot.md, realtime_sharing.md, second_order.md, false_positive_patterns.md, env_selfheal.md, context_compression.md, pivot_strategy.md, attack_memory.md, attack_memory_graph.md
L3 On-demand: lessons_learned.md
QC-specific: references/quality_check_templates.md, shared/output_standard.md, teams/qc/quality_checker.md, teams/qc/qc_dispatcher.md
Injection tier rules: see
references/agent_injection_framework.md
Step 6: Team + Task Dispatch
Step 6.1: Create Audit Team
TeamCreate(team_name="php-audit-skills", description="PHP Code Audit - Target: {PROJECT_NAME}")
Step 6.2: Create Flat Tasks (Phase 1-3 Static Tasks)
Create all known tasks upfront, set blockedBy dependencies via TaskUpdate. Phase 4/5 dynamic tasks are created after Phase-2 completes.
Phase-1 (Environment):
task-1: "env_detective โ framework fingerprint" activeForm="Analyzing environment" (no deps)
task-2: "schema_reconstructor" activeForm="Rebuilding DB schema" (no deps)
task-3: "docker_builder" activeForm="Building Docker env" (blockedBy: [1, 2])
task-4: "QC: environment build" activeForm="QC verifying environment" (blockedBy: [3])
Phase-2 (Recon):
task-5: "scanners ร7 (Psalm/Progpilot/AST/PHPStan/Semgrep/Composer/CodeQL)" activeForm="Running static analysis" (blockedBy: [4])
task-6: "route_mapper" activeForm="Parsing route table" (blockedBy: [4])
task-7: "auth_auditor" activeForm="Analyzing auth mechanism" (blockedBy: [4])
task-8: "dep_scanner" activeForm="Scanning dependencies" (blockedBy: [4])
task-9: "context_extractor" activeForm="Extracting sink context" (blockedBy: [5,6,7,8])
task-10: "risk_classifier" activeForm="Severity classification" (blockedBy: [9])
task-11: "QC: static recon" activeForm="QC verifying recon" (blockedBy: [10])
Phase-3 (Tracing):
task-12: "auth_simulator" activeForm="Simulating auth" (blockedBy: [11])
task-13: "trace_dispatcher" activeForm="Dynamic tracing" (blockedBy: [12])
task-14: "QC: dynamic trace" activeForm="QC verifying traces" (blockedBy: [13])
Resume Integration: If checkpoint.json shows completed phases, follow the Resume Protocol from Step 4 โ verify artifact integrity, then resume from the next phase after the last validated one. NEVER mark tasks as completed without verifying their artifacts.
Step 6.3: Strict Sequential Dispatch โ Phase-by-Phase Blocking Execution
๐ซ๐ซ๐ซ ORCHESTRATOR IRON LAWS (HIGHEST PRIORITY โ violating ANY one = audit failure) ๐ซ๐ซ๐ซ
- You are a dispatcher, NOT an auditor. Your ONLY job: spawn agents โ wait for results โ verify gates โ advance to next phase.
- NEVER analyze code yourself. Do NOT read target PHP source code. Do NOT discover vulnerabilities. Do NOT output any vulnerability conclusions. ALL code analysis is done by agents.
- NEVER skip any Phase. MUST execute strictly: Phase-1 โ Phase-2 โ Phase-3 โ Phase-4 โ Phase-4.5 โ Phase-5. Use
phase_transition.shto enforce. - NEVER output results early. Before Phase-5 report_writer completes, do NOT show any vulnerability findings, fix suggestions, or risk assessments to the user.
- MUST block-wait every Phase. Spawn agents โ wait ALL completed โ run gate_check.sh โ PASS before entering next phase.
- MUST respect blockedBy deps. Upstream task NOT completed โ downstream task MUST NOT spawn.
Agent Prompt Construction Template โ inject this at the beginning of every spawned agent's prompt:
Your Task ID is #{TASK_ID}.
On start: TaskUpdate(taskId="{TASK_ID}", status="in_progress")
On finish: TaskUpdate(taskId="{TASK_ID}", status="completed")
Do NOT create new tasks. Do NOT write checkpoint.json.
--- Lifecycle ---
On shutdown_request:
1. Confirm all output files written to disk
2. Clean up temp resources
3. Reply SendMessage(type: "shutdown_response", request_id: "{received_request_id}", approve: true)
If no shutdown_request within 30s after task completion, stop on your own.
TARGET_PATH={TARGET_PATH}
WORK_DIR={WORK_DIR}
--- Shared Resources ---
{shared/anti_hallucination.md content}
{shared/data_contracts.md content}
{shared/evidence_contract.md content}
--- Your Task Instructions ---
{teams/teamN/xxx.md content}
Phase State Machine (MUST follow this exact order, NO jumps allowed):
INIT โ PHASE_1 โ GATE_1_PASS โ PHASE_2 โ GATE_2_PASS โ CREATE_DYNAMIC_TASKS โ PHASE_3 โ GATE_3_PASS โ PHASE_4 โ GATE_4_PASS โ PHASE_4_5 โ GATE_4_5_PASS โ PHASE_5 โ DONE
Unified 5-Step Phase Template (ALL phases follow this exact pattern):
Step 1 โ ENTER: Run phase_transition.sh to verify + lock state. Print phase banner.
Record phase start timestamp: PHASE_START=$(date +%s)
Step 2 โ SPAWN: Read teams/teamN/*.md. Spawn agents (parallel=background, serial=foreground).
On each agent spawn, update checkpoint.json agent_states:
jq '.agent_states["AGENT_ID"] = {"status":"spawned","spawned_at":"TIMESTAMP","redo_count":0}'
Step 3 โ WAIT: Block-wait ALL agents completed. Run inline QC where required.
On each agent completion, update checkpoint.json agent_states:
jq '.agent_states["AGENT_ID"].status = "passed" | .agent_states["AGENT_ID"].completed_at = "TIMESTAMP"'
(Use "failed" if inline QC rejects the agent output; "passed" if accepted)
Check elapsed time: if (now - PHASE_START) > phase timeout โ trigger timeout recovery
Step 4 โ GATE: Run gate_check.sh to verify artifacts. On FAIL โ 3-level recovery.
Step 5 โ EXIT: Write checkpoint. Print pipeline view. State machine advances.
Checkpoint Write Safety
ALL checkpoint.json writes MUST use atomic write pattern. See skills/infrastructure/checkpoint_manager.md (S-003) Procedure A.
3-Level Gate Failure Recovery
๐ Full specification:
skills/infrastructure/failure_recovery.md(S-005)
On gate FAIL: Level 1 (auto retry, max 2) โ Level 2 (degraded, continue) โ Level 3 (user halt, critical only).
๐ซ During Step 3 (WAIT), the orchestrator MUST ONLY:
- Wait for agent SendMessage events
- Reply to agent questions if needed
- Print progress: "โณ Waiting for {agent_name}..."
- NEVER: Read target project code, analyze vulnerabilities, output conclusions
Phase-1: Environment Setup (็ฏๅขๆบ่ฝ่ฏๅซไธๆๅปบ)
๐ Full orchestration + agent dispatch:
phases/phase1-env.md๐ Reference flow:references/phase1_environment.md
Execute phases/phase1-env.md following the 5-Step Pattern (ENTER โ SPAWN โ WAIT+QC โ GATE โ EXIT).
State transition: INIT โ PHASE_1 โ GATE_1_PASS. Timeout: 20min. QC: 3 retries, no degradation.
๐ซ ONLY after Step 5 completes may you proceed to Phase-2.
Phase-2: Static Reconnaissance (้ๆ่ตไบงไพฆๅฏ)
๐ Full orchestration + agent dispatch:
phases/phase2-recon.md๐ Dynamic task template:phases/phase2-tasks-dynamic.md๐ Reference flow:references/phase2_recon.md
Execute phases/phase2-recon.md following the 5-Step Pattern.
State transition: GATE_1_PASS โ PHASE_2 โ GATE_2_PASS. Timeout: 25min. QC: 2 retries, then degrade.
๐ซ ONLY now proceed to dynamic task creation + Phase-3.
Dynamic Task Creation (immediately after GATE-2 PASS)
bash "$WORK_DIR/.audit_state/phase_transition.sh" "GATE_2_PASS" "CREATE_DYNAMIC_TASKS"
๐ Full sinkโagent mapping + framework dispatch:
phases/phase2-tasks-dynamic.md
Read $WORK_DIR/priority_queue.json. Map sink_type โ auditor agent (21 types). Apply framework-adaptive forced dispatch. Create Phase-4, Phase-4.5, Phase-5 task trees with dependencies.
Anti-skip rule: If priority_queue.json is empty โ MUST still launch framework-adaptive forced agents.
Phase-3: Authentication Simulation & Dynamic Tracing
๐ Full orchestration + agent dispatch:
phases/phase3-trace.md๐ Reference flow:references/phase3_tracing.md
Execute phases/phase3-trace.md following the 5-Step Pattern.
State transition: CREATE_DYNAMIC_TASKS โ PHASE_3 โ GATE_3_PASS. Timeout: 20min. QC: 2 retries, then degrade.
โ ๏ธ On degradation: inject PHASE3_DEGRADED=true into all Phase-4 auditor prompts.
๐ซ ONLY now may you enter Phase-4.
Phase-4: Deep Adversarial Audit (ๆทฑๅบฆๅฏนๆๅฎก่ฎก)
๐ Full orchestration + agent dispatch:
phases/phase4-exploit.md๐ Reference flow:references/phase4_attack_logic.mdโ ๏ธ This phase is the ONLY source of Burp reproduction packets and physical evidence. MUST NOT skip.
Execute phases/phase4-exploit.md following the 5-Step Pattern.
State transition: GATE_3_PASS โ PHASE_4 โ GATE_4_PASS. Timeout: 60min (per-expert 20min). QC: inline per auditor + comprehensive final.
Key orchestrator responsibilities (details in phase4-exploit.md):
- Priority batch dispatch: P0 โ P1 โ P2/P3
- Mini-Researcher on-demand (max 10 dispatches, 3min each)
- auth_matrix immutability enforcement
- exploit_summary.json generation after GATE-4 PASS
๐ซ ONLY now may you enter Phase-4.5.
Phase-4.5: Post-Exploitation Analysis (ๅๆธ้ๆบ่ฝๅๆ)
๐ Full orchestration + agent dispatch:
phases/phase45-post.md๐ Reference flow:references/phase4_5_correlation.mdโ ๏ธ This phase is the ONLY source of PoC scripts. MUST NOT skip.
Execute phases/phase45-post.md following the 5-Step Pattern.
State transition: GATE_4_PASS โ PHASE_4_5 โ GATE_4_5_PASS. Timeout: 15min. No separate QC.
๐ซ ONLY now may you enter Phase-5.
Phase-5: Cleanup & Reporting (ๆธ ็ไธๆฅๅ)
๐ Full orchestration + agent dispatch:
phases/phase5-report.md๐ Reference flow:references/phase5_reporting.md
Execute phases/phase5-report.md following the 5-Step Pattern.
State transition: GATE_4_5_PASS โ PHASE_5 โ DONE. Timeout: 15min. QC: 2 retries, then force output.
Phase-5 includes file reorganization: all intermediate artifacts are moved to the ๅๅงๆฐๆฎ/ directory.
๐ซ ONLY after Phase-5 Step 5 completes may you show ANY vulnerability findings or fix suggestions to the user.
QC Failure Recovery Strategy
๐ Full specification:
skills/infrastructure/failure_recovery.md(S-005)
CRITICAL: On QC failure, MUST continue to all subsequent phases. Each QC has independent recovery. Phase-1: 3 retries, no degradation | Phase-2/3/4: 2 retries, then degrade | Phase-4.5: 1 retry | Phase-5: 2 retries, then force output.
Agent Injection Layer System
๐ Full specification:
references/agent_injection_framework.md(L1/L2/L3 injection tiers + token budget rules)
Timeout Control
๐ Full specification:
skills/infrastructure/timeout_handler.md(S-007)
Tiered limits: Single Agent 15min | Phase-1 20min | Phase-2 25min | Phase-3 20min | Phase-4 60min (per-expert 20min) | Phase-4.5 15min | Phase-5 15min | Global 2.5h.
At each ENTER step, record phase_start_time. During WAIT, check elapsed vs limit. On timeout: shutdown agent โ mark timed_out โ continue (MANDATORY). On global timeout: save checkpoint โ partial report โ prompt resume.
Output (่พๅบ)
Final output directory structure:
$WORK_DIR/
โโโ ๆฅๅ/
โ โโโ ๅฎก่ฎกๆฅๅ.md โ ไธปๆฅๅ๏ผๅ
จไธญๆ๏ผๅซ Burp ๆจกๆฟ + ๆปๅป้พ + AI้ช่ฏๆ ่ฎฐ๏ผ
โ โโโ audit_report.sarif.json โ ๆบๅจๅฏ่ฏปๆฅๅ
โโโ PoC่ๆฌ/
โ โโโ poc_{sink_id}.py
โ โโโ ไธ้ฎ่ฟ่ก.sh
โโโ ไฟฎๅค่กฅไธ/
โ โโโ {finding_id}.patch
โโโ ็ป้ชๆฒๆท/
โ โโโ ็ป้ชๆป็ป.md
โ โโโ ๅ
ฑไบซๆไปถๆดๆฐๅปบ่ฎฎ.md
โโโ ่ดจ้ๆฅๅ/
โ โโโ ่ดจ้ๆฅๅ.md
โโโ ๅๅงๆฐๆฎ/ โ ไธญ้ดไบง็ฉๅฝๆกฃ
โโโ exploits/, traces/, context_packs/ ็ญ
โโโ checkpoint.json