OS command injection is a technique used via a web interface in order to execute OS commands on a web server. The user supplies operating system commands through a web interface in order to execute OS commands. Any web interface that is not properly sanitized is subject to this exploit. With the ability to execute OS commands, the user can upload malicious programs or even obtain passwords.
### Identify and assess the command injection points:
* Web Forms
* URL Parameters
* Search Fields
* File Upload Inputs
* Backup and Restore Scripts
* User Management Scripts
When viewing a file in a web application, the filename is often shown in the URL. Perl allows piping data from a process into an open statement. The user can simply append the Pipe symbol `|` onto the end of the filename.
Appending a semicolon to the end of a URL for a .PHP page followed by an operating system command, will execute the command. `%3B` is URL encoded and decodes to semicolon
Consider the case of an application that contains a set of documents that you can browse from the Internet. If you fire up a personal proxy (such as ZAP or Burp Suite), you can obtain a POST HTTP like the following (`http://www.example.com/public/doc`):
In this post request, we notice how the application retrieves the public documentation. Now we can test if it is possible to add an operating system command to inject in the POST HTTP. Try the following (`http://www.example.com/public/doc`):
If the application doesn’t validate the request, we can obtain the following result:
```html
Exec Results for 'cmd.exe /c type "C:\httpd\public\doc\"Doc=Doc1.pdf+|+Dir c:\'
Output...
Il volume nell'unità C non ha etichetta.
Numero di serie Del volume: 8E3F-4B61
Directory of c:\
18/10/2006 00:27 2,675 Dir_Prog.txt
18/10/2006 00:28 3,887 Dir_ProgFile.txt
16/11/2006 10:43
Doc
11/11/2006 17:25
Documents and Settings
25/10/2006 03:11
I386
14/11/2006 18:51
h4ck3r
30/09/2005 21:40 25,934
```
In this case, we have successfully performed an **OS injection** attack.
-----
### Manual Test
* Bug Hunters Injecting specific characters (such as `;`, `&&`, `||`, `|`, `&`) at different program inputs, they check whether the operating system commands can be injected.
**Example:**
In the search form, instead of entering the ordinary text, inputs like `test; ls` or `test && whoami` and check if these commands are executed.
**Note:**
Examine unexpected responses from the server that may indicate the execution of the injected commands.
* **Using known Payloads**
Injection of values such as `$(Whoami)` or `${7*7}` in input parameters.