ctx 0.2.2 and 0.2.6 on PyPI stole environment variables and sent them to an attacker website after a hijack in May 2022.
An attacker hijacked the PyPI package ctx in May 2022. The last real release was 0.1.2 on 19 December 2014.
What happened
An attacker took control of ctx on PyPI. Sonatype found the compromise on 24 May 2022.
- The bad code read
os.environ.items()when aCtxobject was created. - It encoded the data in base64.
- It sent the data to a Heroku application endpoint.
- Sonatype reports that the 0.1.2 release was replaced on 21 May 2022.
- The PHP library
phpasscarried the same payload.
The GitHub advisory gives the compromise period as 14 to 24 May 2022.
Affected versions
- 0.1.2: the clean 2014 release, later replaced with malicious code.
- 0.2.2: malicious.
- 0.2.6: malicious.
- The GitHub advisory marks versions up to 0.1.4 as vulnerable and lists no patched version.
Indicators of compromise
- Outbound traffic to
anti-theft-web.herokuapp.com, path/hacked/. - An installed
ctxpackage from 14 to 24 May 2022. - Code in the package source that reads environment variables and posts them to a URL.
How to check
Check if ctx is installed.
pip show ctx
If it is installed, search its files for the exfiltration host. The command does not import the package.
pip show -f ctx | head -20; grep -rn "herokuapp" "$(pip show ctx | awk '/^Location/{print $2}')/ctx"
What to do now
- Uninstall
ctxand remove it from your requirements files. - If you installed it from 14 to 24 May 2022, rotate every password, API key and cloud credential in that environment.
- Check your cloud accounts for use of those credentials.
- Check your PHP projects for the
phpasslibrary from the affected fork.
What Vigilance would show
These examples show an install hold and the corresponding owner report.
Example install message
Vigilance blocked `ctx` 0.1.2. This version is too new or changed in a way Vigilance must check first.
Example owner report
Bad update
ctx 0.1.2
A tiny data-handling helper suddenly read every password stored in the computer's settings and mailed them to a stranger's website.
No security team? See who reads the alert.
Frequently asked questions
What happened to the ctx PyPI package?
An attacker hijacked it in May 2022. Bad releases sent environment variables to a Heroku site.
How do I check if I installed the malicious ctx package?
Run pip show ctx. If it is installed, search its files for herokuapp.
Sources
Send this page to the person who looks after AI at your company.