Repository navigation
FEAT: Add Garak malwaregen scenario - #4658
Open
thelastbackspace wants to merge 2 commits into
Open
thelastbackspace wants to merge 2 commits into
thelastbackspace wants to merge 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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
MalwareGenandCodePresenceScorer, 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
| "execution_count": null, | ||
| "id": "48", | ||
| "metadata": {}, | ||
| "outputs": [], |
Comment on lines
+125
to
+126
| def _default_max_per_dataset(self) -> Literal["all"]: | ||
| return "all" |
Contributor
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.CodePresenceScorer, aRegexScorerport ofmalwaregen.AnyCode. The regexes are copied unchanged. The only difference is that garak'sre.Ion 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.MalwareGenscenario with one technique per probe. It follows ApiKey's setup: the corpus is required data, andMalwareGenDatasetConfigurationsamples 20 requests across the selected techniques by default (max_total="all"runs all 240).CodePresenceScorerAND an invertedSelfAskRefusalScoreron 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. Passobjective_scorer=CodePresenceScorer()for garak's detector alone.I don't have an endpoint to run notebooks against, so the new MalwareGen result cell in
garak.ipynbhas no saved output.test_all_scenario_notebooks_have_saved_outputwill fail until someone reruns that notebook. Happy to add the output if there's a way for me to run it.