Security Experts:

Connect with us

Hi, what are you looking for?

SecurityWeekSecurityWeek

Malware & Threats

PyPI Served Malicious Version of Popular ‘Ctx’ Python Package

A popular Python package was compromised recently and replaced with a malicious version apparently designed to help the attacker obtain AWS credentials.

A popular Python package was compromised recently and replaced with a malicious version apparently designed to help the attacker obtain AWS credentials.

The incident was investigated by Sonatype, SANS Institute and an independent researcher. There are actually two libraries that appear to have been targeted in the attack, but only one of them may have had a more significant impact.

The Python package named Ctx, which has, on average, 22,000 downloads per week, was compromised on the Python Package Index (PyPI) on May 14. The last Ctx update prior to this attack was uploaded to PyPI in December 2014, but new versions were published on and after May 14.

An investigation revealed that the original maintainer’s domain name expired and the attacker registered the domain on May 14. With access to the domain, they could have created an email address to which the password reset link would be sent.

The Ctx versions uploaded by the attacker — 0.1.2 (this was also the last version of the original), 0.2.2 and 0.2.6 — included functionality to steal data and upload it to a remote location controlled by the attacker.

Targeted data in one version included AWS access key ID, computer name, and AWS secret access key when a dictionary is created. Another malicious version of Ctx targeted all environment variables.

The second compromised library was the PHPass portable PHP password hashing framework. The original PHPass was deleted in September 2021, along with its original developer’s account. It appears that the developer’s username became available and it was claimed by the attacker, giving them access to the project’s GitHub account.

Both impacted libraries have been taken down. While the malicious Ctx version may have impacted many users, PHPass appears to have had only a handful of installations in recent weeks.

Sonatype reported seeing evidence that suggests the two incidents are related.

Developers who downloaded one of the two packages in recent days should ensure that they are not using one of the malicious versions. SANS Institute provides indicators of compromise (IoC).

Last week, Sonatype reported seeing PyPI serving a malicious Python package that appeared to mimic the popular PyKafka Apache Kafka client. The malicious package, named “pymafka”, was downloaded roughly 300 times. It delivered Cobalt Strike to Windows, macOS and Linux devices. 

UPDATE: Researcher Yunus Aydin, aka sockpuppets, said he was behind this attack. He claimed in a blog post published on May 25 that his activities were not malicious and that he only wanted to show the full potential impact.

Related: Checkmarx Finds Threat Actor ‘Fully Automating’ NPM Supply Chain Attacks

Related: Google Finds 35,863 Java Packages Using Defective Log4j

Related: 1,300 Malicious Packages Found in Popular npm JavaScript Package Manager

Related: New OpenSSF Project Hunts for Malicious Packages in Open Source Repositories

Written By

Eduard Kovacs (@EduardKovacs) is a contributing editor at SecurityWeek. He worked as a high school IT teacher for two years before starting a career in journalism as Softpedia’s security news reporter. Eduard holds a bachelor’s degree in industrial informatics and a master’s degree in computer techniques applied in electrical engineering.

Click to comment

Daily Briefing Newsletter

Subscribe to the SecurityWeek Email Briefing to stay informed on the latest threats, trends, and technology, along with insightful columns from industry experts.

Join this webinar to learn best practices that organizations can use to improve both their resilience to new threats and their response times to incidents.

Register

Join this live webinar as we explore the potential security threats that can arise when third parties are granted access to a sensitive data or systems.

Register

Expert Insights

Related Content

Cybercrime

The changing nature of what we still generally call ransomware will continue through 2023, driven by three primary conditions.

Cybercrime

No one combatting cybercrime knows everything, but everyone in the battle has some intelligence to contribute to the larger knowledge base.

Cybercrime

A recently disclosed vBulletin vulnerability, which had a zero-day status for roughly two days last week, was exploited in a hacker attack targeting the...

Risk Management

The supply chain threat is directly linked to attack surface management, but the supply chain must be known and understood before it can be...

ICS/OT

The overall effect of current global geopolitical conditions is that nation states have a greater incentive to target the ICS/OT of critical industries, while...

Malware & Threats

Threat actors are increasingly abusing Microsoft OneNote documents to deliver malware in both targeted and spray-and-pray campaigns.

Malware & Threats

Microsoft plans to improve the protection of Office users by blocking XLL add-ins from the internet.

Malware & Threats

A vulnerability affecting IBM’s Aspera Faspex file transfer solution, tracked as CVE-2022-47986, has been exploited in attacks.