Brief Summary

In this paragraph we describe how to test an application for OS commandind testing: this means try to inject an on command throughout an HTTP request to the application.

Short Description of the Issue

OS Commanding is a technique used via a web interface in order to execute OS commands on the 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. OS commanding is preventable when security is emphasized during the design and development of applications.

Black Box testing and example

When viewing a file in a web application the file name 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.
Example URL before alteration:

http://sensitive/cgi-bin/userData.pl?doc=user1.txt

Example URL modified:

http://sensitive/cgi-bin/userData.pl?doc=/bin/ls|

This will execute the command “/bin/ls”.
Appending a semicolon to the end of a URL for a .PHP page followed by an operating system command, will execute the command.
Example:

http://sensitive/something.php?dir=%3Bcat%20/etc/passwd

Example
Consider the case of an application that contains a set of documents that you can browse from the Internet. If you fire up WebScabar, you can obtain a POST HTTP like the following:

Gray Box testing

Sanitization
The URL and form data needs to be sanitized for invalid characters. A “blacklist” of characters is an option but it may be difficult to think of all of the characters to validate against. Also there may be some that were not discovered as of yet. A “whitelist” containing only allowable characters should be created to validate the user input. Characters that were missed as well as undiscovered threats should be eliminated by this list.Permissions
The web application and its components should be running under strict permissions that do not allow operating system command execution.