---
title: "CAPEC-108: Command Line Execution through SQL Injection"
url: https://radicalnotion.ai/capec/capec-108
type: capec
description: "An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL_xp_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host."
updated: 2026-06-01
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CAPEC-108: Command Line Execution through SQL Injection

- **Abstraction:** Detailed
- **Status:** Draft
- **Typical severity:** Very High
- **Likelihood of attack:** Low
- **CAPEC catalog version:** 3.9

## Description

An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL\_xp\_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.

## Execution flow

### Step 1: Explore

\[Probe for SQL Injection vulnerability\] The attacker injects SQL syntax into user-controllable data inputs to search unfiltered execution of the SQL syntax in a query.

### Step 2: Exploit

\[Achieve arbitrary command execution through SQL Injection with the MSSQL\_xp\_cmdshell directive\] The attacker leverages a SQL Injection attack to inject shell code to be executed by leveraging the xp\_cmdshell directive.

### Step 3: Exploit

\[Inject malicious data in the database\] Leverage SQL injection to inject data in the database that could later be used to achieve command injection if ever used as a command line argument

### Step 4: Exploit

\[Trigger command line execution with injected arguments\] The attacker causes execution of command line functionality which leverages previously injected database content as arguments.

## Prerequisites

- The application does not properly validate data before storing in the database
- Backend application implicitly trusts the data stored in the database
- Malicious data is used on the backend as a command line argument

## Skills required

- **High:** The attacker most likely has to be familiar with the internal functionality of the system to launch this attack. Without that knowledge, there are not many feedback mechanisms to give an attacker the indication of how to perform command injection or whether the attack is succeeding.

## Resources required

- None: No specialized resources are required to execute this type of attack.

## Consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Modify Data | - |
| Confidentiality | Read Data | - |
| Availability | Unreliable Execution | - |
| Confidentiality, Access Control, Authorization | Gain Privileges | - |
| Confidentiality, Integrity, Availability | Execute Unauthorized Commands | Run Arbitrary Code |

## Mitigations

- Disable MSSQL xp\_cmdshell directive on the database
- Properly validate the data (syntactically and semantically) before writing it to the database.
- Do not implicitly trust the data stored in the database. Re-validate it prior to usage to make sure that it is safe to use in a given context (e.g. as a command line argument).

## Example instances

SQL injection vulnerability in Cacti 0.8.6i and earlier, when register\_argc\_argv is enabled, allows remote attackers to execute arbitrary SQL commands via the (1) second or (2) third arguments to cmd.php. NOTE: this issue can be leveraged to execute arbitrary commands since the SQL query results are later used in the polling\_items array and popen function (CVE-2006-6799). Reference: https://www.cve.org/CVERecord?id=CVE-2006-6799

## Related weaknesses (CWE)

- [CWE-20](https://radicalnotion.ai/cwe/cwe-20): Improper Input Validation
- [CWE-74](https://radicalnotion.ai/cwe/cwe-74): Improper Neutralization of Special Elements in Output Used by a Downstream Component
- [CWE-78](https://radicalnotion.ai/cwe/cwe-78): Improper Neutralization of Special Elements used in an OS Command
- [CWE-89](https://radicalnotion.ai/cwe/cwe-89): Improper Neutralization of Special Elements used in an SQL Command
- [CWE-114](https://radicalnotion.ai/cwe/cwe-114): Process Control

## Related attack patterns

| Relationship | CAPEC | Name |
| --- | --- | --- |
| Parent | [CAPEC-66](https://radicalnotion.ai/capec/capec-66) | SQL Injection |
| Related | [CAPEC-110](https://radicalnotion.ai/capec/capec-110) | SQL Injection through SOAP Parameter Tampering |

## Frequently asked questions

### What is CAPEC-108?

An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL\_xp\_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.

### How does a Command Line Execution through SQL Injection attack work?

It typically unfolds over 4 phases. It begins with: \[Probe for SQL Injection vulnerability\] The attacker injects SQL syntax into user-controllable data inputs to search unfiltered execution of the SQL syntax in a query.

### How do you prevent CAPEC-108?

Disable MSSQL xp\_cmdshell directive on the database

### What weaknesses does CAPEC-108 target?

CAPEC-108 exploits 5 CWE weaknesses, including CWE-20 (Improper Input Validation), CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component), CWE-78 (Improper Neutralization of Special Elements used in an OS Command) and CWE-89 (Improper Neutralization of Special Elements used in an SQL Command).

### How severe is CAPEC-108?

MITRE rates CAPEC-108 as Very High severity with low likelihood of attack.

Primary source: [MITRE CAPEC](https://capec.mitre.org/data/definitions/108.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/capec/capec-108). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
