Remote Code Execution via hg argument injection
The Pontoon application passed an unsanitised project repository URL directly into an hg clone command. An attacker could inject hg configuration options to define an alias that executes arbitrary shell commands, leading to remote code execution.
- Fixed in 6 days
- Paid in 11 days
- Disclosed after 6 days
Steps to reproduce:
Hi, my name is Alessio and I am contacting you on behalf of Snyk Security team.
I am contacting you in regards to a Remote Code Execution vulnerability within your maintained project https://github.com/mozilla/pontoon
Steps to Reproduce:
1. Install pontoon locally (I used Docker)
- follow the instruction here https://mozilla-pontoon.readthedocs.io/en/latest/dev/setup.html
- git clone https://github.com/mozilla/pontoon.git
- cd pontoon/
- make build
- make run
- make setup
- sign in http://localhost:8000/accounts/standalone-login/ (I used username `pontoon` and password `pontoon`)
2. RCE Exploitation
In order to demonstrate this vulnerability, the output of the command `id` will be redirected in a static resource that is accessible from the web application
- visit http://localhost:8000/admin/projects/
- set `Name` and `slug` project
- select one `Locales`
- In the `Repositories` section, select Type `HG`
- in the URL field paste `--config=alias.clone=!id>/app/pontoon/base/static/img/output_rce.html` (it will redirect the output of the command `id` to `output_rce.html` that is accessible by the web app)
- set the `Public Repository Website` with a valid url (i.e `http://localhost`)
- click `Save Project`
- click `Sync`
- the output of the `id` command will be available at http://localhost:8000/static/img/output_rce.html
Actual results:
It's possible to get remote code execution via argument injection.
When creating a new project, the unsanitized user input `source` (the URL) is used in the `hg clone` command (https://github.com/mozilla/pontoon/blob/f000a47d7ff18cdae1c84b306711d34816f1db52/pontoon/sync/vcs/repositories.py#L80).
`hg` allows to define hooks or aliases:
- hooks are "Commands or Python functions that get automatically executed by various actions such as starting or finishing a commit."(https://www.mercurial-scm.org/doc/hgrc.5.html#hooks)
- "aliases allow you to define your own commands in terms of other commands (or aliases), optionally including arguments." (https://www.mercurial-scm.org/doc/hgrc.5.html#alias)
If the user controlled value (`url`) is for example `--config=alias.clone=!id` , and the shell command executed is `hg clone <user_input>`, the command `id` will be executed.
Regarding the `!` here you can find more reference (https://www.mercurial-scm.org/doc/hgrc.5.html#alias)
By following the previous steps, it was possible to execute arbitrary commands using the create new projects functionality.
Expected results:
A new project should have been created (instead of executing arbitrary commands).
I followed the SECURITY policy here https://github.com/mozilla/pontoon/blob/master/SECURITY.md to submit a security vulnerability.
Please let me know if something is not clear.
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 execute arbitrary commands on the server, leading to remote code execution.
What the attacker needed
Access to create projects; ability to trigger a sync
The fix
The application should sanitise or validate the repository URL to prevent argument injection, for example by rejecting URLs that start with a dash or by using a safe API instead of shell commands.
How it was found
- Install Pontoon locally and sign in.
- Go to the admin projects page and create a new project with a name, slug, and locale.
- In the Repositories section, select type HG and enter a crafted URL that uses hg's --config option to define an alias executing a command.
- Set a valid public repository website URL and save the project.
- Click Sync to trigger the hg clone command.
- Access the static file where the command output was redirected.
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.
When you create a project in Pontoon, you give a web address for its code repository. The program then runs a command-line tool called hg to copy that repository. Because the address is not checked, someone can put special instructions in it that make hg run other commands on the server. This lets an attacker run their own commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.