Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AISecurityLab Hackagent StaticAttack

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Adversarial_Attacks
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for defining static attack techniques that transform a goal into one or more fixed chat requests for the target, provided by the HackAgent attacks framework.

Description

StaticAttack is an abstract base class for all fixed-transformation attacks. A static attack turns one goal into one or more chat requests for the target without needing to interact with the target during request generation. It never builds, configures, or calls a model on its own — when an algorithm needs an auxiliary model (a role, such as h4rm3l's decorator), its parameters declare a Completion field and whoever constructs the parameters supplies the callable.

The class provides:

  • generate(goal): Validates the goal (strips, non-empty) and delegates to build_requests.
  • build_requests(goal): Abstract — subclasses implement the actual request construction.
  • decode(response): Maps a target reply back to plain text before judging. Default is identity; cipher attacks override to reverse their cipher.

This is a Pattern Doc: it documents the interface that concrete static attacks (baseline, flipattack, cipherchat, h4rm3l, etc.) implement.

Usage

  • Implementing a new static attack: Subclass StaticAttack, set name and params_type class attributes, and implement build_requests.
  • Cipher/encoding attacks: Override decode to reverse whatever transformation the attack applied to the goal before the target saw it.

Code Reference

Source Location

Signature

class StaticAttack(ABC, Generic[ParamsT]):
    """A fixed transformation from a goal to target requests."""

    name: ClassVar[str]
    params_type: ClassVar[type[AttackParams]]

    def __init__(self, params: ParamsT) -> None: ...

    async def generate(self, goal: str) -> list[Messages]:
        """Return the chat requests to send to the target for goal."""

    @abstractmethod
    async def build_requests(self, goal: str) -> list[Messages]:
        """Build requests for a stripped, non-empty goal."""

    def decode(self, response: str) -> str:
        """Map a target reply back to plain text before it is judged."""
        return response

Import

from hackagent.attacks.techniques.static.base import StaticAttack

I/O Contract

Inputs

Name Type Required Description
params AttackParams subclass Yes Validated, immutable attack configuration with role callables
goal str Yes The attack goal text (stripped, non-empty)

Outputs

Name Type Description
generate return list[Messages] One or more chat request message-lists to send to the target
decode return str Decoded plain text from the target's raw reply

Usage Examples

Implementing a Static Attack

from hackagent.attacks.techniques.static.base import StaticAttack
from hackagent.attacks.techniques.contract import AttackParams, Messages

class MyAttackParams(AttackParams):
    """Parameters for my attack — all plain algorithm settings."""
    temperature: float = 0.7

class MyAttack(StaticAttack[MyAttackParams]):
    name = "my_attack"
    params_type = MyAttackParams

    async def build_requests(self, goal: str) -> list[Messages]:
        """Transform the goal into one or more chat requests."""
        return [
            [{"role": "user", "content": f"Please help me with: {goal}"}]
        ]

Using a Static Attack with the Runner

from hackagent.orchestrator.campaign.runner import run_campaign

# The campaign YAML names the attack; the runner resolves and runs it:
# attacks:
#   - name: my_attack
#     parameters:
#       temperature: 0.9
result = run_campaign("campaigns/my_attack_campaign.yaml")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment