Commix — Command Injection Exploiter

Aswin Chandran
6 min readAug 15, 2023

--

Introduction:

Hello Friends, In this blog, I discuss the Commix Tool, an automated tool for identifying Command Injection vulnerabilities. It offers functionality comparable to that of SQLMap.

1. What is Command Injection?

Command injection is a web security vulnerability that occurs when an attacker injects malicious commands into a software application. These commands are improperly executed by the application’s underlying system, allowing the attacker to perform unauthorized actions, access sensitive data, or even take control of the system.

The most common form of command injection involves inserting malicious commands into input fields or parameters of a web application. When the application processes this input without proper validation, it inadvertently executes the injected commands. This can lead to severe consequences, as the attacker gains the ability to manipulate the system and its data, potentially causing significant damage.

Command Injection

In essence, command injection is like tricking a software application into unintentionally running harmful instructions, much like how Cross-Site Scripting (XSS) tricks a browser into executing malicious scripts. The result can be unauthorized access or control over a system, making command injection a critical security concern that requires careful input validation and proper handling of user input.

Command injection vulnerabilities can manifest in various ways, leading to different types of exploits. Here are some common types of command injection vulnerabilities along with examples for each:

1. Basic Command Injection:

In this type, an attacker directly injects malicious commands into an application’s input fields, which are then executed by the system.

Example:

User Input: ; rm -rf /

Command Executed: ls ; rm -rf / # Deletes all files and directories

2. Blind Command Injection:

Here, the attacker doesn’t directly see the output of the injected command, but can infer its success or failure by observing the application’s behavior.

Example:

User Input: 127.0.0.1; ping -c 1 example.com

Command Executed: nslookup 127.0.0.1; ping -c 1 example.com

The attacker can see if the request to example.com is made, indicating command execution.

3. Time-Based Blind Command Injection:

Attackers inject commands that cause the application to delay its response, revealing information based on the delay.

Example:

User Input: ; sleep 10

Command Executed: ls ; sleep 10

The attacker can observe a 10-second delay in the application’s response.

4. Boolean-Based Blind Command Injection:

Attackers inject commands that rely on true/false conditions, and infer success based on application behaviour.

Example:

User Input: || ping -c 1 example.com

Command Executed: ls || ping -c 1 example.com

5. Out-of-Band Command Injection:

Attackers leverage external systems to retrieve the results of injected commands, often through DNS queries or HTTP requests.

Example:

User Input: ; nslookup malicious-site.com

Command Executed: ls ; nslookup malicious-site.com

6. Pipeline Command Injection:

Attackers chain multiple commands together using pipeline operators to execute complex actions.

Example:

User Input: | cat /etc/passwd

Command Executed: ls | cat /etc/passwd

7. Function Call Command Injection:

Attackers exploit functions within an application that indirectly execute commands.

Example:

User Input: &mail(‘attacker@example.com’)

Command Executed: &mail(‘attacker@example.com’)

2. Impact of command injection

Command injection vulnerabilities can have serious and far-reaching impacts on a system, potentially leading to unauthorized access, data breaches, system compromise, and more. The impact of a successful command injection attack depends on the context and environment in which it occurs. Here are some potential consequences:

1. Unauthorized Command Execution: Attackers can execute arbitrary commands on the target system, gaining control over its functionality and potentially compromising its security.

2. Data Leakage: Command injection can lead to unauthorized access to sensitive data, including confidential files, databases, or user credentials, which can then be exfiltrated by the attacker.

3. System Compromise: If the attacker gains full control over the system, they can manipulate its configuration, install backdoors, or perform other actions that allow them to maintain access even after the initial attack.

4. Denial of Service (DoS): Attackers might use command injection to overload system resources or execute commands that disrupt normal operations, leading to service outages and downtime.

5. Elevation of Privileges: Successful command injection can allow an attacker to escalate their privileges on the system, potentially gaining administrative or root access.

6. Propagation and Lateral Movement: Once inside a system, attackers can use command injection to move laterally through a network, compromising other interconnected systems.

7. Malware Installation: Attackers could use command injection to download and execute malicious software, such as ransomware or keyloggers.

8. Regulatory and Legal Consequences: Data breaches resulting from command injection attacks can lead to legal liabilities, regulatory penalties, and damage to an organization’s reputation.

9. Financial Loss: The fallout from a command injection attack can result in financial losses due to business disruption, remediation costs, legal actions, and potential loss of customer trust.

10.Brand Damage: Publicly disclosed command injection vulnerabilities and successful attacks can tarnish an organization’s reputation and erode customer confidence.

3. How command injection works

Command injection works by exploiting improper handling of user input in software applications, which allows an attacker to inject and execute arbitrary commands on a target system. The basic process involves the following steps:

1. User Input: The attacker identifies an input field or parameter in the application where user input is processed. This could be a search bar, login form, URL parameter, or any other input mechanism.

2. Malicious Payload Injection: The attacker enters specially crafted input that includes not only the intended user data but also malicious commands. These commands are usually separated by characters that are interpreted by the system as command delimiters, such as semicolons (;), ampersands (&), pipes (|), and more.

3. Concatenation of Input: The application, without proper input validation or sanitization, directly concatenates the user input (including the injected malicious commands) into a system command or query.

4. Command Execution: The application’s backend processes the concatenated input and executes it as a system command. This can be a shell command (in the case of command-line applications) or a database query (in the case of SQL injection with command execution).

4. Commix

Commix Tool

Description:

Commix is a powerful open-source penetration testing tool specifically designed to streamline the process of identifying and exploiting command injection vulnerabilities within web-based applications. Created by Anastasios Stasinopoulos, commix serves as a valuable asset for web developers, penetration testers, and security researchers seeking to enhance the security of their applications by uncovering and rectifying potential weaknesses associated with command injection attacks.

Features and advantages of Commix

1. Automated Exploitation: Commix automates the process of detecting and exploiting command injection vulnerabilities in web applications.

2. Real-World Scenarios: Commix-testbed provides a collection of real-world scenarios intentionally made vulnerable to command injection flaws. This aids in evaluating Commixes detection and exploitation capabilities.

3. Custom Modules Development: Users can extend Commixes functionality by developing and importing their own modules, allowing for adaptation to specific testing needs.

4. User-Friendly Interface: Commix offers an easy-to-use interface that simplifies the process of testing web applications for command injection vulnerabilities.

5. Thorough Testing: Commix provides a wide range of options and switches to thoroughly test various parameters and headers, ensuring comprehensive vulnerability assessment.

6. Efficiency: Commix’s automation significantly reduces the time required to identify and exploit command injection vulnerabilities.

7. Accurate Vulnerability Detection: Commix’s features enhance the accuracy of vulnerability detection, reducing false positives.

8. Cost-Effective: Using Commix can help organizations avoid potential security breaches and associated financial losses.

Installation

Step 1: Run the following command to install Commix

$ git clone https://github.com/commixproject/commix.git
$ cd commix

Commix Installation

Step 2: Now run the following command to use commix

$ python3 commix.py -u URL

Commix Usage

Conclusion

Thank you for reading my blog. I would love to hear your feedback and suggestions to improve future posts. Stay tuned for more cybersecurity insights!

References

https://portswigger.net/web-security/os-command-injection

https://owasp.org/www-community/attacks/Command_Injection

https://github.com/commixproject/commix.git

--

--

Aswin Chandran

Certified Ethical Hacker | Cybersecurity Researcher | RedTeam | Penetration Tester | Helped Secure Facebook