Security weaknessCWE Top 25 · #23
CWE-77 Command injection
User input ends up inside a command your server runs, letting an attacker change what that command does.
- Senior security engineers
- 540+ projects delivered
- Reply within one business day
Quick answer
What is CWE-77?
Improper Neutralization of Special Elements used in a Command: The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.
Business impact
What CWE-77 could cost your business
MITRE documents what this weakness can do. Here is what that means for a website, store or app.
Confidentiality
Private data exposed
Customer records, credentials, orders or internal files can be read by people who should never see them.
- Execute Unauthorized Code or Commands
Integrity
Data, pages or code changed
Prices, orders, content or the code your site runs can be altered without your approval.
- Execute Unauthorized Code or Commands
Availability
Downtime and lost sales
Crashes, slowdowns or exhausted resources can take your site, store or app offline.
- Execute Unauthorized Code or Commands
In plain English
What Command injection means for your business
- 540+projects delivered
- 9+years in business
- 23+certified experts
A senior engineer replies within one business day.
Websites sometimes hand work to another program. They call an image converter, a PDF generator, a backup utility or a mail tool by building a command as text and running it. Command injection happens when part of that text comes from a user and is not made safe first. Special characters in the input can end the intended command and start a different one, which the server then runs.
This is one of the most damaging weaknesses a site can have. A successful attack runs with the same permissions as your web application. That can mean reading configuration files and database passwords, changing site files, installing malicious software or using your server to attack others. It is not limited to operating system shells. Any component with its own command language, such as a mail server or a device, can be affected.
Where it shows up
- Image, video and PDF processing features that pass an uploaded file name or user-chosen option to a command-line conversion tool.
- Admin utilities for backups, imports, exports or database dumps that build a system command from form fields or URL parameters.
- Network tools on hosting panels, routers and monitoring dashboards that run ping, lookup or trace commands against a host the user types.
- Contact forms and notification scripts that send mail by calling a mail program directly, placing the sender address or subject into its arguments.
Free security check
Is CWE-77 hiding in your site?
A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.
Official definition
How MITRE defines CWE-77
Improper Neutralization of Special Elements used in a Command
The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.
Many protocols and products have their own custom command language. While OS or shell command strings are frequently discovered and targeted, developers may not realize that these other command languages might also be vulnerable to attacks.
Also known as: Command injection
Fix it
How to fix Command injection
Practical steps in priority order. Share them with your developer or agency.
Replace commands with library calls
Use your language’s built-in functions or a maintained library for image handling, archives, mail and file operations instead of starting an external program. With no command to build, there is nothing to inject into.
Pass arguments separately, without a shell
If you must run a program, call it through an API that takes the executable and an array of arguments. Never join input into one command string, and avoid functions that invoke a shell interpreter.
Keep commands fixed and allowlist values
Write the command itself as a constant in code. Let user input select only from a short list of approved values, or validate it strictly as a number or a pattern of safe characters.
Run with the least privilege
Run the web application under an account with minimal permissions, never as root or administrator. Use containers or sandboxing to limit which files, programs and network destinations a spawned process can reach.
Audit code and monitor execution
Search your code, themes and plugins for functions that execute commands and review each use. Add static analysis to your build, and alert when the web server starts unexpected processes.
Signs you may be affected
- Your code calls shell functions such as exec or system with text assembled from user input.
- Unknown files, scheduled tasks or running processes appear on the server without explanation.
- Features that convert or process files fail oddly when a file name contains punctuation.
Questions to ask your developer
- Does any part of our site run system commands or external programs?
- Is user input ever included in a command, even after filtering?
- What account does the web application run as, and what can it access?
Prevention
What MITRE recommends, phase by phase
Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.
- 01
Architecture and Design
- If at all possible, use library calls rather than external processes to recreate the desired functionality.
- 02
Implementation
- If possible, ensure that all external commands called from the program are statically created.
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of.
- 03
System Configuration
- Assign permissions that prevent the user from accessing/opening privileged files.
- 04
Operation
- Run time: Run time policy enforcement may be used in an allowlist fashion to prevent use of any non-sanctioned commands.
Detection and evidence
How CWE-77 is found, and where it has hit
The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.
How it is detected
- Automated Static AnalysisAutomated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then.
Real vulnerabilities it caused
- CVE-2026-27806Device management product allows injection of Tcl/expect commands
- CVE-2022-1509injection of sed script syntax ("sed injection")
- CVE-2024-5184ML-based email analysis product uses an API service that allows a malicious user to inject a direct prompt and take over the service logic, forcing it to leak the standard hard-coded system prompts and/or execute.
- CVE-2020-11698anti-spam product allows injection of SNMP commands into configuration file
- CVE-2019-12921image program allows injection of commands in "Magick Vector Graphics (MVG)" language.
- CVE-2022-36069Python-based dependency management tool avoids OS command injection when generating Git commands but allows injection of optional arguments with input beginning with a dash (CWE-88), potentially allowing for code.
How we fix it
From finding to fixed: how Codefreex closes CWE-77
Scan and confirm
We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.
Fix at the source
We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.
Verify the fix
We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.
Keep it fixed
Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.
Website SecurityPenetration TestingMalware Removal & Hack RepairWordPress Maintenance
Related weaknesses
Weaknesses related to CWE-77
FAQ
CWE-77: FAQs
Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.
How serious is command injection?
It is one of the most serious weaknesses, because it can let an attacker run their own commands on your server. From there they may read customer data and passwords, alter your site, install malware or move to other systems. MITRE rates the likelihood of exploitation as high. Treat any confirmed case as an emergency.
How do I prevent command injection?
The most reliable fix is to stop building commands from text. Use library functions in place of external programs. Where a program is unavoidable, pass arguments as a separate list without a shell and restrict input to approved values. Run the application with minimal permissions so that a mistake causes limited harm.
Is command injection the same as SQL injection?
They are related but different. Both happen when untrusted input is mixed into instructions for another system. SQL injection targets database queries. Command injection targets commands run by the operating system or another program. The defenses follow the same idea: keep data separate from instructions, using parameterized queries for databases and argument lists for commands.
What is CWE-77?
CWE-77, “Improper Neutralization of Special Elements used in a Command”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.
How serious is CWE-77?
MITRE rates the likelihood of exploit as High. It can affect integrity, confidentiality, availability, with impacts such as execute unauthorized code or commands. It ranks number 23 on the 2025 CWE Top 25 Most Dangerous Software Weaknesses. The real risk depends on where the weakness sits and what data or functions it exposes.
How do you prevent CWE-77?
If at all possible, use library calls rather than external processes to recreate the desired functionality. If possible, ensure that all external commands called from the program are statically created.
Can Codefreex check my site for CWE-77?
Yes. A senior engineer reviews your site, store or app for CWE-77 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.
Free security check
Find out if CWE-77 affects your site
Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.
- A senior strategist reviews your request, not a sales bot
- Clear scope, timeline and estimate within one business day
- Free 30-minute discovery call, no obligation
- NDA available on request
- Emailhello@codefreex.com
- CallUSA +1 (209) 375-3475 · India +91 790 3375 530
- Prefer to talk?Book a 30-minute call
Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.