The Package That Ran Before You Imported It

On November 17, two releases of Microsoft’s agent-framework package went up on PyPI that Microsoft didn’t build. Version 1.26.1 was live at 20:35 UTC, Renovate bots were opening upgrade pull requests within six minutes, and PyPI quarantined it at 21:06. Two minutes later 1.26.2 went up with the same stealer under different file names, and both were gone by 21:16.

Forty minutes is a short window, but it doesn’t take long to install a package. The write-ups so far are about detection: how it was caught, which rules fire, what to block. This post covers the other question, the one you get asked on the 18th: one of our machines installed it, so what did it take?

I have a copy of the 1.26.2 payload, af_runtime_diag.py, and what this post says about how it works comes from reading it. I didn’t run it. For 1.26.1, which I haven’t seen, and for how the stealer behaved live, I rely on JFrog and Elastic, who took it apart, and on OX Security. Where they disagree, I say so. What I’ve added is the investigator’s view: where the evidence lives, and what it can and can’t prove.

How a .pth File Runs Code

When Python starts, its site module reads every .pth file in each site-packages directory. Most lines just add a folder to the import path. But a line that starts with import gets executed, right then, before your script runs.

The malicious 1.26.1 wheel added a 28-byte file to the root of site-packages, agent_framework_meta.pth, with one line in it:

import agent_framework_meta

That’s all it takes. Every Python process in that environment now runs the stealer: your script, pytest, the IDE’s language server, the container’s entrypoint, and pip itself. You never have to import agent_framework. Version 1.26.2 did the same thing with af_runtime_diag.pth and a module next to it, af_runtime_diag.py.

There are legitimate .pth files with import lines too: setuptools ships distutils-precedence.pth, virtualenv ships _virtualenv.pth, and editable installs leave __editable__ files. So the existence of one isn’t a finding. One you can’t account for is.

What It Took

The 1.26.2 module is 7,658 bytes of Python, and it starts with a guard:

def _start():
    if os.environ.get("_AF_TEL"):
        return
    os.environ["_AF_TEL"] = "1"

