{
  "hunt": {
    "meta": {
      "tlp": "clear",
      "hunt": {
        "handoff": "keep-as-periodic-hunt",
        "trigger": "intel-report",
        "methodology": "model-assisted",
        "applicability": "campaign-specific",
        "justification": "The agent-framework PyPI compromise reached nearly 200,000 monthly downloads; its automated credential harvesting can lead to total Azure or GitHub subscription takeover from a single infected build node."
      },
      "name": "Malicious Python Package Persistence and Secret Theft",
      "type": "investigation",
      "labels": [
        "hunt",
        "attack.t1195.002",
        "attack.t1546",
        "attack.t1059.006",
        "attack.t1555",
        "attack.t1003",
        "attack.t1528",
        "credential access",
        "execution",
        "exfiltration",
        "initial access",
        "persistence"
      ],
      "series": {
        "slug": "we-caught-the-agent-framework-pypi-compromise-six-minutes-after-it-published",
        "index": 1,
        "title": "We caught the agent-framework PyPI compromise six minutes after it published",
        "total": 2
      },
      "related": [
        {
          "hunt": "exfiltration-to-webhook-site",
          "reason": "This hunt focuses on the on-host lifecycle (installation, persistence, and harvesting); exfiltration behavior is a network-centric sibling hunt.",
          "relation": "out-of-scope-alternative"
        }
      ],
      "targets": {
        "hunter": {
          "name": "Hunt agent",
          "agent": true
        },
        "analyst": {
          "name": "Tier-2 analyst",
          "role": "analyst"
        },
        "endpoint": {
          "name": "Endpoint telemetry (hb_ surfaces)",
          "category": "endpoint",
          "telemetry": [
            "endpoint"
          ]
        }
      },
      "analysis": "A simple file detection can find the .pth hook, but this hunt correlates inventory status with the unusual behavioral pattern of cross-process environment reading to confirm that a package was not just installed but was actively used to steal secrets.",
      "coverage": [
        {
          "stage": "initial-access-malicious-pypi-package",
          "steps": [
            "package-inventory-scoping"
          ],
          "status": "covered"
        },
        {
          "stage": "persistence-python-pth-hook",
          "steps": [
            "malicious-file-hooks"
          ],
          "status": "covered"
        },
        {
          "stage": "execution-background-stealer-fork",
          "steps": [
            "python-stealer-processes"
          ],
          "status": "covered"
        },
        {
          "stage": "credential-access-secret-harvesting",
          "steps": [
            "harvesting-behavior"
          ],
          "status": "covered"
        },
        {
          "stage": "exfiltration-to-webhook-site",
          "reason": "Belongs to another part of the 'We caught the agent-framework PyPI compromise six minutes after it published' series.",
          "status": "out_of_scope"
        }
      ],
      "scenario": {
        "stages": [
          {
            "name": "Malicious PyPI package installation",
            "slug": "initial-access-malicious-pypi-package",
            "tactic": "initial-access",
            "techniques": [
              "T1195.002"
            ],
            "observables": [
              "agent-framework==1.26.1",
              "agent-framework==1.26.2",
              "d27fa34414e6201d5e03e559ef634f020057554d7b3f4898dd5d7cd3e989e110",
              "3d20a8bc91351a9a16b6db243b848ceca0206b7a8623b02d2af553a9c9f7e0a9"
            ]
          },
          {
            "name": "Persistence via Python .pth hook",
            "slug": "persistence-python-pth-hook",
            "tactic": "persistence",
            "techniques": [
              "T1546"
            ],
            "observables": [
              "agent_framework_meta.pth",
              "af_runtime_diag.pth",
              "_telemetry.py",
              "af_runtime_diag.py",
              "21f28e8517a10ffe431f8d68f5875c85eca4001ae6d118322b0a41873998eb5e",
              "325e7e9f0ec94e41ad1a1b7a3f18a6b8b5bffece2e2b97b8d3369eb967452f93"
            ]
          },
          {
            "name": "Background stealer execution",
            "slug": "execution-background-stealer-fork",
            "tactic": "execution",
            "techniques": [
              "T1059.006"
            ],
            "observables": [
              "os.fork()",
              "os.setsid()",
              "_AF_TEL",
              "threading.Thread",
              "t.daemon = True"
            ]
          },
          {
            "name": "Credential harvesting from disk and memory",
            "slug": "credential-access-secret-harvesting",
            "tactic": "credential-access",
            "techniques": [
              "T1555",
              "T1003",
              "T1528"
            ],
            "observables": [
              "~/.azure",
              "/proc/*/environ",
              "pip.conf",
              ".npmrc",
              ".git-credentials",
              "config.json",
              "SYSTEM_ACCESSTOKEN",
              "IDENTITY_HEADER"
            ]
          },
          {
            "name": "Network exfiltration to webhook.site",
            "slug": "exfiltration-to-webhook-site",
            "tactic": "exfiltration",
            "techniques": [
              "T1041"
            ],
            "observables": [
              "webhook.site",
              "af-runtime-diagnostics/1",
              "runtime-diagnostics/1",
              "d381fd80-ec62-42ad-8f5c-d1b15103c9bb"
            ]
          }
        ],
        "summary": "The agent-framework PyPI package (versions 1.26.1 and 1.26.2) was compromised to include a persistent credential stealer triggered by a .pth startup hook. The malware executes in the background of any Python process to harvest cloud tokens, environment variables, and configuration files from the filesystem and process memory for exfiltration to webhook.site."
      },
      "severity": "high",
      "rationale": "Target build agents, developer laptops, and CI/CD runners where Python development activity is frequent. Use the initial scoping step to limit the analysis to hosts where the specific malicious versions are present.",
      "guardrails": {
        "claims": "no_unsupported",
        "evidence": "citation_required",
        "telemetry": "untrusted",
        "missing_data": "not_benign"
      },
      "hypothesis": "An intruder has installed a compromised version of the agent-framework package which persists via a .pth hook and harvests cloud credentials by reading environment variables from the /proc filesystem and local configuration files.",
      "parameters": {
        "scope_hosts": {
          "type": "list[host]",
          "default": [],
          "description": "Narrow the hunt to specific hosts; leave empty for the entire estate."
        },
        "lookback_days": {
          "type": "number",
          "default": "14",
          "description": "Days of history to examine."
        },
        "persistence_files": {
          "from": {
            "ref": "elastic-security-labs",
            "kind": "article",
            "observed": "2026-11-18"
          },
          "type": "list[path]",
          "default": [
            "agent_framework_meta.pth",
            "_telemetry.py",
            "af_runtime_diag.pth",
            "af_runtime_diag.py"
          ],
          "description": "Filenames used by the .pth hook and telemetry loader."
        },
        "malicious_versions": {
          "from": {
            "ref": "elastic-security-labs",
            "kind": "article",
            "observed": "2026-11-18"
          },
          "type": "list[string]",
          "default": [
            "1.26.1",
            "1.26.2"
          ],
          "description": "The specific compromised versions of agent-framework."
        }
      },
      "provenance": {
        "authors": [
          {
            "org": "huntbase.io",
            "name": "Huntbase hunt generation"
          }
        ],
        "generated": {
          "by": "huntbase-hunt-generation",
          "from": "https://www.elastic.co/security-labs/threat-command/we-caught-the-agent-framework-pypi-compromise-six-minutes-after-it-published",
          "gates": [
            "dry-run",
            "lint",
            "critic"
          ],
          "model": "hb_google/gemini-3-flash-preview"
        }
      },
      "references": [
        {
          "url": "https://www.elastic.co/security-labs/threat-command/we-caught-the-agent-framework-pypi-compromise-six-minutes-after-it-published",
          "name": "Elastic Security Labs \u2014 We caught the agent-framework PyPI compromise six minutes after it published"
        }
      ],
      "blind_spots": [
        {
          "id": "auditd-not-configured",
          "risk": "The harvesting behavior might be invisible if the audit configuration does not capture reads to /proc/*/environ.",
          "stage": "credential-access-secret-harvesting",
          "question": "Are all environment variable reads via the proc filesystem being logged?",
          "requires": "hb_linux_audit specifically monitoring /proc syscalls"
        },
        {
          "id": "ephemeral-containers",
          "risk": "Build-and-destroy CI/CD nodes may install and run the stealer, perform the theft, and terminate before the inventory surface records their presence.",
          "stage": "initial-access-malicious-pypi-package",
          "question": "Did the package run in a container that was destroyed before a scan?",
          "requires": "real-time package inventory for container lifecycles"
        }
      ]
    },
    "name": "Malicious Python Package Persistence and Secret Theft",
    "description": "This hunt identifies hosts impacted by the agent-framework supply-chain compromise. The malicious versions (1.26.1 and 1.26.2) use a .pth startup hook to execute a credential stealer every time any Python script starts. The stealer forks a background process to harvest environment variables from up to 300 running processes and searches for Azure, AWS, and GitHub credential caches on disk. We trace the lifecycle from package installation and hook creation to active secret harvesting behavior."
  },
  "nodes": [
    {
      "id": "hypothesis",
      "type": "hypothesis",
      "label": "Hypothesis",
      "config": {
        "tags": [],
        "series": {
          "slug": "we-caught-the-agent-framework-pypi-compromise-six-minutes-after-it-published",
          "index": 1,
          "title": "We caught the agent-framework PyPI compromise six minutes after it published",
          "total": 2
        },
        "coverage": [
          {
            "stage": "initial-access-malicious-pypi-package",
            "steps": [
              "package-inventory-scoping"
            ],
            "status": "covered"
          },
          {
            "stage": "persistence-python-pth-hook",
            "steps": [
              "malicious-file-hooks"
            ],
            "status": "covered"
          },
          {
            "stage": "execution-background-stealer-fork",
            "steps": [
              "python-stealer-processes"
            ],
            "status": "covered"
          },
          {
            "stage": "credential-access-secret-harvesting",
            "steps": [
              "harvesting-behavior"
            ],
            "status": "covered"
          },
          {
            "stage": "exfiltration-to-webhook-site",
            "reason": "Belongs to another part of the 'We caught the agent-framework PyPI compromise six minutes after it published' series.",
            "status": "out_of_scope"
          }
        ],
        "rationale": "An intruder has installed a compromised version of the agent-framework package which persists via a .pth hook and harvests cloud credentials by reading environment variables from the /proc filesystem and local configuration files.",
        "blind_spots": [
          {
            "id": "auditd-not-configured",
            "risk": "The harvesting behavior might be invisible if the audit configuration does not capture reads to /proc/*/environ.",
            "stage": "credential-access-secret-harvesting",
            "question": "Are all environment variable reads via the proc filesystem being logged?",
            "requires": "hb_linux_audit specifically monitoring /proc syscalls"
          },
          {
            "id": "ephemeral-containers",
            "risk": "Build-and-destroy CI/CD nodes may install and run the stealer, perform the theft, and terminate before the inventory surface records their presence.",
            "stage": "initial-access-malicious-pypi-package",
            "question": "Did the package run in a container that was destroyed before a scan?",
            "requires": "real-time package inventory for container lifecycles"
          }
        ],
        "scoping_notes": "Target build agents, developer laptops, and CI/CD runners where Python development activity is frequent. Use the initial scoping step to limit the analysis to hosts where the specific malicious versions are present.",
        "beyond_detection": "A simple file detection can find the .pth hook, but this hunt correlates inventory status with the unusual behavioral pattern of cross-process environment reading to confirm that a package was not just installed but was actively used to steal secrets."
      }
    },
    {
      "id": "package-inventory-scoping",
      "type": "query",
      "label": "Scope compromised package inventory",
      "config": {
        "dsl": "sqlite",
        "role": "scoping",
        "source": "endpoint",
        "content": "SELECT device_hostname, package_name, package_version, install_path FROM hb_software_inventory WHERE LOWER(package_name) = 'agent-framework' AND instr(',' || '{{malicious_versions}}' || ',', ',' || package_version || ',') > 0",
        "surface": "hb_software_inventory",
        "description": "Identify hosts that have the malicious versions of the agent-framework package installed.",
        "expected_signal": "A list of hostnames where the malicious package is present in the software inventory. None means no hosts are reporting the specific versions."
      },
      "parents": [
        {
          "id": "hypothesis"
        }
      ],
      "primitive_config": {
        "dsl": "sqlite",
        "role": "scoping",
        "label": "Scope compromised package inventory",
        "reads": [
          "device_hostname",
          "install_path",
          "package_name",
          "package_version"
        ],
        "source": "hb_software_inventory",
        "target": "endpoint",
        "content": "SELECT device_hostname, package_name, package_version, install_path FROM hb_software_inventory WHERE LOWER(package_name) = 'agent-framework' AND instr(',' || '{{malicious_versions}}' || ',', ',' || package_version || ',') > 0",
        "silence": "not_evidence_of_absence",
        "expected": "A list of hostnames where the malicious package is present in the software inventory. None means no hosts are reporting the specific versions.",
        "verified": "dry-run",
        "verified_at": "2026-11-19"
      }
    },
    {
      "id": "malicious-file-hooks",
      "type": "query",
      "label": "Find malicious persistence hooks",
      "config": {
        "dsl": "sqlite",
        "role": "detection-candidate",
        "source": "endpoint",
        "content": "SELECT device_hostname, file_path, file_name, process_name, time FROM hb_file_activity WHERE instr(',' || '{{persistence_files}}' || ',', ',' || file_name || ',') > 0 AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days')",
        "surface": "hb_file_activity",
        "description": "Detect the creation or presence of the .pth hook files that trigger the stealer.",
        "expected_signal": "File activity rows naming the malicious .pth or .py files. This is the primary indicator of persistence."
      },
      "parents": [
        {
          "id": "package-inventory-scoping"
        }
      ],
      "primitive_config": {
        "dsl": "sqlite",
        "role": "detection-candidate",
        "label": "Find malicious persistence hooks",
        "reads": [
          "device_hostname",
          "file_name",
          "file_path",
          "process_name",
          "time"
        ],
        "source": "hb_file_activity",
        "target": "endpoint",
        "content": "SELECT device_hostname, file_path, file_name, process_name, time FROM hb_file_activity WHERE instr(',' || '{{persistence_files}}' || ',', ',' || file_name || ',') > 0 AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days')",
        "silence": "not_evidence_of_absence",
        "expected": "File activity rows naming the malicious .pth or .py files. This is the primary indicator of persistence.",
        "verified": "dry-run",
        "verified_at": "2026-11-19"
      }
    },
    {
      "id": "python-stealer-processes",
      "type": "query",
      "label": "Search for stealer background execution",
      "config": {
        "dsl": "sqlite",
        "role": "enrichment",
        "source": "endpoint",
        "content": "SELECT device_hostname, process_name, process_cmd_line, parent_process_name, time FROM hb_process_activity WHERE (LOWER(process_cmd_line) LIKE '%_telemetry%' OR LOWER(process_cmd_line) LIKE '%agent_framework_meta%') AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days')",
        "surface": "hb_process_activity",
        "description": "Identify Python processes that show behavior consistent with the detached stealer (e.g., _AF_TEL marker).",
        "expected_signal": "Processes referencing the malicious telemetry modules in their command line. This proves the hook was active."
      },
      "parents": [
        {
          "id": "package-inventory-scoping"
        }
      ],
      "primitive_config": {
        "dsl": "sqlite",
        "role": "enrichment",
        "label": "Search for stealer background execution",
        "reads": [
          "device_hostname",
          "parent_process_name",
          "process_cmd_line",
          "process_name",
          "time"
        ],
        "source": "hb_process_activity",
        "target": "endpoint",
        "content": "SELECT device_hostname, process_name, process_cmd_line, parent_process_name, time FROM hb_process_activity WHERE (LOWER(process_cmd_line) LIKE '%_telemetry%' OR LOWER(process_cmd_line) LIKE '%agent_framework_meta%') AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days')",
        "silence": "not_evidence_of_absence",
        "expected": "Processes referencing the malicious telemetry modules in their command line. This proves the hook was active.",
        "verified": "dry-run",
        "verified_at": "2026-11-19"
      }
    },
    {
      "id": "agent-infection-triage",
      "type": "analytic",
      "label": "Triage host infection status",
      "config": {
        "cite": "required",
        "tools": [
          "endpoint"
        ],
        "context": [
          "package-inventory-scoping",
          "malicious-file-hooks",
          "python-stealer-processes"
        ],
        "objective": "Identify hosts that have the malicious package installed AND show evidence of persistence hooks or telemetry process execution.",
        "description": "Determine which hosts are likely infected based on inventory and early-stage artifacts.",
        "max_iterations": 3,
        "expected_signal": "A per-host verdict confirming the infection.",
        "success_criteria": "A verdict of infected | clean per host citing the specific file or process activity found."
      },
      "parents": [
        {
          "id": "malicious-file-hooks",
          "kind": "merge"
        },
        {
          "id": "python-stealer-processes",
          "kind": "merge"
        }
      ]
    },
    {
      "id": "harvesting-behavior",
      "type": "query",
      "label": "Detect environment harvesting via /proc",
      "config": {
        "dsl": "sqlite",
        "role": "baseline",
        "source": "endpoint",
        "content": "SELECT device_hostname, process_path, path_name, COUNT(DISTINCT device_hostname) AS hosts, time FROM hb_linux_audit WHERE path_name LIKE '/proc/%/environ' AND syscall = 'open' AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days') GROUP BY process_path, path_name HAVING hosts <= 3",
        "surface": "hb_linux_audit",
        "description": "Detect the unusual behavior of a Python process reading environment files from other processes.",
        "expected_signal": "Python processes reading multiple proc environment files. This is rare and indicative of the stealer's harvesting phase."
      },
      "parents": [
        {
          "id": "agent-infection-triage"
        }
      ],
      "primitive_config": {
        "dsl": "sqlite",
        "role": "baseline",
        "label": "Detect environment harvesting via /proc",
        "reads": [
          "device_hostname",
          "path_name",
          "process_path",
          "syscall",
          "time"
        ],
        "source": "hb_linux_audit",
        "target": "endpoint",
        "content": "SELECT device_hostname, process_path, path_name, COUNT(DISTINCT device_hostname) AS hosts, time FROM hb_linux_audit WHERE path_name LIKE '/proc/%/environ' AND syscall = 'open' AND ('{{scope_hosts}}' = '' OR instr(',' || '{{scope_hosts}}' || ',', ',' || device_hostname || ',') > 0) AND time >= datetime('now', '-{{lookback_days}} days') GROUP BY process_path, path_name HAVING hosts <= 3",
        "silence": "not_evidence_of_absence",
        "baseline": {
          "window": "{{lookback_days}}d",
          "compare": "first_seen"
        },
        "expected": "Python processes reading multiple proc environment files. This is rare and indicative of the stealer's harvesting phase.",
        "verified": "dry-run",
        "prevalence": {
          "by": "device_hostname",
          "key": [
            "process_path",
            "path_name"
          ],
          "rare_below": 3
        },
        "verified_at": "2026-11-19"
      }
    },
    {
      "id": "agent-theft-analysis",
      "type": "analytic",
      "label": "Analyze active secret theft",
      "config": {
        "cite": "required",
        "tools": [
          "endpoint"
        ],
        "context": [
          "agent-infection-triage",
          "harvesting-behavior"
        ],
        "objective": "Determine if the infected hosts identified earlier are actively harvesting secrets, citing the specific proc reads or file access patterns.",
        "description": "Correlate the confirmed infection with behavioral evidence of secret harvesting.",
        "max_iterations": 4,
        "expected_signal": "A confirmed theft verdict for hosts where harvesting behavior matches the infection.",
        "success_criteria": "A final verdict of malicious-theft | suspicious | clean per host."
      },
      "parents": [
        {
          "id": "harvesting-behavior"
        }
      ]
    },
    {
      "id": "decision-route",
      "type": "checkpoint",
      "label": "Route based on theft verdict",
      "config": {
        "fuzzy": true,
        "judge": "hunter",
        "question": "the agent-theft-analysis verdict is malicious-theft for at least one host",
        "condition": "the agent-theft-analysis verdict is malicious-theft for at least one host",
        "blind_spot": "auditd-not-configured",
        "confidence": "high",
        "description": "Direct response actions based on the confirmed threat.",
        "checkpoint_type": "mandatory"
      },
      "parents": [
        {
          "id": "agent-theft-analysis"
        }
      ]
    },
    {
      "id": "isolate-compromised-host",
      "type": "action",
      "label": "Isolate compromised host",
      "config": {
        "target": "endpoint",
        "description": "Halt credential exfiltration and preserve evidence for forensics.",
        "instructions": "Isolate the host from the network immediately to stop further token exfiltration. Collect a memory dump if possible to preserve process environment variables.",
        "action_approval": "required"
      },
      "parents": [
        {
          "id": "decision-route",
          "branch": "on_supports"
        }
      ]
    },
    {
      "id": "analyst-manual-review",
      "type": "task",
      "label": "Manual analyst review",
      "config": {
        "assignee": "analyst",
        "description": "Review suspicious activity that did not meet the full threshold for automated isolation.",
        "instructions": "Review the cited rows from the theft analysis agent. Inspect the host for the presence of the .pth hook files and rotate any identities associated with the host's build environment."
      },
      "parents": [
        {
          "id": "decision-route",
          "branch": "default"
        },
        {
          "id": "decision-route",
          "branch": "on_unavailable"
        },
        {
          "id": "decision-route",
          "branch": "on_refutes"
        }
      ]
    },
    {
      "id": "task-remediate-secrets",
      "type": "task",
      "label": "Remediate and rotate secrets",
      "config": {
        "assignee": "analyst",
        "description": "Mitigate the impact of stolen credentials by rotating all exposed secrets.",
        "instructions": "Uninstall the malicious agent-framework package and pin to version 1.26.0. Rotate all secrets stored on the host, including Azure CLI caches, .npmrc tokens, and GitHub OIDC federated credentials."
      },
      "parents": [
        {
          "id": "isolate-compromised-host"
        }
      ]
    },
    {
      "id": "task-close-out",
      "type": "task",
      "label": "Close out hunt",
      "config": {
        "assignee": "analyst",
        "description": "Finalize the investigation and document findings.",
        "instructions": "Record what was found, which hosts were impacted, and whether any evidence suggests the stolen secrets were used for lateral movement in the cloud."
      },
      "parents": [
        {
          "id": "analyst-manual-review"
        },
        {
          "id": "task-remediate-secrets"
        }
      ]
    }
  ]
}