Overview
Concrete name-to-class lookup registry for all attack techniques a campaign can run, with lazy module import and parameter schema generation, provided by the HackAgent attacks package.
Description
The registry maps attack names (baseline, flipattack, bon, pap, pair, tap, crescendo, autodan_turbo, etc.) to "module:Class" strings. get_attack_class(name) lazily imports the module and returns the class, so naming an attack does not pull in heavy dependencies. params_schema(name) returns a JSON schema of the attack's plain parameters (roles excluded, since callables have no schema). ATTACKS is a frozenset of all names; STATIC_ATTACKS and ITERATIVE_ATTACKS partition them.
Usage
- Campaign resolution: resolve_campaign uses get_attack_class() to instantiate attacks from the campaign spec.
- Planner catalog: The planner uses params_schema() to present parameter options to the LLM.
- CLI/TUI: The UI lists available attacks via ATTACKS.
Code Reference
Source Location
Signature
ATTACKS: frozenset[str]
STATIC_ATTACKS: frozenset[str]
ITERATIVE_ATTACKS: frozenset[str]
AttackType = Union[type[StaticAttack], type[IterativeAttack]]
def get_attack_class(name: str) -> AttackType:
"""Return the attack class registered under name."""
def params_schema(name: str) -> Optional[dict[str, Any]]:
"""JSON schema of name's parameters (roles excluded)."""
Import
from hackagent.attacks.techniques.registry import (
ATTACKS, STATIC_ATTACKS, ITERATIVE_ATTACKS,
get_attack_class, params_schema,
)
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| name |
str |
Yes |
Attack name (e.g. "flipattack", "bon")
|
Outputs
| Name |
Type |
Description
|
| get_attack_class() |
AttackType |
StaticAttack or IterativeAttack subclass
|
| params_schema() |
Optional[dict] |
JSON schema of plain parameters or None
|
| ATTACKS |
frozenset[str] |
All registered attack names
|
Usage Examples
Get an Attack Class
from hackagent.attacks.techniques.registry import get_attack_class
AttackClass = get_attack_class("bon")
attack = AttackClass(params) # params is a BoNParams instance
List All Attacks
from hackagent.attacks.techniques.registry import ATTACKS
for name in sorted(ATTACKS):
print(name)
Get Parameter Schema
from hackagent.attacks.techniques.registry import params_schema
import json
schema = params_schema("bon")
print(json.dumps(schema, indent=2))
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.