<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marius+Quadflieg</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marius+Quadflieg"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Marius_Quadflieg"/>
		<updated>2026-04-25T09:54:49Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Marius_Quadflieg&amp;diff=35283</id>
		<title>User:Marius Quadflieg</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Marius_Quadflieg&amp;diff=35283"/>
				<updated>2008-08-04T12:56:21Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;IT Compliance Management - MGI METRO Group Information Technology GmbH&lt;br /&gt;
&lt;br /&gt;
Software Engineering Student - Fontys Hogeschool Venlo (NL)&lt;br /&gt;
&lt;br /&gt;
'''Blog:''' [http://www.portal4gamers.de www.portal4gamers.de]&lt;br /&gt;
&lt;br /&gt;
'''Email:''' marius at quadflieg dot name&lt;br /&gt;
&lt;br /&gt;
'''PGP Key:''' [http://pgp.mit.edu:11371/pks/lookup?search=0xD8168DB7&amp;amp;op=index 0xD8168DB7]&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Information_Leakage_and_Improper_Error_Handling&amp;diff=26484</id>
		<title>Top 10 2007-Information Leakage and Improper Error Handling</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Information_Leakage_and_Improper_Error_Handling&amp;diff=26484"/>
				<updated>2008-03-10T09:37:43Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: /* Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applications can unintentionally leak information about their configuration, internal workings, or violate privacy through a variety of application problems. Applications can also leak internal state via how long they take to process certain operations or via different responses to differing inputs, such as displaying the same error text with different error numbers. Web applications will often leak information about their internal state through detailed or debug error messages. Often, this information can be leveraged to launch or even automate more powerful attacks.&lt;br /&gt;
&lt;br /&gt;
== Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All web application frameworks are vulnerable to information leakage and improper error handling. &lt;br /&gt;
&lt;br /&gt;
== Vulnerability ==&lt;br /&gt;
&lt;br /&gt;
Applications frequently generate error messages and display them to users. Many times these error messages are quite useful to attackers, as they reveal implementation details or information that is useful in exploiting a vulnerability. There are several common examples of this:&lt;br /&gt;
&lt;br /&gt;
*Detailed error handling, where inducing an error displays too much information, such as stack traces, failed SQL statements, or other debugging information&lt;br /&gt;
*Functions that produce different results based upon different inputs. For example, supplying the same username but different passwords to a login function should produce the same text for no such user, and bad password. However, many systems produce different error codes&lt;br /&gt;
&lt;br /&gt;
== Verifying Security ==&lt;br /&gt;
&lt;br /&gt;
The goal is to verify that the application does not leak information via error messages or other means.&lt;br /&gt;
&lt;br /&gt;
Automated approaches: Vulnerability scanning tools will usually cause error messages to be generated. Static analysis tools can search for the use of APIs that leak information, but will not be able to verify the meaning of those messages. &lt;br /&gt;
&lt;br /&gt;
Manual approaches: A code review can search for improper error handling and other patterns that leak information, but it is time-consuming. Testing will also generate error messages, but knowing what error paths were covered is a challenge.&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
Developers should use tools like OWASP's WebScarab to try to make their application generate errors. Applications that have not been tested in this way will almost certainly generate unexpected error output. Applications should also include a standard exception handling architecture to prevent unwanted information from leaking to attackers. &lt;br /&gt;
&lt;br /&gt;
Preventing information leakage requires discipline. The following practices have proven effective:&lt;br /&gt;
&lt;br /&gt;
*'''Ensure that the entire software development team shares a''' '''common approach to exception handling'''.&lt;br /&gt;
*'''Disable or limit detailed error handling'''. In particular, do not display debug information to end users, stack traces, or path information.&lt;br /&gt;
*'''Ensure that secure paths that have multiple outcomes return similar or identical error messages''' in roughly the same time. If this is not possible, consider imposing a random wait time for all transactions to hide this detail from the attacker.&lt;br /&gt;
*Various layers may return fatal or exceptional results, such as the database layer, the underlying web server (IIS, Apache, etc). It is vital that '''errors from all these layers are adequately checked and configured to prevent error messages from being exploited by intruders'''.&lt;br /&gt;
*Be aware that common frameworks return different HTTP error codes depending on if the error is within your custom code or within the framework’s code. '''It is worthwhile creating a default error handler which returns an appropriately sanitized error message for most users in production for all error paths'''.&lt;br /&gt;
*Overriding - Although security through obscurity, choosing to override the default error handler so that it always returns “200” (OK) error screens reduces the ability of automated scanning tools from determining if a serious error occurred. While this is “security through obscurity,” it can provide an extra layer of defense.&lt;br /&gt;
*Some larger organizations have chosen to include random / unique error codes amongst all their applications. This can assist the help desk with finding the correct solution for a particular error, but it may also allow attackers to determine exactly which path an application failed.&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4899 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4899] &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3389 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3389] &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0580 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0580] &lt;br /&gt;
&lt;br /&gt;
== Related Articles ==&lt;br /&gt;
* [[Error Handling]]&lt;br /&gt;
* [[:Category:Sensitive Data Protection Vulnerability]]&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*CWE: CWE-200 (Information Leak), CWE-203 (Discrepancy Information Leak), CWE-215 (Information Leak Through Debug Information), CWE-209 (Error Message Information Leak), others. &lt;br /&gt;
*WASC Threat Classification: &lt;br /&gt;
**[http://www.webappsec.org/projects/threat/classes/information_leakage.shtml http://www.webappsec.org/projects/threat/classes/information_leakage.shtml] &lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Malicious_File_Execution&amp;diff=25997</id>
		<title>Top 10 2007-Malicious File Execution</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Malicious_File_Execution&amp;diff=25997"/>
				<updated>2008-02-26T11:57:15Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: /* Protection */ Changed gramatical structure and added a space between two words&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Insecure Direct Object Reference|useprev=PrevLink|prev=-Injection Flaws|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
Malicious file execution vulnerabilities are found in many applications. Developers will often directly use or concatenate potentially hostile input with file or stream functions, or improperly trust input files. On many platforms, frameworks allow the use of external object references, such as URLs or file system references. When the data is insufficiently checked, this can lead to arbitrary remote and hostile content being included, processed or invoked by the web server. &lt;br /&gt;
&lt;br /&gt;
This allows attackers to perform:&lt;br /&gt;
&lt;br /&gt;
*Remote code execution&lt;br /&gt;
*Remote root kit installation and complete system compromise&lt;br /&gt;
*On Windows, internal system compromise may be possible through the use of PHP’s SMB file wrappers &lt;br /&gt;
This attack is particularly prevalent on PHP, and extreme care must be taken with any stream or file function to ensure that user supplied input does not influence file names.&lt;br /&gt;
&lt;br /&gt;
== Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All web application frameworks are vulnerable to malicious file execution if they accept filenames or files from the user. Typical examples include: .NET assemblies which allow URL file name arguments, or code which accepts the user’s choice of filename to include local files.&lt;br /&gt;
&lt;br /&gt;
'''PHP is particularly vulnerable''' to remote file include (RFI) attack through parameter tampering with any file or streams based API.&lt;br /&gt;
&lt;br /&gt;
== Vulnerability ==&lt;br /&gt;
&lt;br /&gt;
A common vulnerable construct is:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;include $_REQUEST['filename’];&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Not only does this allow evaluation of remote hostile scripts, it can be used to access local file servers (if PHP is hosted upon Windows) due to SMB support in PHP’s file system wrappers.&lt;br /&gt;
&lt;br /&gt;
Other methods of attack include:&lt;br /&gt;
&lt;br /&gt;
*Hostile data being uploaded to session files, log data, and via image uploads (typical of forum software)&lt;br /&gt;
*Using compression or audio streams, such as zlib:// or ogg:// which do not inspect the internal PHP URL flag and thus allow access to remote resources even if allow_url_fopen or allow_url_include is disabled&lt;br /&gt;
*Using PHP wrappers, such as php://input and others to take input from the request POST data rather than a file&lt;br /&gt;
*Using PHP’s data: wrapper, such as &amp;lt;code&amp;gt;data:;base64,PD9waHAgcGhwaW5mbygpOz8+&amp;lt;/code&amp;gt;&lt;br /&gt;
As this list is extensive (and periodically changes), it is vital to use a properly designed security architecture and robust design when dealing with user supplied inputs influencing the choice of server side filenames and access.&lt;br /&gt;
&lt;br /&gt;
Although PHP examples have been given, this attack is also applicable in different ways to .NET and J2EE. Applications written in those frameworks need to pay particular attention to code access security mechanisms to ensure that filenames supplied by or influenced by the user do not allow security controls to be obviated.&lt;br /&gt;
&lt;br /&gt;
For example, it is possible that XML documents submitted by an attacker will have a hostile DTD that forces the XML parser to load a remote DTD, and parse and process the results. An Australian security firm has demonstrated this approach to port scanning behind firewalls. See [SIF01] in this chapter’s references for more information. &lt;br /&gt;
&lt;br /&gt;
The damage this particular vulnerability causes is directly related to the strength of the sandbox / platform isolation controls in the framework. As PHP is rarely isolated and has no sandbox concept or security architecture, the damage is far worse for an attack than other platforms with limited or partial trust, or are contained within a suitable sand box, such as when a web app is running under a JVM with the security manager properly enabled and configured (which is rarely the default). &lt;br /&gt;
&lt;br /&gt;
== Verifying Security ==&lt;br /&gt;
&lt;br /&gt;
Automated approaches: Vulnerability scanning tools will have difficulty identifying the parameters that are used in a file include or the syntax for making them work. Static analysis tools can search for the use of dangerous APIs, but cannot verify that appropriate validation or encoding might be in place to protect against the vulnerability.&lt;br /&gt;
&lt;br /&gt;
Manual approaches: A code review can search for code that might allow a file to be included in the application, but there are many possible mistakes to recognize. Testing can also detect these vulnerabilities, but identifying the particular parameters and the right syntax can be difficult.&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
Preventing remote file include flaws takes some careful planning at the architectural and design phases, through to thorough testing. In general, a well-written application will not use user-supplied input in any filename for any server-based resource (such as images, XML and XSL transform documents, or script inclusions), and will have firewall rules in place preventing new outbound connections to the Internet or internally back to any other server. However, many legacy applications will continue to have a need to accept user supplied input. &lt;br /&gt;
&lt;br /&gt;
Among the most important considerations are:&lt;br /&gt;
&lt;br /&gt;
*'''Use an indirect object reference map''' (see section A4 for more details). For example, where a partial filename was once used, consider a hash of the partial reference. Instead of :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;amp;lt;select name=”language”&amp;amp;gt;&lt;br /&gt;
    &amp;amp;lt;option value=”English”&amp;amp;gt;English&amp;amp;lt;/option&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
use&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;amp;lt;select name=”language”&amp;amp;gt;&lt;br /&gt;
    &amp;amp;lt;option value=”78463a384a5aa4fad5fa73e2f506ecfc”&amp;amp;gt;English&amp;amp;lt;/option&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Consider using salts to prevent brute forcing of the indirect object reference. Alternatively, just use index values such as 1, 2, 3, and ensure that the array bounds are checked to detect parameter tampering.3. &lt;br /&gt;
&lt;br /&gt;
*'''Use explicit taint checking mechanisms''', if your language supports it. Otherwise, consider a variable naming scheme to assist with taint checking:&lt;br /&gt;
 &amp;lt;code&amp;gt;$hostile = &amp;amp;$_POST; // refer to POST variables, not $_REQUEST&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;$safe[‘filename’]= validate_file_name($hostile[‘unsafe_filename’]); // make it safe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore any operation based upon hostile input is immediately obvious:&lt;br /&gt;
 &amp;lt;code&amp;gt;WRONG: &amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;require_once($_POST[‘unsafe_filename’] . ‘inc.php’);&amp;lt;/span&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt;RIGHT: require_once($safe[‘filename’] . ‘inc.php’);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Strongly validate user''' input using &amp;quot;accept known good&amp;quot; as a strategy&lt;br /&gt;
*'''Add firewall''' rules to prevent web servers making new connections to external web sites and internal systems. For high value systems, isolate the web server in its own VLAN or private subnet &lt;br /&gt;
*'''Check any user supplied files or filenames''' taken from the user for legitimate purposes, which cannot obviate other controls. Otherwise be obviated, tainting could include user supplied data in the session object, avatars and images, PDF reports, temporary files, and so on&lt;br /&gt;
*'''Consider implementing a chroot jail '''or other sand box mechanisms such as virtualization to isolate applications from each other&lt;br /&gt;
*'''PHP:''' '''Disable allow_url_fopen and allow_url_include''' in php.ini and consider building PHP locally to not include this functionality. Very few applications need this functionality and thus these settings should be enabled on a per application basis&lt;br /&gt;
*'''PHP: Disable register_globals and use E_STRICT to find uninitialized variables'''&lt;br /&gt;
*'''PHP: Ensure that all file and streams functions (stream_*)''' '''are carefully vetted'''. Ensure that the user input is not supplied any function which takes a filename argument, including:&lt;br /&gt;
&amp;lt;code&amp;gt;include() include_once() require() require_once() fopen() imagecreatefromXXX() file() file_get_contents() copy() delete() unlink() upload_tmp_dir() $_FILES move_uploaded_file()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*PHP: Be extremely cautious if data is passed to system() eval() passthru() or ` (the backtick operator).&lt;br /&gt;
*With J2EE, ensure that the security manager is enabled and properly configured and that the application is demanding permissions appropriately&lt;br /&gt;
*With ASP.NET, please refer to the documentation on partial trust, and design your applications to be segmented in trust, so that most of the application exists in the lowest possible trust state possible&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0360 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0360]&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5220 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5220]    &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4722 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4722] &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*CWE: CWE-98 (PHP File Inclusion), CWE-78 (OS Command Injection), CWE-95 (Eval injection), CWE-434 (Unrestricted file upload)&lt;br /&gt;
*WASC Threat Classification: &lt;br /&gt;
[http://www.webappsec.org/projects/threat/classes/os_commanding.shtml http://www.webappsec.org/projects/threat/classes/os_commanding.shtml] http://www.webappsec.org/projects/threat/classes/os_commanding.shtml&lt;br /&gt;
*OWASP Guide, [http://www.owasp.org/index.php/File_System http://www.owasp.org/index.php/File_System#Includes_and_Remote_files] &lt;br /&gt;
*OWASP Testing Guide, [http://www.owasp.org/index.php/Testing_for_Directory_Traversal http://www.owasp.org/index.php/Testing_for_Directory_Traversal] &lt;br /&gt;
*OWASP PHP Top 5, [http://www.owasp.org/index.php/PHP_Top_5 http://www.owasp.org/index.php/PHP_Top_5#P1:_Remote_Code_Execution] &lt;br /&gt;
*Stefan Esser,&lt;br /&gt;
[http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html] &lt;br /&gt;
*[SIF01] SIFT,Sift Networks, Web Services: Teaching an old dog new tricks, [http://www.ruxcon.org.au/files/2006/web_services_security.ppt http://www.ruxcon.org.au/files/2006/web_services_security.ppt] &lt;br /&gt;
*[http://www.owasp.org/index.php/OWASP_Java_Table_of_Contents http://www.owasp.org/index.php/OWASP_Java_Table_of_Contents#Defining_a_Java_Security_Policy] &lt;br /&gt;
*Microsoft - Programming for Partial Trust, [http://msdn2.microsoft.com/en-us/library/ms364059(VS.80).aspx http://msdn2.microsoft.com/en-us/library/ms364059(VS.80).aspx] &lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Insecure Direct Object Reference|useprev=PrevLink|prev=-Injection Flaws|usemain=MainLink|main=}}&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Malicious_File_Execution&amp;diff=25996</id>
		<title>Top 10 2007-Malicious File Execution</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Malicious_File_Execution&amp;diff=25996"/>
				<updated>2008-02-26T11:34:44Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: /* Protection */ removed double word&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Insecure Direct Object Reference|useprev=PrevLink|prev=-Injection Flaws|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
Malicious file execution vulnerabilities are found in many applications. Developers will often directly use or concatenate potentially hostile input with file or stream functions, or improperly trust input files. On many platforms, frameworks allow the use of external object references, such as URLs or file system references. When the data is insufficiently checked, this can lead to arbitrary remote and hostile content being included, processed or invoked by the web server. &lt;br /&gt;
&lt;br /&gt;
This allows attackers to perform:&lt;br /&gt;
&lt;br /&gt;
*Remote code execution&lt;br /&gt;
*Remote root kit installation and complete system compromise&lt;br /&gt;
*On Windows, internal system compromise may be possible through the use of PHP’s SMB file wrappers &lt;br /&gt;
This attack is particularly prevalent on PHP, and extreme care must be taken with any stream or file function to ensure that user supplied input does not influence file names.&lt;br /&gt;
&lt;br /&gt;
== Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All web application frameworks are vulnerable to malicious file execution if they accept filenames or files from the user. Typical examples include: .NET assemblies which allow URL file name arguments, or code which accepts the user’s choice of filename to include local files.&lt;br /&gt;
&lt;br /&gt;
'''PHP is particularly vulnerable''' to remote file include (RFI) attack through parameter tampering with any file or streams based API.&lt;br /&gt;
&lt;br /&gt;
== Vulnerability ==&lt;br /&gt;
&lt;br /&gt;
A common vulnerable construct is:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;include $_REQUEST['filename’];&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Not only does this allow evaluation of remote hostile scripts, it can be used to access local file servers (if PHP is hosted upon Windows) due to SMB support in PHP’s file system wrappers.&lt;br /&gt;
&lt;br /&gt;
Other methods of attack include:&lt;br /&gt;
&lt;br /&gt;
*Hostile data being uploaded to session files, log data, and via image uploads (typical of forum software)&lt;br /&gt;
*Using compression or audio streams, such as zlib:// or ogg:// which do not inspect the internal PHP URL flag and thus allow access to remote resources even if allow_url_fopen or allow_url_include is disabled&lt;br /&gt;
*Using PHP wrappers, such as php://input and others to take input from the request POST data rather than a file&lt;br /&gt;
*Using PHP’s data: wrapper, such as &amp;lt;code&amp;gt;data:;base64,PD9waHAgcGhwaW5mbygpOz8+&amp;lt;/code&amp;gt;&lt;br /&gt;
As this list is extensive (and periodically changes), it is vital to use a properly designed security architecture and robust design when dealing with user supplied inputs influencing the choice of server side filenames and access.&lt;br /&gt;
&lt;br /&gt;
Although PHP examples have been given, this attack is also applicable in different ways to .NET and J2EE. Applications written in those frameworks need to pay particular attention to code access security mechanisms to ensure that filenames supplied by or influenced by the user do not allow security controls to be obviated.&lt;br /&gt;
&lt;br /&gt;
For example, it is possible that XML documents submitted by an attacker will have a hostile DTD that forces the XML parser to load a remote DTD, and parse and process the results. An Australian security firm has demonstrated this approach to port scanning behind firewalls. See [SIF01] in this chapter’s references for more information. &lt;br /&gt;
&lt;br /&gt;
The damage this particular vulnerability causes is directly related to the strength of the sandbox / platform isolation controls in the framework. As PHP is rarely isolated and has no sandbox concept or security architecture, the damage is far worse for an attack than other platforms with limited or partial trust, or are contained within a suitable sand box, such as when a web app is running under a JVM with the security manager properly enabled and configured (which is rarely the default). &lt;br /&gt;
&lt;br /&gt;
== Verifying Security ==&lt;br /&gt;
&lt;br /&gt;
Automated approaches: Vulnerability scanning tools will have difficulty identifying the parameters that are used in a file include or the syntax for making them work. Static analysis tools can search for the use of dangerous APIs, but cannot verify that appropriate validation or encoding might be in place to protect against the vulnerability.&lt;br /&gt;
&lt;br /&gt;
Manual approaches: A code review can search for code that might allow a file to be included in the application, but there are many possible mistakes to recognize. Testing can also detect these vulnerabilities, but identifying the particular parameters and the right syntax can be difficult.&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
Preventing remote file include flaws takes some careful planning at the architectural and design phases, through to thorough testing. In general, a well-written application will not use user-supplied input in any filename for any server-based resource (such as images, XML and XSL transform documents, or script inclusions), and will have firewall rules in place preventing new outbound connections to the Internet or internally back to any other server. However, many legacy applications will continue to have a need to accept user supplied input. &lt;br /&gt;
&lt;br /&gt;
Among the most important considerations are:&lt;br /&gt;
&lt;br /&gt;
*'''Use an indirect object reference map''' (see section A4 for more details). For example, where a partial filename was once used, consider a hash of the partial reference. Instead of :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;amp;lt;select name=”language”&amp;amp;gt;&lt;br /&gt;
    &amp;amp;lt;option value=”English”&amp;amp;gt;English&amp;amp;lt;/option&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
use&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;amp;lt;select name=”language”&amp;amp;gt;&lt;br /&gt;
    &amp;amp;lt;option value=”78463a384a5aa4fad5fa73e2f506ecfc”&amp;amp;gt;English&amp;amp;lt;/option&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Consider using salts to prevent brute forcing of the indirect object reference. Alternatively, just use index values such as 1, 2, 3, and ensure that the array bounds are checked to detect parameter tampering.3. &lt;br /&gt;
&lt;br /&gt;
*'''Use explicit taint checking mechanisms''', if your language supports it. Otherwise, consider a variable naming scheme to assist with taint checking:&lt;br /&gt;
 &amp;lt;code&amp;gt;$hostile = &amp;amp;$_POST; // refer to POST variables, not $_REQUEST&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;$safe[‘filename’]= validate_file_name($hostile[‘unsafe_filename’]); // make it safe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore any operation based upon hostile input is immediately obvious:&lt;br /&gt;
 &amp;lt;code&amp;gt;WRONG: &amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;require_once($_POST[‘unsafe_filename’] . ‘inc.php’);&amp;lt;/span&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt;RIGHT: require_once($safe[‘filename’] . ‘inc.php’);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Strongly validate user''' input using &amp;quot;accept known good&amp;quot; as a strategy&lt;br /&gt;
*'''Add firewall''' rules to prevent web servers making new connections to external web sites and internal systems. For high value systems, isolate the web server in its own VLAN or private subnet &lt;br /&gt;
*'''Check user supplied that any files or filenames'''taken from the user for legitimate purposes cannot obviate other controls,be otherwise obviated, such as tainting including user supplied data in the session object, avatars and images, PDF reports, temporary files, and so on&lt;br /&gt;
*'''Consider implementing a chroot jail '''or other sand box mechanisms such as virtualization to isolate applications from each other&lt;br /&gt;
*'''PHP:''' '''Disable allow_url_fopen and allow_url_include''' in php.ini and consider building PHP locally to not include this functionality. Very few applications need this functionality and thus these settings should be enabled on a per application basis&lt;br /&gt;
*'''PHP: Disable register_globals and use E_STRICT to find uninitialized variables'''&lt;br /&gt;
*'''PHP: Ensure that all file and streams functions (stream_*)''' '''are carefully vetted'''. Ensure that the user input is not supplied any function which takes a filename argument, including:&lt;br /&gt;
&amp;lt;code&amp;gt;include() include_once() require() require_once() fopen() imagecreatefromXXX() file() file_get_contents() copy() delete() unlink() upload_tmp_dir() $_FILES move_uploaded_file()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*PHP: Be extremely cautious if data is passed to system() eval() passthru() or ` (the backtick operator).&lt;br /&gt;
*With J2EE, ensure that the security manager is enabled and properly configured and that the application is demanding permissions appropriately&lt;br /&gt;
*With ASP.NET, please refer to the documentation on partial trust, and design your applications to be segmented in trust, so that most of the application exists in the lowest possible trust state possible&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0360 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0360]&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5220 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5220]    &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4722 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4722] &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*CWE: CWE-98 (PHP File Inclusion), CWE-78 (OS Command Injection), CWE-95 (Eval injection), CWE-434 (Unrestricted file upload)&lt;br /&gt;
*WASC Threat Classification: &lt;br /&gt;
[http://www.webappsec.org/projects/threat/classes/os_commanding.shtml http://www.webappsec.org/projects/threat/classes/os_commanding.shtml] http://www.webappsec.org/projects/threat/classes/os_commanding.shtml&lt;br /&gt;
*OWASP Guide, [http://www.owasp.org/index.php/File_System http://www.owasp.org/index.php/File_System#Includes_and_Remote_files] &lt;br /&gt;
*OWASP Testing Guide, [http://www.owasp.org/index.php/Testing_for_Directory_Traversal http://www.owasp.org/index.php/Testing_for_Directory_Traversal] &lt;br /&gt;
*OWASP PHP Top 5, [http://www.owasp.org/index.php/PHP_Top_5 http://www.owasp.org/index.php/PHP_Top_5#P1:_Remote_Code_Execution] &lt;br /&gt;
*Stefan Esser,&lt;br /&gt;
[http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html] &lt;br /&gt;
*[SIF01] SIFT,Sift Networks, Web Services: Teaching an old dog new tricks, [http://www.ruxcon.org.au/files/2006/web_services_security.ppt http://www.ruxcon.org.au/files/2006/web_services_security.ppt] &lt;br /&gt;
*[http://www.owasp.org/index.php/OWASP_Java_Table_of_Contents http://www.owasp.org/index.php/OWASP_Java_Table_of_Contents#Defining_a_Java_Security_Policy] &lt;br /&gt;
*Microsoft - Programming for Partial Trust, [http://msdn2.microsoft.com/en-us/library/ms364059(VS.80).aspx http://msdn2.microsoft.com/en-us/library/ms364059(VS.80).aspx] &lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Insecure Direct Object Reference|useprev=PrevLink|prev=-Injection Flaws|usemain=MainLink|main=}}&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Marius_Quadflieg&amp;diff=25944</id>
		<title>User:Marius Quadflieg</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Marius_Quadflieg&amp;diff=25944"/>
				<updated>2008-02-25T10:54:54Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: New page: Software Engineering Student - Fontys Hogeschool Venlo (NL)  '''Blog:''' [http://www.portal4gamers.de www.portal4gamers.de]  '''Email:''' marius at quadflieg dot name  '''PGP Key:''' [http...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Software Engineering Student - Fontys Hogeschool Venlo (NL)&lt;br /&gt;
&lt;br /&gt;
'''Blog:''' [http://www.portal4gamers.de www.portal4gamers.de]&lt;br /&gt;
&lt;br /&gt;
'''Email:''' marius at quadflieg dot name&lt;br /&gt;
&lt;br /&gt;
'''PGP Key:''' [http://pgp.mit.edu:11371/pks/lookup?search=0xD8168DB7&amp;amp;op=index 0xD8168DB7]&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=25943</id>
		<title>Testing for SQL Injection (OTG-INPVAL-005)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=25943"/>
				<updated>2008-02-25T10:50:09Z</updated>
		
		<summary type="html">&lt;p&gt;Marius Quadflieg: Fixed a spelling error&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[http://www.owasp.org/index.php/Web_Application_Penetration_Testing_AoC Up]]&amp;lt;br&amp;gt;&lt;br /&gt;
{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
An [[SQL Injection]] attack consists of insertion or &amp;quot;injection&amp;quot; of an SQL query via the input data from the client to the application.&amp;lt;BR&amp;gt; &lt;br /&gt;
A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such shutdown the DBMS), recover the content of a given file present on the DBMS filesystem and in some cases issue commands to the operating system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Description of the Issue ==&lt;br /&gt;
SQL Injection attacks can be divided into the following three classes:&lt;br /&gt;
* Inband: data is extracted using the same channel that is used to inject the SQL code. This is the most straightforward kind of attack, in which the retrieved data is presented directly in the application web page&lt;br /&gt;
* Out-of-band: data is retrieved using a different channel (e.g.: an email with the results of the query is generated and sent to the tester)&lt;br /&gt;
* Inferential: there is no actual transfer of data, but the tester is able to reconstruct the information by sending particular requests and observing the resulting behaviour of the DB Server.&lt;br /&gt;
&lt;br /&gt;
Independent of the attack class, a successful SQL Injection attack requires the attacker to craft a syntactically correct SQL Query. If the application returns an error message generated by an incorrect query, then it is easy to reconstruct the logic of the original query and therefore understand how to perform the injection correctly. However, if the application hides the error details, then the tester must be able to reverse engineer the logic of the original query. The latter case is known as &amp;quot;[[Blind SQL Injection]]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==  Black Box testing and example == &lt;br /&gt;
&lt;br /&gt;
=== SQL Injection Detection ===&lt;br /&gt;
&lt;br /&gt;
The first step in this test is to understand when our application connects to a DB Server in order to access some data. Typical examples of cases when an application needs to talk to a DB include:&lt;br /&gt;
* Authentication forms: when authentication is performed using a web form, chances are that the user credentials are checked against a database that contains all usernames and passwords (or, better, password hashes)&lt;br /&gt;
* Search engines: the string submitted by the user could be used in a SQL query that extracts all relevant records from a database&lt;br /&gt;
* E-Commerce sites: the products and their characteristics (price, description, availability, ...) are very likely to be stored in a relational database.&lt;br /&gt;
The tester has to make a list of all input fields whose values could be used in crafting a SQL query, including the hidden fields of POST requests and then test them separately, trying to interfere with the query and to generate an error.&lt;br /&gt;
The very first test usually consists of adding a single quote (') or a semicolon (;) to the field under test. The first is used in SQL as a string terminator and, if not filtered by the application, would lead to an incorrect query. The second is used to end a SQL statement and, if it is not filtered, it is also likely to generate an error. &lt;br /&gt;
The output of a vulnerable field might resemble the following (on a Microsoft SQL Server, in this case):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'&lt;br /&gt;
[Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark before the &lt;br /&gt;
character string ''.&lt;br /&gt;
/target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also comments (--) and other SQL keywords like 'AND' and 'OR' can be used to try to modify the query. A very simple but sometimes still effective technique is simply to insert a string where a number is expected, as an error like the following might be generated:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Microsoft OLE DB Provider for ODBC Drivers error '80040e07'&lt;br /&gt;
 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the&lt;br /&gt;
 varchar value 'test' to a column of data type int.&lt;br /&gt;
 /target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A full error message like the ones in the examples provides a wealth of information to the tester in order to mount a successful injection. However, applications often do not provide so much detail: a simple '500 Server Error' or a custom error page might be issued, meaning that we need to use blind injection techniques.&lt;br /&gt;
In any case, it is very important to test *each field separately*: only one variable must vary while all the other remain constant, in order to precisely understand which parameters are vulnerable and which are not.&lt;br /&gt;
&lt;br /&gt;
=== Standard SQL Injection Testing ===&lt;br /&gt;
&lt;br /&gt;
Consider the following SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE Username='$username' AND Password='$password' &lt;br /&gt;
&lt;br /&gt;
A similar query is generally used from the web application in order to authenticate a user. If the query returns a value it means that inside the database a user with that credentials exists, then the user is allowed to login to the system, otherwise the access is denied.&lt;br /&gt;
The values of the input fields are inserted from the user generally through a web form. &lt;br /&gt;
We suppose to insert the following Username and Password values: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1&lt;br /&gt;
 $password = 1' or '1' = '1&lt;br /&gt;
&lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;SELECT * FROM Users WHERE Username= '1' OR '1' = '1' AND Password= '1' OR '1' = '1'&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
If we suppose that the values of the parameters are sent to the server through the GET method, and if the domain of the vulnerable web site is www.example.com, the request that we'll carry out will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1&amp;amp;password=1'%20or%20'1'%20=%20'1 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After a short analysis we notice that the query return a value (or a set of values) because the  condition is always true (OR 1=1). In this way the system has authenticated the user without knowing the username and password.&amp;lt;BR&amp;gt; ''In some systems the first row of a user table would be an administrator user. This may be the profile returned in some cases.''&lt;br /&gt;
Another example of query is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='$username') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
In this case, there are two problems, one due to the use of the parenthesis and one due to the use of MD5 hash function. &lt;br /&gt;
First of all we resolve the problem of the parenthesis. &lt;br /&gt;
That simply consist of adding a number of closing parenthesis until we obtain a corrected query. To resolve the second problem we try to invalidate the second condition.&lt;br /&gt;
We add to our query a final symbol that means that a comment is beginning. In this way everything that follows such symbol is considered as a comment.&lt;br /&gt;
Every DBMS has the own symbols of comment, however a common symbol to the greater part of the database is /*. In Oracle the symbol is &amp;quot;--&amp;quot;.&lt;br /&gt;
Saying this, the values that we'll use as Username and Password are: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1'))/*&lt;br /&gt;
 $password = foo&lt;br /&gt;
&lt;br /&gt;
In this way we'll get the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='1' or '1' = '1'))/*') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
The url request will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which return a number of values. Sometimes, the authentication code verifies that the number of returned tuple is exactly equal to 1. In the previous examples, this situation would be difficult (in the database there is only one value per user). &lt;br /&gt;
In order to go around to this problem, it is enough to insert a SQL command, that imposes the condition that the number of the returned tuple must be one. (One record returned)&lt;br /&gt;
In order to reach this goal, we use the command &amp;quot;LIMIT &amp;lt;num&amp;gt;&amp;quot;, where &amp;lt;num&amp;gt; is the number of the tuples that we expect to be returned. The value of the fields Username and Password regarding the previous example will be modified according the following:&lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1')) LIMIT 1/* &lt;br /&gt;
 $password = foo &lt;br /&gt;
&lt;br /&gt;
In this way we create a request like the follow:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))%20LIMIT%201/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Union Query SQL Injection Testing ===&lt;br /&gt;
Another test to carry out, involves the use of the UNION operation. Through such operation it is possible, in case of SQL Injection, to join a query, purposely forged from the tester, to the original query. The result of the forged query will be joined to the result of the original query, allowing the tester to obtain the values of fields of other tables.&lt;br /&gt;
We suppose for our examples that the query executed from the server is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=$id &lt;br /&gt;
&lt;br /&gt;
We will set the following Id value: &lt;br /&gt;
&lt;br /&gt;
 $id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable&lt;br /&gt;
&lt;br /&gt;
We will have the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable &lt;br /&gt;
&lt;br /&gt;
which will join the result of the original query with all the credit card users. &lt;br /&gt;
The keyword '''ALL''' is necessary to get around the query that make use of keyword DISTINCT. &lt;br /&gt;
Moreover we notice that beyond the credit card numbers, we have selected other two values. These two values are necessary, because the two query must have an equal number of parameters, in order to avoid a syntax error.&lt;br /&gt;
&lt;br /&gt;
=== Blind SQL Injection Testing ===&lt;br /&gt;
We have pointed out that exists another category of SQL injection, called Blind SQL Injection, in which nothing is known on the outcome of an operation. This behavior happens in cases where the programmer has created a customed error page that does not reveal anything on the structure of the query or on the database. (Does not return a SQL error, it may just return a HTTP 500).&lt;br /&gt;
&amp;lt;BR&amp;gt;&lt;br /&gt;
Thanks to the inference methods it is possible to avoid this obstacle and thus to succeed to recover the values of some desired fields. The method consists in carrying out a series of booloean queries to the server, observing the answers and finally deducing the meaning of such answers.&lt;br /&gt;
We consider, as always, the www.example.com domain and we suppose that it contains a parameter vulnerable to SQL injection of name id.&lt;br /&gt;
This means that carrying out the following request: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?id=1' &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
we will get one page with a custom message error which is due to a syntactic error in the query. We suppose that the query executed on the server is: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='$Id' &lt;br /&gt;
&lt;br /&gt;
which is exploitable through the methods seen previously. &lt;br /&gt;
What we want is to obtain the values of the username field. The tests that we will execute will allow us to obtain the value of the username field, extracting such value character by character. This is possible through the use of some standard functions, present practically in every database. For our examples we will use the following pseudo-functions: &lt;br /&gt;
&lt;br /&gt;
'''SUBSTRING (text, start, length)''': it returns a substring starting from the position &amp;quot;start&amp;quot; of text and of length &amp;quot;length&amp;quot;. If &amp;quot;start&amp;quot; is greater than the length of text, the function returns a null value. &lt;br /&gt;
&lt;br /&gt;
'''ASCII (char)''': it gives back ASCII value of the input character. A null value is returned if char is 0.&lt;br /&gt;
&lt;br /&gt;
'''LENGTH (text)''': it gives back the length in characters of the input text.&lt;br /&gt;
&lt;br /&gt;
Through such functions we will execute our tests on the first character and, when we will have discovered the value, we will pass to the second and so on, until we will have discovered the entire value. &lt;br /&gt;
The tests will take advantage of the function SUBSTRING in order to select only one character at time (selecting a single character means to impose the length parameter to 1) and function ASCII in order to obtain the ASCII value, so that we can do numerical comparison. The results of the comparison will be done with all the values of ASCII table, until finding the desired value.&lt;br /&gt;
As an example we will insert the following value for ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1 &lt;br /&gt;
&lt;br /&gt;
that creates the following query (from now on we will call it &amp;quot;inferential query&amp;quot;): &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1'&lt;br /&gt;
&lt;br /&gt;
The previous returns a result if and only if the first character of field username is equal to the ASCII value 97. If we get a false value then we increase the index of ASCII table from 97 to 98 and we repeat the request. If instead we obtain a true value, we set to zero the index of the table and we pass to analyze the next character, modifying the parameters of SUBSTRING function.&lt;br /&gt;
The problem is to understand in that way we distinguish the test that has carried a true value, from the one that has carried a false value.&lt;br /&gt;
In order to make this we create a query that we are sure returns a false value. &lt;br /&gt;
This is possible by the following value as field ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND '1' = '2 &lt;br /&gt;
&lt;br /&gt;
by which will create the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND '1' = '2' &lt;br /&gt;
&lt;br /&gt;
The answer of the server obtained (that is HTML code) will be the false value for our tests. &lt;br /&gt;
This is enough to verify whether the value obtained from the execution of the inferential query is equal to the value obtained with the test exposed before. &lt;br /&gt;
Sometimes this method does not work. In the case the server returns two different pages as a result of two identical consecutive web requests we will not be able to discriminate the true value from the false value. In these particular cases, it is necessary to use particular filters that allow us to eliminate the code that changes between the two requests and to obtain a template. Later on, for every inferential request executed, we will extract the relative template from the response using the same function, and we will perform a control between the two template in order to decide the result of the test.&lt;br /&gt;
In the previous tests, we are supposed to know in what way it is possible to understand when we have ended the inference beacause we have obtained the value. &lt;br /&gt;
In order to understand when we have ended, we will use one characteristic of the SUBSTRING function and the LENGTH function.&lt;br /&gt;
When our test will return a true value and we would have used an ASCII code equals to 0 (that is the value null), then that mean that we have ended to make inference, or that the value we have analyzed effectively contains the value null.&lt;br /&gt;
&lt;br /&gt;
We will insert the following value for the field ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND LENGTH(username)=N AND '1' = '1 &lt;br /&gt;
&lt;br /&gt;
Where N is the number of characters that we have analyzed with now (excluded the null value). &lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND LENGTH(username)=N AND '1' = '1' &lt;br /&gt;
&lt;br /&gt;
that gives back a true or false value. If we have a true value, then we have ended to make inference and therefore we have gained the value of the parameter. If we obtain a false value, this means that the null character is present on the value of the parameter, then we must continue to analyze the next parameter until we will find another null value.&lt;br /&gt;
&lt;br /&gt;
The blind SQL injection attack needs a high volume of queries. The tester may need an automatic tool to exploit the vulnerability.&lt;br /&gt;
A simple tool which performs this task, via GET requests on MySql DB is SqlDumper, is shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:sqldumper.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Stored Procedure Injection ===&lt;br /&gt;
Question: How can the risk of SQL injection be eliminated? &amp;lt;br&amp;gt;&lt;br /&gt;
Answer: Stored procedures.&amp;lt;br&amp;gt;&lt;br /&gt;
I have seen this answer too many times without qualifications.  Merely the use of stored procedures does not assist in the mitigation of SQL injection.  If not handled properly, dynamic SQL within stored procedures can be just as vulnerable to SQL injection as dynamic SQL within a web page.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
When using dynamic SQL within a stored procedure, the application must properly sanitize the user input to eliminate the risk of code injection.  If not sanitized, the user could enter malicious SQL that will be executed within the stored procedure.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Black box testing uses SQL injection to compromise the system. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure user_login @username varchar(20), @passwd varchar(20) As&lt;br /&gt;
 Declare @sqlstring varchar(250) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select 1 from users &lt;br /&gt;
 Where username = ‘ + @username + ‘ and passwd = ‘ + @passwd&lt;br /&gt;
 exec(@sqlstring)&lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 anyusername or 1=1'&lt;br /&gt;
 anypassword&lt;br /&gt;
This procedure does not sanitize the input therefore allowing the return value to show an existing record with these parameters.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
NOTE:  This example may seem unlikely due to the use of dynamic SQL to log in a user but consider a dynamic reporting query where the user selects the columns to view. The user could insert malicious code into this scenario and compromise the data.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure get_report @columnamelist varchar(7900) As&lt;br /&gt;
 Declare @sqlstring varchar(8000) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select ‘ + @columnamelist + ‘ from ReportTable‘&lt;br /&gt;
 exec(@sqlstring) &lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 1 from users; update users set password = 'password'; select *&lt;br /&gt;
&lt;br /&gt;
This will result in the report running and all users’ passwords being updated.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Related Articles ==&lt;br /&gt;
&lt;br /&gt;
* [[Top 10 2007-Injection Flaws]]&lt;br /&gt;
* [[SQL Injection]]&lt;br /&gt;
* [[Avoiding SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
Technology specific Testing Guide pages have been created for the following DBMSs:&lt;br /&gt;
&lt;br /&gt;
* [[Testing for Oracle | Oracle]]&lt;br /&gt;
* [[Testing for MySQL | MySQL]]&lt;br /&gt;
* [[Testing for SQL Server | SQL Server]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Victor Chapela: &amp;quot;Advanced SQL Injection&amp;quot; - http://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt&lt;br /&gt;
* Chris Anley: &amp;quot;Advanced SQL Injection In SQL Server Applications&amp;quot; - http://www.nextgenss.com/papers/advanced_sql_injection.pdf&lt;br /&gt;
* Chris Anley: &amp;quot;More Advanced SQL Injection&amp;quot; - http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf&lt;br /&gt;
* David Litchfield: &amp;quot;Data-mining with SQL Injection and Inference&amp;quot; - http://www.nextgenss.com/research/papers/sqlinference.pdf&lt;br /&gt;
* Kevin Spett: &amp;quot;SQL Injection&amp;quot; - http://www.spidynamics.com/papers/SQLInjectionWhitePaper.pdf&lt;br /&gt;
* Kevin Spett: &amp;quot;Blind SQL Injection&amp;quot; - http://www.spidynamics.com/whitepapers/Blind_SQLInjection.pdf&lt;br /&gt;
* Imperva: &amp;quot;Blind SQL Injection&amp;quot; - http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html&lt;br /&gt;
* Ferruh Mavituna: &amp;quot;SQL Injection Cheat Sheet&amp;quot; - http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* OWASP SQLiX- http://www.owasp.org/index.php/Category:OWASP_SQLiX_Project&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - [[http://www.sqlpowerinjector.com/index.htm SQL Power Injector]]&amp;lt;br&amp;gt;&lt;br /&gt;
* ilo--:  MySql Blind Injection Bruteforcing, Reversing.org - [[http://www.reversing.org/node/view/11 sqlbftools]]&amp;lt;br&amp;gt;&lt;br /&gt;
* Bernardo Damele and Daniele Bellucci: sqlmap, a blind SQL injection tool - http://sqlmap.sourceforge.net&lt;br /&gt;
* Antonio Parata: Dump Files by SQL inference on Mysql - [[http://www.ictsc.it/site/IT/projects/sqlDumper/sqldumper.src.tar.gz SqlDumper]]&amp;lt;br&amp;gt;&lt;br /&gt;
* icesurfer: SQL Server Takeover Tool - [[http://sqlninja.sourceforge.net sqlninja]]&lt;br /&gt;
&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;/div&gt;</summary>
		<author><name>Marius Quadflieg</name></author>	</entry>

	</feed>