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.
Originally disclosed on HackerOne
- 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:
- Monitor a remote mercurial repo with phabricator;
- Create a branch and called "--config=hooks.pre-log=wget" on the remote;
- After phabricator update the remote repo,visit the history page of that crafted branch;
http://instanceip/source/hgclone/history/--config%253Dhooks.pre-log%253Dwget/
- It will raise an error like below and the wget command will be executed;
- 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


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
- Set up Phabricator to monitor a remote Mercurial repository.
- Create a branch on the remote whose name looks like a Mercurial configuration option defining a hook.
- Let Phabricator pull the updated repository.
- Visit the history page for that crafted branch.
- 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.