Overview
Automated CTF challenge solver that executes workflow steps, extracts flag candidates via regex patterns, validates flag formats, and generates manual guidance when automation fails.
Description
The CTFChallengeAutomator class attempts to automatically solve CTF challenges by executing the workflow generated by CTFWorkflowManager. It processes each workflow step (parallel or sequential), extracts flag candidates from tool output using regex patterns (flag{...}, ctf{...}, MD5/SHA1/SHA256 hashes), validates flag formats, and tracks confidence. If no flag is found, it generates manual guidance steps.
Usage
- Auto-solve: Call auto_solve_challenge(challenge) to attempt automated solving
- Flag extraction: Use _extract_flag_candidates(output) to find flag patterns in tool output
- Flag validation: Use _validate_flag_format(flag) to verify a candidate matches common formats
Code Reference
Source Location
- Repository: HexStrike AI
- File: hexstrike_server.py
- Lines: L3855-4017 (CTFChallengeAutomator class)
Signature
class CTFChallengeAutomator:
def __init__(self):
self.active_challenges: Dict[str, Any] = {}
self.solution_cache: Dict[str, Any] = {}
self.learning_database: Dict[str, Any] = {}
self.success_patterns: Dict[str, Any] = {}
def auto_solve_challenge(self, challenge: CTFChallenge) -> Dict[str, Any]:
"""Attempt to automatically solve a CTF challenge."""
def _extract_flag_candidates(self, output: str) -> List[str]:
"""Extract potential flags from tool output using regex patterns."""
def _validate_flag_format(self, flag: str) -> bool:
"""Validate if a string matches common flag formats (flag{...}, ctf{...})."""
def _generate_manual_guidance(self, challenge: CTFChallenge, current_result: Dict) -> List[Dict[str, str]]:
"""Generate manual guidance when automation fails."""
Import
from hexstrike_server import CTFChallengeAutomator
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| challenge |
CTFChallenge |
Yes |
Challenge to auto-solve
|
Outputs
| Name |
Type |
Description
|
| challenge_id |
str |
Challenge name identifier
|
| status |
str |
"solved" / "needs_manual_intervention" / "error"
|
| automated_steps |
List[Dict] |
Results from each executed workflow step
|
| flag_candidates |
List[str] |
Extracted flag pattern matches
|
| confidence |
float |
0.0-1.0, increases by 0.1 per successful step
|
| flag |
str |
The solved flag (only present if status="solved")
|
| manual_steps |
List[Dict] |
Guidance for manual solving (if not solved)
|
Usage Examples
Auto-Solving a CTF Challenge
from hexstrike_server import CTFChallenge, CTFChallengeAutomator
challenge = CTFChallenge(
name="Web SQL Injection",
category="web",
description="Exploit SQL injection in the search parameter to find the flag.",
difficulty="easy",
url="http://challenge.ctf.example.com"
)
automator = CTFChallengeAutomator()
result = automator.auto_solve_challenge(challenge)
print(f"Status: {result['status']}")
print(f"Confidence: {result['confidence']:.0%}")
print(f"Flag candidates: {result['flag_candidates']}")
if result['status'] == 'solved':
print(f"Flag: {result['flag']}")
elif result['status'] == 'needs_manual_intervention':
print(f"Manual steps: {result['manual_steps']}")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.