Skip to content
Account takeover Write-up Intermediate

Account Takeover and Malicious Replacement of Ctx Project

The PyPI project 'ctx' was taken over after the owner's email domain expired and was re-registered by an attacker, who then reset the account password and uploaded malicious releases. These releases collected environment variables and sent them to an attacker-controlled server, potentially exposing secrets like API keys.

python-security.readthedocs.io

Published on python-security.readthedocs.io

The ctx hosted project on PyPI was taken over via user account compromise and replaced with a malicious project which contained runtime code which collected the content of os.environ.items() when instantiating Ctx objects. The captured environment variables were sent as a base64 encoded query parameter to a heroku…

The author, on python-security.readthedocs.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the owner's email domain expired and was re-registered by the attacker, who then used it to reset the account password because multi-factor authentication was not enabled.

Impact

Users who installed the malicious versions could have had their environment variables, including sensitive data like passwords and API keys, exfiltrated to the attacker.

What the attacker needed

Owner's email domain expired; attacker registers the expired domain; no multi-factor authentication on account

The fix

The malicious releases were removed, the project name was prohibited from re-registration, and the compromised account was frozen; additionally, enabling multi-factor authentication and using hash-checking mode are recommended.

How it was found

  1. The domain hosting the owner's email expired and was registered by the attacker.
  2. The attacker initiated a password reset for the owner's PyPI account.
  3. The attacker completed the password reset and gained access to the account.
  4. The attacker uploaded malicious versions of the 'ctx' project to PyPI.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

An attacker took control of a software package on PyPI (a public repository for Python code) by exploiting an expired email domain. They then uploaded malicious versions that stole sensitive information from users' computers when the package was installed and used.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.