Poisoned Pipeline / Techniques / T0244

T0244 · Execution · TA04 · observed in 1 incident(s)

Run a payload at every interpreter start from a site-packages hook

Open Source Security CI/CD Posture

A Python wheel installs its files straight into site-packages, and the
interpreter's site initialization reads every .pth file it finds there.
Lines in a .pth file that begin with "import" are executed rather than
treated as path entries, so a one-line file turns any module sitting beside
it into a program that starts with Python. Nothing has to import the
package. One pip install plants the hook, and every later interpreter start
in that environment — pip itself, pytest, a linter, a build script, a
notebook kernel, the application — runs the payload first, before any of
the user's own code has decided what to trust.

The mechanism is worth separating from the two things it is usually filed
under. An install-time script (T0151) runs once, during the install, and
leaves a line in the install log; a backdoor inside the package (T0138)
only fires if something imports the module that holds it. A .pth hook is
neither: it produces no install output, and it does not care whether the
package is used. The Microsoft agent-framework releases of 17 November
2026 are the clearest case — 1.26.2 shipped a 23-byte af_runtime_diag.pth
containing "import af_runtime_diag" and a 7,658-byte module beside it,
while the package's own __init__.py was restored to byte-identical clean
content so that anyone diffing the importable code would find nothing. A
CI job that installed the package and then ran pytest was compromised
before the first test collected.

The hook is also cheap to disguise. Both releases used names that read as
tooling — af_runtime_diag, agent_framework_meta — and the payload set an
anti-recursion flag, forked, detached with setsid (T0245) and suppressed
every exception so the visible behaviour of the machine is unchanged.

This is not operating-system persistence. No service, cron entry, scheduled
task or registry key is created, and the hook disappears when the
site-packages directory does; what persists is the registry entry that
keeps the malicious files one resolution away. The defending question is
therefore not "was this package imported" but "what executable lines are in
the .pth files of every environment that installed it" — a file type most
inventory tools never read.

Distinct from T0151, which is code run by the installer, and from T0138,
which is code reached through the package's own API. Here execution is
attached to the interpreter's startup, and the package's importable code
can be perfectly clean while it happens.

Where this idea came from

Public incident / advisory

From the 17 November 2026 Microsoft agent-framework PyPI compromise, where 1.26.1 shipped agent_framework_meta.pth and 1.26.2 shipped a 23-byte af_runtime_diag.pth plus a 7,658-byte module, and the importable package code was restored to byte-identical clean content in the second release. Site initialization executes .pth lines beginning with "import", so the payload ran on every interpreter start in the environment without the package being imported. Earlier catalogue entries used the same primitive as one persistence line among several (AS67 mrmustard); this records it as the execution mechanism. Distinct from T0151 (installer-time code, logged and once), T0138 (code behind the package's own API) and T0172 (a runtime backdoor). It is not OS persistence — no service, cron entry or scheduled task is created, and the hook lasts only as long as the files stay.

Mitigations

None linked yet.

Detections

None linked yet.

Observed in incidents (1)

References