Malicious PyPI Package 'gradient-descent-optimizer' Steals AI/Cloud Credentials
Overview
A malicious Python package named `gradient-descent-optimizer` was discovered and removed from the Python Package Index (PyPI). This package was a supply chain attack targeting AI and machine learning developers by typosquatting popular library names. The package's `setup.py` file contained an obfuscated malicious script that was executed upon installation via `pip`. The script's primary function was to harvest sensitive credentials from the developer's machine. It systematically searched for common locations where API keys and secrets are stored, including environment variables (`OPENAI_API_KEY`, `AWS_ACCESS_KEY_ID`), configuration files (`~/.aws/credentials`, `~/.gcp/config`), shell history files (`~/.bash_history`), and Kubernetes configuration (`~/.kube/config`). After collecting the credentials, the payload would Base64-encode them and exfiltrate the data to an attacker-controlled server using the DNS protocol to bypass egress firewall rules, hiding the traffic as legitimate DNS queries. This sophisticated attack demonstrates the growing threat of supply chain attacks in the AI ecosystem, where developers frequently install numerous open-source packages. The compromise of these keys could lead to significant financial loss through fraudulent use of cloud and AI API services, as well as theft of valuable intellectual property like private models and datasets.
Affected Systems
Testing Guide
1. **Check Installed Packages:** Run `pip list | grep gradient-descent-optimizer` to see if the malicious package is installed in your Python environment. 2. **Review Shell History:** Check your shell history (`history | grep 'pip install gradient-descent-optimizer'`) to see if the package was installed in the past. 3. **Scan Network Logs:** If available, review DNS query logs from the potentially affected machine for unusual TXT or A record queries to unknown domains around the time of installation, which could indicate data exfiltration.
Mitigation Steps
1. **Remove the Package:** If installed, immediately uninstall the package using `pip uninstall gradient-descent-optimizer`. 2. **Rotate All Credentials:** Assume all secrets on the affected machine have been compromised. Immediately rotate all API keys (OpenAI, Hugging Face, etc.), cloud credentials (AWS, GCP, Azure), SSH keys, and any other secrets found on the machine. 3. **Audit Systems:** Perform a full security audit of the compromised machine to check for persistence mechanisms or further malware. 4. **Use Scanners:** Vet new packages using tools like `pip-audit` or other software composition analysis (SCA) scanners before installing them. 5. **Isolate Build Environments:** Use locked dependency files (`requirements.txt`, `poetry.lock`) and perform installations in isolated, short-lived environments (e.g., Docker containers) rather than directly on developer workstations.
Patch Details
The malicious package was removed from the PyPI registry on 2026-02-19. There is no 'patch' other than removing the package and rotating all secrets.