PyPI’s 2FA Requirements Don’t Go Far Enough, Researchers Say

The official open source code repository for the Python programming language, the Python Package Index (PyPI), will require all user accounts to enable two-factor authentication (2FA) by the end of 2023.

The security move may help prevent cyberattackers from compromising maintainer accounts and injecting malicious code into existing legitimate projects, but it’s not a silver bullet when it comes to shoring up overall software supply chain security, researchers warn.

“Between now and the end of the year, PyPI will begin gating access to certain site functionality based on 2FA usage,” explained PyPI administrator and maintainer Donald Stufft, in a recent blog posting. “In addition, we may begin selecting certain users or projects for early enforcement.”

To implement 2FA, package maintainers have the option to use a security token or other hardware device, or an authentication app; and Stufft said that users are encouraged to switch to using either PyPI’s Trusted Publishers feature or API tokens to upload code to PyPI.

Stemming PyPI’s Malicious Package Activity

The announcement comes amidst a slew of attacks by cybercriminals looking to infiltrate various software programs and apps with malware that can then go on to be widely disseminated. Since PyPI and other repositories like npm and GitHub house the building blocks that developers use to build those offerings, compromising their contents is a great way to do that.

Researchers say that 2FA in particular (which GitHub also recently implemented) will help prevent developer account takeover, which is one way that bad actors get their hooks into apps.

“We’ve seen phishing attacks launched against the project maintainers for commonly used PyPI packages that are intended to compromise those accounts,” says Ashlee Benge, director of threat intelligence advocacy at ReversingLabs. “Once compromised, those accounts can easily be used to push malicious code to the PyPI project in question.”

One of the most likely scenarios of initial infection would be a developer accidentally installing a malicious package, for example, typing a Python install command by mistake, says Dave Truman, vice president of cyber-risk at Kroll.

“A lot of the malicious packages contain functionality for stealing credentials or browser session cookies and are coded to run on the malicious package being installed,” he explains. “At this point, the malware would steal their credentials and sessions which could possibly include logins usable with PyPI. In other words … one developer could allow the actor to pivot to a major supply chain attack depending on what that developer has access to — 2FA on PyPI would help stop the actor taking advantage of [that].”

More Software Supply Chain Security Work to Do

ReversingLabs’ Benge notes that while PyPI’s 2FA requirements are a step in the right direction, more security layers are needed to really lock down the software supply chain. That’s because one of the most common ways that cybercriminals leverage software repositories is by uploading their own malicious packages in hopes of duping developers into pulling them into their software.

After all, anyone can sign up for a PyPI account, no questions asked.

These efforts usually involve mundane social-engineering tactics, she says: “Typosquatting is common — for example, naming a package ‘djanga’ (containing malicious code) versus ‘django’ (the legitimate and commonly used library).”

Another tactic is to hunt for abandoned projects to bring back to life. “A formerly benign project is abandoned, removed, and then repurposed for hosting malware, like with termcolour,” she explains. This recycling approach offers malicious actors the benefit of using the former project’s legitimate reputation to lure in developers.

“Adversaries are continually figuring out multiple ways to get developers to use malicious packages, which is why it’s critical for Python and other programming languages with software repositories like PyPi to have a comprehensive software supply chain approach to security,” says Javed Hasan, CEO and co-founder, Lineaje.

Also, there are multiple ways to defeat 2FA, Benge notes, including SIM swapping, OIDC exploitation, and session hijacking. While these tend to be labor intensive, motivated attackers will still go to the trouble of trying to work around MFA and certainly 2FA, she says.

“Such attacks require much higher levels of engagement by attackers and many additional steps that will deter less motivated threat actors, but compromising an organization’s supply chain offers a potentially huge payoff for threat actors, and many may decide that the extra effort is worth it,” she says.

While repositories take steps to make their environments safer, organizations and developers need to take their own precautions, Hasan counsels.

“Organizations need modern supply chain tamper detection tools that help companies break down what’s in their software and avoid deployment of unknown and dangerous components,” he says. Also, efforts like software bills of materials (SBOMs) and attack surface management can help.

Read More HERE

Leave a Reply