MCP Security: How I blocked a Trojan with an 8-layer pipeline
Trojan:Win64/Lazy.PGPK!MTB) inside your MCP marketplace is a great way to wake up and realize your security is basically a screen door. It happened because of a classic typosquatting trick on GitHub—someone cloned a legit MCP server, swapped the "Download Latest Release" badge to point to a malicious zip, and my import script blindly swallowed it.The payload was a nasty staged launcher: a .cmd file triggering a .exe with an obfuscated Lua bytecode .txt file. My old audit only checked metadata (names and prompts), so it completely missed the binary payload hiding in a nested zip. As a dev who hates friction but loves stability, I spent the last two weeks building a massive defense pipeline to make sure this never happens again.
Here is the deep dive into the 8-layer security architecture I've deployed to keep our LLM agents safe.
The Defense Layers
L1.5 — Metadata Sanity Checks
This is the "cheap" layer. I run 6 rules against the skill metadata to flag red flags immediately:
Access-Control-Allow-Origin: *.L1.6 — Static Analysis & Secret Scanning
I implemented 36 rules using JS regex (avoiding the overhead of a Semgrep binary) to catch common vulnerabilities:
Pro tip: I had to fix a bug where process.env.X was triggering hardcoded key alerts. I now strip environment variable patterns before scanning.
L1.7 — Binary & Malware Detection (The "Trojan Killer")
This is the new layer specifically designed to stop the
unit.exe type of attacks. It recursively unzips everything and scans for:const BINARY_EXTENSIONS = ['.exe', '.dll', '.scr', '.msi'];
const LAUNCHER_EXTENSIONS = ['.bat', '.cmd', '.vbs', '.ps1'];I also added 8 regex patterns to catch:
start X.exe Y.txt.raw.githubusercontent.com zip links or "Download" badges.-encodedcommand with long base64 strings.eval(atob(...)) and oversized text files (>100KB) that aren't JSON.If any of these hit, the skill is instantly quarantined, scored 0, and nuked from the public catalog.
L1.8 — Malware Family Signatures
The final layer uses YARA-equivalent rules to identify 17 specific malware families, mapping them directly to MITRE ATT&CK technique IDs for better tracking.
This setup basically turns the import process into a gauntlet. If you're building an AI workflow with third-party MCP servers, please don't just trust the README—verify the binaries.
All Replies (3)
npx or similar runtime calls.