The Backend Behind the Agent: Seeing MCP Servers Through the Lens
The markdownify-mcp server passes unsanitised file paths from its conversion tools into a shell command, allowing an attacker to inject arbitrary OS commands. An attacker could execute commands on the host running the MCP server.
Published on medium.com
In the rapidly evolving world of AI agents and orchestration frameworks, Model Context Protocol (MCP) servers are often described as novel building blocks enabling smarter, more modular systems. Yet when we strip away the new terminology, an MCP server is fundamentally no different from a traditional backend service…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The filePath argument from tool inputs is passed unsanitised into execAsync, which runs a shell command, allowing shell metacharacters to break out and execute arbitrary commands.
Impact
An attacker could execute arbitrary system commands on the host running the MCP server, potentially compromising the entire system.
What the attacker needed
Markdownify-mcp server installed; attacker can send prompts to the MCP server
The fix
The server should sanitise input and avoid unsafe execution patterns, such as using exec with unsanitised arguments.
How it was found
- Install the markdownify MCP server and use it with Claude Desktop.
- Send a legitimate prompt to the pdf-to-markdown tool to see normal behaviour.
- Send a malicious prompt that includes shell metacharacters in the file path.
- Observe that arbitrary commands run on the MCP server's host.
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 write-up has not been written yet. The Original tab links to the source.
An MCP server is a backend service that AI agents call to perform tasks like converting files. Here, the server took a file path from the user and put it directly into a system command without cleaning it, so a malicious file path could run extra commands on the server. This is called command injection.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.