1

I am using zaproxy for automatic testing of my site. There is a P1 alert in the scan report. I dont know how to rectify this err. Can someone please help me out:-

https://example.com/index.php?id=1535&source=home&storyId=468&r=video%2Fview%22%26timeout+%2FT+5%26%22&mode=current

    Parameter

r

    Attack

video/view"&timeout /T 5&"
4

2 回答 2

2

OK, so this is a timing attack. These are prone to false positives if the server is under load.

You should always try to manually validate any potential vulnerability reported by a scanning tool, including ZAP.

In this case open the URLs referenced in your browser - did it take around 5 seconds to load? Then change the '5' on the URL to something much larger, eg '30' - did it now take 30 seconds?

If took around the same length of time then this is likely to be a false positive.

于 2016-02-09T12:21:29.120 回答
-1

Alert Detail

High (Medium) Remote OS Command Injection Description

Attack technique used for unauthorized execution of operating system commands. This attack is possible when an application accepts untrusted input to build operating system commands in an insecure manner involving improper data sanitization, and/or improper calling of external programs.

URL

https://example.com/index.php?id=1535&source=home&storyId=468&r=video%2Fview%22%26timeout+%2FT+5%26%22&mode=current

Parameter

r

Attack

video/view"&timeout /T 5&"

URL

https://example.com/index.php?id=1535&source=home&storyId=468&r=video%2Fview&mode=current%22%7Ctimeout+%2FT+5

Parameter

mode

Attack

current"|timeout /T 5

URL

https://example.com/index.php?r=site/login

Parameter

userTimeZone

Attack

&sleep 5s&

URL

https://example.com/js/tinymce/tinymce.min.js?version=1405493567%26sleep+%7B0%7Ds%26

Parameter

version

Attack

1405493567&sleep {0}s&

URL

https://example.com/themes/sharperax/css/sh-style.css?version=1454508637%22%26sleep+5s%26%22

Parameter

version

Attack

1454508637"&sleep 5s&"

Instances

5

Solution

If at all possible, use library calls rather than external processes to recreate the desired functionality.

Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by your software.

OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows you to specify restrictions on file operations.

This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise.

For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the command locally in the session's state instead of sending it out to the client in a hidden form field.

Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

For example, consider using the ESAPI Encoding control or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error.

If you need to use dynamically-generated query strings or commands in spite of the risk, properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict whitelist (such as everything that is not alphanumeric or white space). If some special characters are still needed, such as white space, wrap each argument in quotes after the escaping/filtering step. Be careful of argument injection.

If the program to be executed allows arguments to be specified within an input file or from standard input, then consider using that mode to pass arguments instead of the command line.

If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated.

Some languages offer multiple functions that can be used to invoke commands. Where possible, identify any function that invokes a command shell using a single string, and replace it with a function that requires individual arguments. These functions typically perform appropriate quoting and filtering of arguments. For example, in C, the system() function accepts a string that contains the entire command to be executed, whereas execl(), execve(), and others require an array of strings, one for each argument. In Windows, CreateProcess() only accepts one command at a time. In Perl, if system() is provided with an array of arguments, then it will quote each of the arguments.

Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a whitelist of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. Do not rely exclusively on looking for malicious or malformed inputs (i.e., do not rely on a blacklist). However, blacklists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.

When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if you are expecting colors such as "red" or "blue."

When constructing OS command strings, use stringent whitelists that limit the character set based on the expected value of the parameter in the request. This will indirectly limit the scope of an attack, but this technique is less important than proper output encoding and escaping.

Note that proper output encoding, escaping, and quoting is the most effective solution for preventing OS command injection, although input validation may provide some defense-in-depth. This is because it effectively limits what will appear in output. Input validation will not always prevent OS command injection, especially if you are required to support free-form text fields that could contain arbitrary characters. For example, when invoking a mail program, you might need to allow the subject field to contain otherwise-dangerous inputs like ";" and ">" characters, which would need to be escaped or otherwise handled. In this case, stripping the character might reduce the risk of OS command injection, but it would produce incorrect behavior because the subject field would not be recorded as the user intended. This might seem to be a minor inconvenience, but it could be more important when the program relies on well-structured subject lines in order to pass messages to other components.

Even if you make a mistake in your validation (such as forgetting one out of 100 input fields), appropriate encoding is still likely to protect you from injection-based attacks. As long as it is not done in isolation, input validation is still a useful technique, since it may significantly reduce your attack surface, allow you to detect some attacks, and provide other security benefits that proper encoding does not address.

Reference

http://cwe.mitre.org/data/definitions/78.html

https://www.owasp.org/index.php/Command_Injection

CWE Id

78

WASC Id

31

于 2016-02-08T09:23:15.757 回答