If _AF_TEL is already set, it stops. If not, it sets it, forks a detached child (a background thread on Windows, which can’t fork) and gets to work. The flag lives in the process environment, so it covers only that process and its children. When pytest starts a Python subprocess, the theft doesn’t run again. A new shell, a new CI step or a new container starts without the flag and does.

  • Your environment. Any variable whose name contains one of 35 substrings: TOKEN, SECRET, PASSWORD, KEY, AWS, AZURE, GITHUB, HF_, OPENAI, NPM, PIP and so on. Version 1.26.1 had 31; 1.26.2 added ACTIONS, OIDC, RUNNER and ARM_.
  • Everyone else’s environment. On Linux it reads /proc/<pid>/environ for up to 300 processes and keeps lines that look like secrets. If the build agent’s own process had SYSTEM_ACCESSTOKEN in it, so does the attacker.
  • Credential files. Up to 80 files (60 in 1.26.1) matching 37 patterns: Azure CLI token caches in ~/.azure/*.json, .npmrc, .netrc, .git-credentials, pip.conf, .docker/config.json, Hugging Face tokens, .env and JSON files under /app and /workspace, and Azure DevOps agent .credentials files. Three of the patterns, new in 1.26.2, are for GitHub-hosted runners under /home/runner.
  • Fresh cloud tokens. It asks the Azure instance metadata service (169.254.169.254) or App Service’s identity endpoint for managed identity tokens for 12 Azure resources. One of them is 499b84ac-1321-427f-aa17-267ca6975798, the application ID for Azure DevOps, so a managed identity with DevOps permissions hands over a DevOps token as well as the Azure ones. Then it asks for the instance metadata: subscription, resource group and VM name, a map of where the stolen tokens work.
  • Pipeline tokens. In a GitHub Actions job with id-token: write, it requests OIDC tokens for api://AzureADTokenExchange, the audience Azure federated credentials accept, and for https://management.azure.com/. That part is new in 1.26.2. Inside Azure DevOps it tries the pipeline’s OIDC endpoint, once with a scope and once without (JFrog says real Azure DevOps rejects that request; Elastic says it’s unclear).

All of it goes to a free webhook.site inbox in one HTTPS POST: JSON, compressed with zlib, then Base64. No encryption. The only thing the code bothers to hide is the inbox address, and that’s just Base64 too:

$ grep '^_ENC' af_runtime_diag.py | cut -d'"' -f2 | base64 -d
https://webhook.site/d381fd80-ec62-42ad-8f5c-d1b15103c9bb

The User-Agent is runtime-diagnostics/1. Version 1.26.1 sent the same data to the same inbox as af-runtime-diagnostics/1.

Two details matter a lot for scoping. First, nothing is written to disk to say “done”, so every new Python process that didn’t inherit the flag repeats the whole thing, with whatever is in its environment at that moment. Second, most of the 37 file patterns are Linux paths. A Mac has no /proc either, so there it mostly got environment variables and the Azure CLI cache, and Windows is much the same. That’s still plenty, but it’s a different list of things to rotate.

Reading It Without Running It

If you’ve pulled the file off one of your own hosts, or you want to check my reading, here’s how I worked with it. Do all of this on an analysis machine, not the host you’re investigating: a single python3 command there triggers the .pth file.

First, make sure it’s the same file. The hash matches the one Wiz and Endor Labs published:

$ shasum -a 256 af_runtime_diag.py
54d885b7d7161c9ed96489c66364c4bfbf635929166843bba10d97d46b5a2e1f  af_runtime_diag.py

To see what it looks for without executing it, let Python parse the file as data. The ast module reads the code but never runs it:

python3 -I -c 'import ast, sys
for n in ast.walk(ast.parse(open(sys.argv[1]).read())):
    if isinstance(n, ast.Assign) and getattr(n.targets[0], "id", "") in ("keys", "pats", "res"):
        print(n.targets[0].id, len(n.value.elts))' af_runtime_diag.py

keys 35
pats 37
res 12

That’s where the counts above come from: environment substrings, file patterns and Azure resources.

If your proxy or a packet capture kept the body of the POST, you don’t have to guess what was taken. Undo the encoding:

base64 -d < body.b64 | python3 -I -c 'import sys, zlib
sys.stdout.write(zlib.decompress(sys.stdin.buffer.read()).decode())' > stolen.json

The JSON has env, files, imds, gh_oidc and ado sections, so it amounts to a list of what to rotate. Handle stolen.json as carefully as the credentials in it.

Was It Installed?

Start with the machine, not the lockfile. Look before you touch anything with Python, because running Python is what triggers it. ls, find and grep are safe. python -c and pip list are not.

find / -name '*.pth' -path '*-packages*' 2>/dev/null \
  -exec grep -lE '^import[[:space:]]' {} +

That lists every .pth file with an import line in every Python on the box: system, Homebrew, pyenv, conda, every virtualenv. For this incident, look for these four names:

agent_framework_meta.pth   agent_framework_meta/_telemetry.py
af_runtime_diag.pth        af_runtime_diag.py

Next to them, agent_framework-1.26.1.dist-info (or 1.26.2) records the install. Its INSTALLER file says what did it (pip, uv), and RECORD lists every file the wheel put down. With pip, the files’ modification times are when they were installed. uv links files out of its cache, so there the times may reflect when the cache was filled. Either way they should fall between 20:35 and 21:16 UTC on the 17th, or later if an image or cache built in that window kept them alive.

The machine may have removed it since and still have the download. A wheel is a zip, and zip file names are stored as plain text, so you can grep pip’s and uv’s caches for them without unpacking anything (-a makes grep read binary files instead of skipping them):

grep -rlaE 'agent_framework_meta\.pth|af_runtime_diag\.pth' \
  ~/.cache/pip ~/Library/Caches/pip ~/.cache/uv 2>/dev/null

Then the places it might have come from: lockfiles and Renovate or Dependabot pull requests from the 17th, CI jobs that ran in that window, and container images built then. That last one is the long tail. An image with 1.26.1 baked into site-packages runs the stealer every time a container starts, for as long as anyone keeps running it.

Did It Run?

This is the harder question, and the honest answer is that disk can’t tell you. The payload leaves no marker, no log and no temp file. There will be .pyc files in __pycache__, but pip compiles those at install time, so they don’t prove anything ran.

The evidence that it ran is elsewhere:

  • DNS. Any lookup of webhook.site from that host. Very few legitimate processes on a build server have a reason to resolve it.
  • Proxy logs. A POST to /d381fd80-ec62-42ad-8f5c-d1b15103c9bb?t=telemetry with one of the two User-Agents. JFrog notes that early requests got HTTP 200, and that later the inbox started answering 429, “Request limit exceeded.” A 200 is a completed theft.
  • The metadata service. Requests to 169.254.169.254 from a Python process. On a host outside Azure, those requests time out, and JFrog measured about 104 seconds of timeouts before the POST. That gap is visible in a timeline. On AWS and Google Cloud, something does answer at that address (with an error), so the requests fail fast and the gap mostly shows up on laptops and on-premises hosts.
  • Endpoint telemetry. A Python process reading hundreds of /proc/*/environ files, then a forked child calling setsid. If you have auditd or an EDR on Linux build hosts, that pattern is unusual and specific.

