Skip to content

FEAT: Add Garak malwaregen scenario - #4658

Open
thelastbackspace wants to merge 2 commits into
microsoft:mainfrom
thelastbackspace:feat/3929-garak-malwaregen
Open

thelastbackspace wants to merge 2 commits into
microsoft:mainfrom
thelastbackspace:feat/3929-garak-malwaregen

Conversation

@thelastbackspace

Copy link
Copy Markdown
Contributor

Description

Adds garak.malwaregen, a port of garak's malwaregen probes (TopLevel, SubFunctions, Evasion, Payload) at the 3f50ea5f commit PyRIT already pins. Closes #3929, part of #511.

  • Local datasets for the 8 languages, the 16 request templates (tagged by probe) and the 15 payload types, with provenance entries. Rendered, they give the same 240 prompts as garak, in the same order.
  • CodePresenceScorer, a RegexScorer port of malwaregen.AnyCode. The regexes are copied unchanged. The only difference is that garak's re.I on the x86/x86_64 patterns is written as an inline (?i). I didn't change any pattern, so there's nothing to list in the docstring yet. A test pins the scorer's patterns to garak's.
  • MalwareGen scenario with one technique per probe. It follows ApiKey's setup: the corpus is required data, and MalwareGenDatasetConfiguration samples 20 requests across the selected techniques by default (max_total="all" runs all 240).
  • The default objective scorer is CodePresenceScorer AND an inverted SelfAskRefusalScorer on the scoring target. AnyCode is tuned for recall (the x86 pattern matches "remove" or "compare" in plain English), so without the refusal check a lot of refusals would count as hits. Pass objective_scorer=CodePresenceScorer() for garak's detector alone.
  • Docs: a MalwareGen section in the garak scanner notebook, plus short mentions in the dataset and true/false scorer docs.

I don't have an endpoint to run notebooks against, so the new MalwareGen result cell in garak.ipynb has no saved output. test_all_scenario_notebooks_have_saved_output will fail until someone reruns that notebook. Happy to add the output if there's a way for me to run it.

Port garak's malwaregen probes (TopLevel, SubFunctions, Evasion, Payload)
at commit 3f50ea5f as the garak.malwaregen scenario, with local datasets for
the languages, templates and payload types.

CodePresenceScorer ports malwaregen.AnyCode with the regexes unchanged. The
default objective scorer combines it with an inverted SelfAskRefusalScorer so
a refusal that matches a pattern isn't counted.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 08:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The default MalwareGen configuration runs 240 requests instead of the advertised 20, and missing saved notebook output causes the documentation test to fail.

2 open issues
What changed in this PR

Adds garak.malwaregen to PyRIT’s scanner, extending Garak feature parity with four malware-generation probe groups and code-presence scoring.

Changes:

  • Adds three local corpora that assemble into 240 requests across eight languages.
  • Introduces MalwareGen and CodePresenceScorer, with refusal-aware scoring and configurable sampling.
  • Adds unit tests, documentation examples, lazy exports, and provenance records.
File Description
third_party/​garak-provenance.json Records sources for Garak-derived additions.
tests/​unit/​score/​regex/​test_code_presence_scorer.py Tests regex parity and detection behavior.
tests/​unit/​scenario/​garak/​test_malwaregen.py Tests assembly, sampling, scoring, and resume.
tests/​unit/​datasets/​test_garak_malwaregen_dataset.py Checks corpus counts and contents.
pyrit/​score/​true_false/​regex/​code_presence_scorer.py Adds Garak-compatible code detection.
pyrit/​score/​true_false/​regex/​__init__.py Lazily exports the new scorer.
pyrit/​score/​__init__.py Exposes the scorer through the public API.
pyrit/​scenario/​scenarios/​garak/​malwaregen.py Implements the scenario and dataset configuration.
pyrit/​scenario/​scenarios/​garak/​__init__.py Exports the scenario and supporting types.
pyrit/​datasets/​seed_datasets/​local/​garak/​malwaregen_templates.prompt Adds 16 probe templates.
pyrit/​datasets/​seed_datasets/​local/​garak/​malwaregen_payload_tasks.prompt Adds 15 payload categories.
pyrit/​datasets/​seed_datasets/​local/​garak/​malwaregen_languages.prompt Adds eight programming languages.
doc/​scanner/​garak.py Documents scenario usage and examples.
doc/​scanner/​garak.ipynb Adds the paired MalwareGen notebook example.
doc/​code/​scoring/​1_true_false_scorers.py Describes code-presence scoring.
doc/​code/​scoring/​1_true_false_scorers.ipynb Mirrors the scorer documentation.
doc/​code/​datasets/​1_loading_datasets.py Lists the new local corpora.
doc/​code/​datasets/​1_loading_datasets.ipynb Mirrors the dataset documentation.

Review effort: Balanced

Comment thread doc/scanner/garak.ipynb
"execution_count": null,
"id": "48",
"metadata": {},
"outputs": [],
Comment on lines +125 to +126
def _default_max_per_dataset(self) -> Literal["all"]:
return "all"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in b458a1c. The config now defaults to 20 like the other garak scenarios, with a test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: Add Garak malwaregen scenario

2 participants