Skip to content
RCE Disclosed report Intermediate

Command injection on Phabricator instance with an evil hg branch name

A Mercurial branch name beginning with a command-line option was passed unsanitised into a shell command run by Phabricator, so a crafted branch name could inject an arbitrary hook and execute commands on the server. An attacker who controls a monitored remote repository could run commands on the Phabricator host when the branch history page was viewed.

criticalonly Follow

Originally disclosed on HackerOne

Critical 9.9 View original
  • Fixed in 32 hours
  • Paid in 32 hours
  • Disclosed after 40 hours

Hi phabricator,

I found an evil branch name of hg a repo can lead to arbitrary command injection on phabricator instance.

Here is the reproduction steps:

  1. Monitor a remote mercurial repo with phabricator;
  2. Create a branch and called "--config=hooks.pre-log=wget" on the remote;
  3. After phabricator update the remote repo,visit the history page of that crafted branch;
http://instanceip/source/hgclone/history/--config%253Dhooks.pre-log%253Dwget/
  1. It will raise an error like below and the wget command will be executed;
  2. I test this issue both on my own server instance and the cloud instance with mercurial 4.4(latest) installed(on my server).
Command failed with error #255! COMMAND hg --config ui.ssh='/data/phabricator/phabricator/bin/ssh-
connect' log --debug --template '{node};{parents}\n' --limit 101 -b '--config=hooks.pre-log=wget' --rev 
'reverse(ancestors('\''84e8c5feb4faba2f1b230575e747c3bffe7c7a3c'\''))' STDOUT running hook pre-log: 
wget STDERR not trusting file /var/repo/3/.hg/hgrc from untrusted user root, group root not trusting file 
/var/repo/3/.hg/hgrc from untrusted user root, group root wget: missing URL Usage: wget [OPTION]... 
[URL]... Try `wget --help' for more options. abort: pre-log hook exited with status 1

The root cause is that the branch name inject to the hg command directly and that define a hook will run before the hg log command been executed. Thanks!

Attachments

evil_hg_branch_name_command_injection.png
evil_hg_branch_name_command_injection.png From the original on HackerOne
evil_hg_branch_name_command_injection_cloud.png
evil_hg_branch_name_command_injection_cloud.png

The original report as published on HackerOne, by criticalonly. 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 branch name was interpolated directly into the hg command line without validation, so a name starting with dashes was parsed as an option such as a hook definition.

Impact

An attacker controlling a monitored repository could execute arbitrary commands on the Phabricator server, as demonstrated by running wget.

What the attacker needed

Control of a monitored Mercurial repo; Phabricator watches that repository; victim views the crafted branch history

How it was found

  1. Set up Phabricator to monitor a remote Mercurial repository.
  2. Create a branch on the remote whose name looks like a Mercurial configuration option defining a hook.
  3. Let Phabricator pull the updated repository.
  4. Visit the history page for that crafted branch.
  5. Observe the error output and that the injected command ran.

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.

Phabricator can watch a remote Mercurial code repository and show its branches. The name of a branch was placed straight into a command the server runs, and Mercurial treats names starting with dashes as extra options. By naming a branch so it looked like a configuration option, the reporter made the server run a command of their choosing.

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 criticalonly

View all

1 more disclosed report, best first.

More from Phabricator

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.