If none of those sources exist, you’re left with inference. It was installed at 20:52, and the CI job ran pytest at 20:53, so it ran. Shell history, CI job logs and container start events give you the Python launches. Every one of them after the install time is an attempted theft, each with its own environment.

Did It Get Through?

Running isn’t the same as succeeding. Three flaws in the payload can shorten the list of hosts that actually lost something:

  • One try. It sends a single POST, waits up to 25 seconds, never retries and throws away every error. A 429 from the inbox, a block at the proxy or a timeout means that run’s data never left. A 200 means it did. If your proxy records the status code, that’s the closest thing to proof you’ll get, one run at a time.
  • Windows exits. Windows can’t fork, so there the payload runs in a background thread, and Python kills those threads when the main program ends. A short script, or a pip command that finished before the POST, probably took the theft down with it. Outside Azure that’s likely, because the metadata timeouts alone take about 100 seconds. On Linux and macOS the forked child keeps going after its parent exits, so this doesn’t help there.
  • Other processes. The /proc/*/environ sweep uses a shorter filter than the one for its own environment: names containing TOKEN, SECRET or PASSWORD, names ending in KEY, and a few specific ones like IDENTITY_HEADER. An AWS_ACCESS_KEY_ID in another process doesn’t match. It can also read only processes owned by the same user, unless it ran as root, and many CI containers run as root.

None of these lowers what you rotate unless you can show it for a specific run. A 429 on one POST says nothing about the next time Python started on that host.

That’s a timeline problem, and it’s what Recap is for. Put the install time from the dist-info, the CI job log, the DNS log and the proxy log on one clock, and the gaps and overlaps answer the question better than any one log. Record what you found, and what you couldn’t prove, in Tessera.

Clean Up Without Running It Again

Collect first. Copy the .pth file, the module, the dist-info folder and the cached wheel somewhere safe, and hash them before you change anything. The published SHA-256 values for the wheels are:

1.26.1  d27fa34414e6201d5e03e559ef634f020057554d7b3f4898dd5d7cd3e989e110
1.26.2  3d20a8bc91351a9a16b6db243b848ceca0206b7a8623b02d2af553a9c9f7e0a9

JFrog and Elastic list the hashes of the individual files too.

Then the trap. pip is a Python program, so pip uninstall starts Python, which reads the .pth file and steals everything one more time on the way out. JFrog’s fix uses the payload’s own guard against it: set the variable it checks for, and it stands down.

export _AF_TEL=1

Do that in the shell first, delete the four files and their __pycache__ entries, then uninstall, clear the package from pip’s or uv’s cache, and pin agent-framework==1.26.0.

What to Rotate

Rotate whatever it could have read, not what you think it did read. Per host, that’s every secret in the environment of every process running while Python ran, plus every credential file on the list above. Three things are easy to miss:

  • Azure CLI sessions. Changing a password or a client secret doesn’t revoke the refresh tokens sitting in ~/.azure. Revoke the Entra ID sessions too.
  • Managed identity tokens. There’s no static secret to rotate, and a stolen token can be valid for up to 24 hours. Recycle the compute, narrow the role assignments, and check the sign-in logs for that identity.
  • Self-hosted build agents. Wipe them and register them again. Their credentials were in the files it reads.

And since the inbox was a free webhook.site URL, assume the theft wasn’t private. Anyone who knows the address may be able to read what was sent to it, and the address is in every write-up.

The Bigger Lesson

Nothing here is new. .pth execution has been in Python forever, and it’s a documented persistence technique. What made it effective was the target: an AI agent framework, installed in exactly the places that hold the most cloud credentials, and upgraded automatically by bots within minutes.

The hunting command above is worth running on your build hosts today, whether or not you ever used agent-framework. You should be able to name every .pth file it finds.