CAPEC-695: Repo Jacking
An adversary takes advantage of the redirect property of directly linked Version Control System (VCS) repositories to trick users into incorporating malicious code into their applications.
Last updated
Overview
Software developers may directly reference a VCS repository (i.e., via a hardcoded URL) within source code to integrate the repository as a dependency for the underlying application. If the repository owner/maintainer modifies the repository name, changes their VCS username, or transfers ownership of the repository, the VCS implements a redirect to the new repository location so that existing software referencing the repository will not break. However, if the original location of the repository is reestablished, the VCS will revert to resolving the hardcoded path. Adversaries may, therefore, re-register deleted or previously used usernames and recreate repositories with malicious code to infect applications referencing the repository. When an application then fetches the desired dependency, it will now reference the adversary's malicious repository since the hardcoded repository path is once again active. This ultimately allows the adversary to infect numerous applications, while achieving a variety of negative technical impacts.
How the attack works
The phases an attacker typically follows.
- Step 1Explore
[Identify target] The adversary must first identify a target repository that is commonly used and whose owner/maintainer has either changed/deleted their username or transferred ownership of the repository and then deleted their account. The target should typically be a popular and widely used package, as to increase the scope of the attack.
- Step 2Experiment
[Recreate initial repository path] The adversary re-registers the account that was renamed/deleted by the target repository's owner/maintainer and recreates the target repository with malicious code intended to exploit an application. These steps may need to happen in reverse (i.e., recreate repository and then rename an existing account to the target account) if protections are in place to prevent repository reuse.
- Step 3Exploit
[Exploit victims] The adversary's malicious code is incorporated into applications that directly reference the initial repository, which further allows the adversary to conduct additional attacks.
What the attacker needs
Prerequisites
- Identification of a popular repository that may be directly referenced in numerous software applications
- A repository owner/maintainer who has recently changed their username or deleted their account
Skills required
- Low skill: Ability to create an account on a VCS hosting site and recreate an existing directory structure.
- Low skill: Ability to create malware that can exploit various software applications.
Consequences
What a successful CAPEC-695 attack can achieve.
Read Data, Modify Data
Affects: Integrity
Execute Unauthorized Commands, Alter Execution Logic, Gain Privileges
Affects: Access Control, Authorization
How to mitigate it
Defenses that reduce the risk of CAPEC-695.
- Leverage dedicated package managers instead of directly linking to VCS repositories.
- Utilize version pinning and lock files to prevent use of maliciously modified repositories.
- Implement "vendoring" (i.e., including third-party dependencies locally) and leverage automated testing techniques (e.g., static analysis) to determine if the software behaves maliciously.
- Leverage automated tools, such as Checkmarx's "ChainJacking" tool, to determine susceptibility to Repo Jacking attacks.
Examples
In May 2022, the CTX Python package and PhPass PHP package were both exploited by the same adversary via Repo Jacking attacks. For the CTX package, the adversary performed an account takeover via a password reset, due to an expired domain-hosting email. The attack on PhPass entailed bypassing GitHub's authentication for retired repositories. In both cases, sensitive data in the form of API keys and passwords, each stored in the form of environment variables, were exfiltrated. [2] [3]
In October 2021, the popular JavaScript library UAParser.js was exploited via the takeover of the author's Node Package Manager (NPM) account. The adversary-provided malware downloaded and executed binaries from a remote server to conduct crypto-mining and to exfiltrate sensitive data on Windows systems. This was a wide-scale attack as the package receives 8 to 9 million downloads per week. [2]
Terminology & mappings
Mapped taxonomies
- ATTACK: Supply Chain Compromise: Compromise Software Dependencies and Development Tools (1195.001)
Frequently asked questions
Common questions about CAPEC-695.
- What is CAPEC-695?
- An adversary takes advantage of the redirect property of directly linked Version Control System (VCS) repositories to trick users into incorporating malicious code into their applications.
- How does a Repo Jacking attack work?
- It typically unfolds over 3 phases. It begins with: [Identify target] The adversary must first identify a target repository that is commonly used and whose owner/maintainer has either changed/deleted their username or transferred ownership of the repository and then deleted their account. The target should typically be a popular and widely used package, as to increase the scope of the attack.
- How do you prevent CAPEC-695?
- Leverage dedicated package managers instead of directly linking to VCS repositories.
- What weaknesses does CAPEC-695 target?
- CAPEC-695 exploits 2 CWE weaknesses: CWE-494 (Download of Code Without Integrity Check) and CWE-829 (Inclusion of Functionality from Untrusted Control Sphere).
- How severe is CAPEC-695?
- MITRE rates CAPEC-695 as High severity with medium likelihood of attack.
Sources
- [1]Repo Jacking: Exploiting the Dependency Supply Chain (2020)
- [2]CyRC Vulnerability Analysis: Repo jacking in the software supply chain (2022)
- [3]Attacker Caught Hijacking Packages Using Multiple Techniques to Steal AWS Credentials (2022)
- [4]GitHub RepoJacking Weakness Exploited in the Wild by Attackers (2022)
References
Attack-pattern data is sourced from the MITRE CAPEC catalog (v3.9). Weakness associations link to the corresponding CWE entries on RadicalNotion.AI.
Defend against CAPEC-695
Track the CVEs and weaknesses this technique exploits, with AI-written analysis and remediation steps.