
Proof of Concept for CVE-2024-32002: Git submodule path injection vulnerability.
While solving the Compiled machine on the Hack The Box platform, I came across a curious behavior involving Git and submodules. Upon investigating further, I found this excellent post by researcher Amal Murali, which details a path injection technique via .gitmodules. From there, I decided to study CVE-2024-32002 and create a practical PoC demonstrating the real impact of the vulnerability.
CVE-2024-32002 exploits a critical flaw in Git related to submodule path resolution. Git allows repositories to include submodules defined in the .gitmodules file, specifying both a path and a URL. The vulnerability arises when the path is manipulated to point inside the .git directory, which stores metadata and internal configurations of the repository.
By combining:
.gitmodules to set the path to A/modules/xa → .git…Git is tricked into resolving A/modules/x as .git/modules/x, i.e., inside the internal .git directory. This allows an attacker to inject arbitrary files such as malicious hooks, which can be executed during legitimate operations like checkout, merge, or clone.
This vulnerability represents a remote code execution vector, especially dangerous in CI/CD environments, automation, or shared repositories.
setup.sh script demonstratesThis script automates the creation of a vulnerable environment and reproduces the impact of the flaw:
hook-repo) containing a post-checkout hook that writes to /tmp/teste.txtmain-repo) and adds the submodule.gitmodules file to redirect the submodule path to A/modules/xa → .git, causing A/modules/x to be resolved as .git/modules/x.gitmodules into the index using git update-index --index-infocloned-repo) with , initializing the submoduleIf successful, the hook executes and creates the file /tmp/teste.txt with the content:
joao was here
This repository includes a Dockerfile that:
docker build -t git-cve-poc .
docker run --rm -it git-cve-poc
This vulnerability affects Git versions prior to 2.45.1. The flaw was fixed with stricter validations in submodule path resolution. Repositories that use submodules should be audited, and automated environments should be updated immediately.
This project is for educational and research purposes only. Do not use in production environments. The goal is to demonstrate the technical impact of the vulnerability and promote good security practices.
--recursive.git/hooks/ and runs git checkout HEAD to trigger the exploit