This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Testing for Input Validation"

From OWASP
Jump to: navigation, search
m
m (Formatting.)
 
(43 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Template:OWASP Testing Guide v3}}
+
{{Template:OWASP Testing Guide v4}}
  
''' 4.8 Data Validation Testing '''
+
''' 4.8 Input Validation Testing '''
 
----
 
----
  
The most common web application security weakness is the failure to properly validate input coming from the client or environment before using it. This weakness leads to almost all of the major vulnerabilities in web applications, such as cross site scripting, SQL injection, interpreter injection, locale/Unicode attacks, file system attacks, and buffer overflows.<br>
+
The most common web application security weakness is the failure to properly validate input coming from the client or from the environment before using it. This weakness leads to almost all of the major vulnerabilities in web applications, such as cross site scripting, SQL injection, interpreter injection, locale/Unicode attacks, file system attacks, and buffer overflows.
Data from an external entity or client should never be trusted, since it can be arbitrarily tampered with by an attacker. "All Input is Evil", says Michael Howard in his famous book "Writing Secure Code". That is rule number one. Unfortunately, complex applications often have a large number of entry points, which makes it difficult for a developer to enforce this rule.
+
 
<br>
+
 
In this chapter, we describe Data Validation testing. This is the task of testing all the possible forms of input, to understand if the application sufficiently validates input data before using it.<br>
+
Data from an external entity or client should never be trusted, since it can be arbitrarily tampered with by an attacker. "All Input is Evil", says Michael Howard in his famous book "Writing Secure Code". That is rule number one. Unfortunately, complex applications often have a large number of entry points, which makes it difficult for a developer to enforce this rule. This chapter describes Data Validation testing. This is the task of testing all the possible forms of input to understand if the application sufficiently validates input data before using it.
We split data validation testing into the following categories:<br>
+
 
 +
 
 +
Input validation testing is split into the following categories.<br> <br>
  
 
'''Testing for Cross site scripting'''<br>
 
'''Testing for Cross site scripting'''<br>
In Cross Site Scripting (XSS) testing, we test if it is possible to manipulate the input parameters of the application so that it generates malicious output. We find a XSS vulnerability when the application does not validate our input and creates an output that is under our control. This vulnerability leads to various attacks, for example, stealing confidential information (such as session cookies) or taking control of the victim's browser. A XSS breaks the following pattern: Input -> Output  == cross-site scripting<br>
+
Cross Site Scripting (XSS) testing checks if it is possible to manipulate the input parameters of the application so that it generates malicious output. Testers find an XSS vulnerability when the application does not validate their input and creates an output that is under their control. This vulnerability leads to various attacks, for example, stealing confidential information (such as session cookies) or taking control of the victim's browser. An XSS attack breaks the following pattern: Input -> Output  == cross-site scripting.
In this guide, we describe the following types of XSS testing:<br>
+
 
[[Testing for Reflected Cross site scripting|4.8.1 Testing for Reflected Cross Site Scripting]]<br>
+
 
[[Testing for Stored Cross site scripting|4.8.2 Testing for Stored Cross Site Scripting]]<br>
+
In this guide, the following types of XSS testing are discussed in details:<br>
[[Testing for DOM-based Cross site scripting|4.8.3 Testing for DOM based Cross Site Scripting]]<br>
+
 
[[Testing for Cross site flashing|4.8.4 Testing for Cross Site Flashing]]<br>
+
[[Testing for Reflected Cross site scripting (OTG-INPVAL-001) |'''4.8.1 Testing for Reflected Cross Site Scripting (OTG-INPVAL-001)''']]
 +
 
 +
[[Testing for Stored Cross site scripting (OTG-INPVAL-002) |'''4.8.2 Testing for Stored Cross Site Scripting (OTG-INPVAL-002)''']]
 +
 
 +
Client side XSS testing, such as DOM XSS and Cross site Flashing is discussed in the Client Side testing section. <br> <br>
 +
 
 +
'''Testing for HTTP Verb Tampering and Parameter Pollution'''
  
'''[[Testing for SQL Injection|4.8.5 SQL Injection ]]<br>'''
+
HTTP Verb Tampering tests the web application's response to different HTTP methods accessing system objects. For every system object discovered during spidering, the tester should attempt accessing all of those objects with every HTTP method.
In SQL injection testing, we test if it is possible to inject data into the application so that it executes a user-controlled SQL query in the back-end DB. We find a SQL injection vulnerability if the application uses user input to create SQL queries without proper input validation. A successful exploitation of this class of vulnerability allows an unauthorized user to access or manipulate data in the database. Note that application data often represents the core asset of a company. An SQL Injection breaks the following pattern:
+
HTTP Parameter Pollution tests the applications response to receiving multiple HTTP parameters with the same name. For example, if the parameter ''username'' is included in the GET or POST parameters twice, which one is honoured, if any.
Input -> Query SQL == SQL injection<br>
 
SQL Injection testing is further broken down into:<br>
 
[[Testing for Oracle|4.8.5.1 Oracle Testing ]]<br>
 
[[Testing for MySQL|4.8.5.2 MySQL Testing ]]<br>
 
[[Testing for SQL Server|4.8.5.3 SQL Server Testing]]<br>
 
[[Testing for MS Access|4.8.5.4 MS Access Testing]]<br>
 
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.5.5 Testing PostgreSQL]]<br>
 
  
'''[[Testing for LDAP Injection |4.8.6 LDAP Injection]]<br>'''
+
HTTP Verb Tampering is described in
LDAP injection testing is similar to SQL Injection Testing. The differences are that we use the LDAP protocol instead of SQL and that the target is an LDAP Server instead of an SQL Server.  
+
 
An LDAP Injection breaks the following pattern:<br>
+
[[Testing for HTTP Verb Tampering (OTG-INPVAL-003)|'''4.8.3 Testing for HTTP Verb Tampering (OTG-INPVAL-003)''']]
 +
 
 +
and HTTP Parameter testing techniques are presented in
 +
 
 +
[[Testing for HTTP Parameter pollution (OTG-INPVAL-004)|'''4.8.4 Testing for HTTP Parameter pollution (OTG-INPVAL-004)''']]
 +
 
 +
<br> '''[[Testing for SQL Injection  (OTG-INPVAL-005)|4.8.5 SQL Injection  (OTG-INPVAL-005)]]<br>'''
 +
SQL injection testing checks if it is possible to inject data into the application so that it executes a user-controlled SQL query in the back-end database. Testers find an SQL injection vulnerability if the application uses user input to create SQL queries without proper input validation. A successful exploitation of this class of vulnerability allows an unauthorized user to access or manipulate data in the database. Note that application data often represents the core asset of a company. An SQL Injection attack breaks the following pattern:
 +
Input -> Query SQL == SQL injection
 +
 
 +
SQL Injection testing is further broken down by product or vendor:<br>
 +
[[Testing for Oracle |4.8.5.1 Oracle Testing]]<br>
 +
[[Testing for MySQL |4.8.5.2 MySQL Testing]] <br>
 +
[[Testing for SQL Server |4.8.5.3 SQL Server Testing]] <br>
 +
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.5.4 Testing PostgreSQL]]<br>
 +
[[Testing for MS Access|4.8.5.5 MS Access Testing]]<br>
 +
[[Testing for NoSQL injection|4.8.5.6 Testing for NoSQL injection]]<br>
 +
 
 +
<br> '''[[Testing for LDAP Injection (OTG-INPVAL-006) |4.8.6 LDAP Injection (OTG-INPVAL-006)]]<br>'''
 +
LDAP injection testing is similar to SQL Injection testing. The differences are that testers use the LDAP protocol instead of SQL and the target is an LDAP Server instead of a SQL Server.  
 +
An LDAP Injection attack breaks the following pattern:<br>
 
Input -> Query LDAP == LDAP injection<br>
 
Input -> Query LDAP == LDAP injection<br>
  
'''[[Testing for ORM Injection |4.8.7 ORM Injection]]<br>'''
+
<br> '''[[Testing for ORM Injection   (OTG-INPVAL-007) |4.8.7 ORM Injection (OTG-INPVAL-007)]]<br>'''
ORM injection testing is similar to SQL Injection Testing, as well. In this case, we use an SQL Injection against an ORM-generated data access object model. From the tester point of view, this attack is virtually identical to a SQL Injection attack. However, the injection vulnerability exists in the code generated by an ORM tool.<br>
+
ORM injection testing is similar to SQL Injection Testing. In this case, testers use a SQL Injection against an ORM-generated data access object model. From the tester's point of view, this attack is virtually identical to a SQL Injection attack. However, the injection vulnerability exists in the code generated by an ORM tool.<br>
  
'''[[Testing for XML Injection |4.8.8 XML Injection]]<br>'''
+
<br> '''[[Testing for XML Injection (OTG-INPVAL-008) |4.8.8 XML Injection (OTG-INPVAL-008)]]<br>'''
In XML injection testing, we test if it possible to inject a particular XML document into the application. We find a XML injection vulnerability if the XML parser fails to make appropriate data validation.<br>
+
XML injection testing checks if it possible to inject a particular XML document into the application. Testers find an XML injection vulnerability if the XML parser fails to make appropriate data validation.<br>
An XML Injection breaks the following pattern:<br>
+
An XML Injection attack breaks the following pattern:<br>
 
Input -> XML doc == XML injection<br>
 
Input -> XML doc == XML injection<br>
  
'''[[Testing for SSI Injection |4.8.9 SSI Injection]]<br>'''
+
<br> '''[[Testing for SSI Injection (OTG-INPVAL-009) |4.8.9 SSI Injection (OTG-INPVAL-009)]]<br>'''
Web servers usually give to the developer the possibility to add small pieces of dynamic code inside static HTML pages, without having to deal with full-fledged server-side or client-side languages. This feature is incarnated by the Server-Side Includes (SSI). In SSI injection testing, we test if it possible to inject data into the application that will be interpreted by SSI mechanisms. A successful exploitation of this vulnerability allows an attacker to inject code into HTML pages or even perform remote code execution.<br>
+
Web servers usually give developers the ability to add small pieces of dynamic code inside static HTML pages, without having to deal with full-fledged server-side or client-side languages. This feature is incarnated by Server-Side Includes (SSI) Injection. In SSI injection testing, testers check if it is possible to inject into the application data that will be interpreted by SSI mechanisms. A successful exploitation of this vulnerability allows an attacker to inject code into HTML pages or even perform remote code execution.<br>
  
'''[[Testing for XPath Injection |4.8.10 XPath Injection]]<br>'''
+
<br> '''[[Testing for XPath Injection (OTG-INPVAL-010) |4.8.10 XPath Injection (OTG-INPVAL-010)]]<br>'''
XPath is a language that has been designed and developed primarily to address parts of an XML document. In XPath injection testing, we test if it possible to inject data into an application so that it executes user-controlled XPath queries. When successfully exploited, this vulnerability may allow an attacker to bypass authentication mechanisms or access information without proper authorization.<br>
+
XPath is a language that has been designed and developed primarily to address parts of an XML document. In XPath injection testing, testers check if it is possible to inject data into an application so that it executes user-controlled XPath queries. When successfully exploited, this vulnerability may allow an attacker to bypass authentication mechanisms or access information without proper authorization.<br>
  
'''[[Testing for IMAP/SMTP Injection|4.8.11 IMAP/SMTP Injection]]<br>'''
+
<br> '''[[Testing for IMAP/SMTP Injection (OTG-INPVAL-011)|4.8.11 IMAP/SMTP Injection (OTG-INPVAL-011)]]<br>'''
This threat affects all the applications that communicate with mail servers (IMAP/SMTP), generally webmail applications. In IMAP/SMTP injection testing, we test if it possible to inject arbitrary IMAP/SMTP commands into the mail servers, due to input data not properly sanitized. <br>
+
This threat affects all the applications that communicate with mail servers (IMAP/SMTP), generally web mail applications. In IMAP/SMTP injection testing, testers check if it possible to inject arbitrary IMAP/SMTP commands into the mail servers, due to input data not properly sanitized. <br>
An IMAP/SMTP Injection breaks the following pattern:<br>
+
An IMAP/SMTP Injection attack breaks the following pattern:<br>
Input -> IMAP/SMPT command == IMAP/SMTP Injection<br>
+
Input -> IMAP/SMTP command == IMAP/SMTP Injection<br>
  
'''[[Testing for Code Injection|4.8.12 Code Injection]]<br>'''
+
<br> '''[[Testing for Code Injection (OTG-INPVAL-012)|4.8.12 Code Injection (OTG-INPVAL-012)]]<br>'''
In code injection testing, we check if it is possible to inject into an application data that will be later executed by the web server.<br>
+
Code injection testing checks if it is possible to inject into an application data that will be later executed by the web server.<br>
A Code Injection breaks the following pattern:<br>
+
A Code Injection attack breaks the following pattern:<br>
Input -> malicius Code == Code Injection<br>
+
Input -> malicious Code == Code Injection
  
'''[[Testing for Command Injection|4.8.13 OS Commanding]]<br>'''
+
[[Testing for Local File Inclusion|4.8.12.1 Testing for Local File Inclusion]]
In command injection testing, we will try to inject an OS command throughout an HTTP request into the application.<br>
+
 
An OS Command Injection breaks the following pattern:<br>
+
[[Testing for Remote File Inclusion|4.8.12.2 Testing for Remote File Inclusion]]<br>
 +
 
 +
<br> '''[[Testing for Command Injection   (OTG-INPVAL-013)|4.8.13 OS Commanding   (OTG-INPVAL-013)]]<br>'''
 +
In command injection testing testers will try to inject an OS command through an HTTP request into the application.<br>
 +
An OS Command Injection attack breaks the following pattern:<br>
 
Input -> OS Command == OS Command Injection<br>
 
Input -> OS Command == OS Command Injection<br>
  
'''[[Testing for Buffer Overflow|4.8.14 Buffer overflow Testing ]]<br>'''
+
<br> '''[[Testing for Buffer Overflow (OTG-INPVAL-014)|4.8.14 Buffer overflow (OTG-INPVAL-014)]]<br>'''
In these tests, we check for different types of buffer overflow vulnerabilities. Here are the testing methods for the common types of buffer overflow vulnerabilities:<br>
+
In these tests, testers check for different types of buffer overflow vulnerabilities. Here are the testing methods for the common types of buffer overflow vulnerabilities:<br>
[[Testing for Heap Overflow |4.8.14.1 Heap overflow ]]<br>
+
[[Testing for Heap Overflow |4.8.14.1 Heap overflow]] <br>
[[Testing for Stack Overflow |4.8.14.2 Stack overflow ]]<br>
+
[[Testing for Stack Overflow |4.8.14.2 Stack overflow]] <br>
[[Testing for Format String |4.8.14.3 Format string ]]<br>
+
[[Testing for Format String |4.8.14.3 Format string]] <br>
 +
 
 
In general Buffer overflow breaks the following pattern:<br>
 
In general Buffer overflow breaks the following pattern:<br>
 
Input -> Fixed buffer or format string == overflow<br>
 
Input -> Fixed buffer or format string == overflow<br>
  
'''[[Testing for Incubated Vulnerability |4.8.15 Incubated vulnerability testing]] <br>'''
+
<br> '''[[Testing for Incubated Vulnerability (OTG-INPVAL-015) |4.8.15 Incubated vulnerability (OTG-INPVAL-015)]] <br>'''
Incubated testing is a complex testing that need more that one data validation vulnerability to work.<br>
+
Incubated testing is a complex testing that needs more than one data validation vulnerability to work.<br>
 +
 
 +
<br> [[Testing for HTTP Splitting/Smuggling  (OTG-INPVAL-016)|'''4.8.16 Testing for HTTP Splitting/Smuggling  (OTG-INPVAL-016)''']]<br>
 +
Describes how to test for an HTTP Exploit, as HTTP Verb, HTTP Splitting, HTTP Smuggling.
 +
 
 +
<br> [[Testing for HTTP Incoming requests (OTG-INPVAL-017)|'''4.8.17 Testing for HTTP Incoming Requests (OTG-INPVAL-017)''']]
 +
 
 +
Describes how to monitor all incoming/outgoing http requests on both client or web server side. This is in order to verify if there are unnecessary or suspicious HTTP requests being sent in the background.
 +
 
  
In every pattern showed the data should be validated by the application before it's trusted and processed. The goal of our testing is to verify if the application actually performs validation and does not trust its input.
+
In every pattern shown, the data should be validated by the application before it's trusted and processed. The goal of testing is to verify if the application actually performs validation and does not trust its input.

Latest revision as of 20:00, 9 June 2019

This article is part of the new OWASP Testing Guide v4.
Back to the OWASP Testing Guide v4 ToC: https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents Back to the OWASP Testing Guide Project: https://www.owasp.org/index.php/OWASP_Testing_Project


4.8 Input Validation Testing


The most common web application security weakness is the failure to properly validate input coming from the client or from the environment before using it. This weakness leads to almost all of the major vulnerabilities in web applications, such as cross site scripting, SQL injection, interpreter injection, locale/Unicode attacks, file system attacks, and buffer overflows.


Data from an external entity or client should never be trusted, since it can be arbitrarily tampered with by an attacker. "All Input is Evil", says Michael Howard in his famous book "Writing Secure Code". That is rule number one. Unfortunately, complex applications often have a large number of entry points, which makes it difficult for a developer to enforce this rule. This chapter describes Data Validation testing. This is the task of testing all the possible forms of input to understand if the application sufficiently validates input data before using it.


Input validation testing is split into the following categories.

Testing for Cross site scripting
Cross Site Scripting (XSS) testing checks if it is possible to manipulate the input parameters of the application so that it generates malicious output. Testers find an XSS vulnerability when the application does not validate their input and creates an output that is under their control. This vulnerability leads to various attacks, for example, stealing confidential information (such as session cookies) or taking control of the victim's browser. An XSS attack breaks the following pattern: Input -> Output == cross-site scripting.


In this guide, the following types of XSS testing are discussed in details:

4.8.1 Testing for Reflected Cross Site Scripting (OTG-INPVAL-001)

4.8.2 Testing for Stored Cross Site Scripting (OTG-INPVAL-002)

Client side XSS testing, such as DOM XSS and Cross site Flashing is discussed in the Client Side testing section.

Testing for HTTP Verb Tampering and Parameter Pollution

HTTP Verb Tampering tests the web application's response to different HTTP methods accessing system objects. For every system object discovered during spidering, the tester should attempt accessing all of those objects with every HTTP method. HTTP Parameter Pollution tests the applications response to receiving multiple HTTP parameters with the same name. For example, if the parameter username is included in the GET or POST parameters twice, which one is honoured, if any.

HTTP Verb Tampering is described in

4.8.3 Testing for HTTP Verb Tampering (OTG-INPVAL-003)

and HTTP Parameter testing techniques are presented in

4.8.4 Testing for HTTP Parameter pollution (OTG-INPVAL-004)


4.8.5 SQL Injection (OTG-INPVAL-005)
SQL injection testing checks if it is possible to inject data into the application so that it executes a user-controlled SQL query in the back-end database. Testers find an SQL injection vulnerability if the application uses user input to create SQL queries without proper input validation. A successful exploitation of this class of vulnerability allows an unauthorized user to access or manipulate data in the database. Note that application data often represents the core asset of a company. An SQL Injection attack breaks the following pattern: Input -> Query SQL == SQL injection

SQL Injection testing is further broken down by product or vendor:
4.8.5.1 Oracle Testing
4.8.5.2 MySQL Testing
4.8.5.3 SQL Server Testing
4.8.5.4 Testing PostgreSQL
4.8.5.5 MS Access Testing
4.8.5.6 Testing for NoSQL injection


4.8.6 LDAP Injection (OTG-INPVAL-006)
LDAP injection testing is similar to SQL Injection testing. The differences are that testers use the LDAP protocol instead of SQL and the target is an LDAP Server instead of a SQL Server. An LDAP Injection attack breaks the following pattern:
Input -> Query LDAP == LDAP injection


4.8.7 ORM Injection (OTG-INPVAL-007)
ORM injection testing is similar to SQL Injection Testing. In this case, testers use a SQL Injection against an ORM-generated data access object model. From the tester's point of view, this attack is virtually identical to a SQL Injection attack. However, the injection vulnerability exists in the code generated by an ORM tool.


4.8.8 XML Injection (OTG-INPVAL-008)
XML injection testing checks if it possible to inject a particular XML document into the application. Testers find an XML injection vulnerability if the XML parser fails to make appropriate data validation.
An XML Injection attack breaks the following pattern:
Input -> XML doc == XML injection


4.8.9 SSI Injection (OTG-INPVAL-009)
Web servers usually give developers the ability to add small pieces of dynamic code inside static HTML pages, without having to deal with full-fledged server-side or client-side languages. This feature is incarnated by Server-Side Includes (SSI) Injection. In SSI injection testing, testers check if it is possible to inject into the application data that will be interpreted by SSI mechanisms. A successful exploitation of this vulnerability allows an attacker to inject code into HTML pages or even perform remote code execution.


4.8.10 XPath Injection (OTG-INPVAL-010)
XPath is a language that has been designed and developed primarily to address parts of an XML document. In XPath injection testing, testers check if it is possible to inject data into an application so that it executes user-controlled XPath queries. When successfully exploited, this vulnerability may allow an attacker to bypass authentication mechanisms or access information without proper authorization.


4.8.11 IMAP/SMTP Injection (OTG-INPVAL-011)
This threat affects all the applications that communicate with mail servers (IMAP/SMTP), generally web mail applications. In IMAP/SMTP injection testing, testers check if it possible to inject arbitrary IMAP/SMTP commands into the mail servers, due to input data not properly sanitized.
An IMAP/SMTP Injection attack breaks the following pattern:
Input -> IMAP/SMTP command == IMAP/SMTP Injection


4.8.12 Code Injection (OTG-INPVAL-012)
Code injection testing checks if it is possible to inject into an application data that will be later executed by the web server.
A Code Injection attack breaks the following pattern:
Input -> malicious Code == Code Injection

4.8.12.1 Testing for Local File Inclusion

4.8.12.2 Testing for Remote File Inclusion


4.8.13 OS Commanding (OTG-INPVAL-013)
In command injection testing testers will try to inject an OS command through an HTTP request into the application.
An OS Command Injection attack breaks the following pattern:
Input -> OS Command == OS Command Injection


4.8.14 Buffer overflow (OTG-INPVAL-014)
In these tests, testers check for different types of buffer overflow vulnerabilities. Here are the testing methods for the common types of buffer overflow vulnerabilities:
4.8.14.1 Heap overflow
4.8.14.2 Stack overflow
4.8.14.3 Format string

In general Buffer overflow breaks the following pattern:
Input -> Fixed buffer or format string == overflow


4.8.15 Incubated vulnerability (OTG-INPVAL-015)
Incubated testing is a complex testing that needs more than one data validation vulnerability to work.


4.8.16 Testing for HTTP Splitting/Smuggling (OTG-INPVAL-016)
Describes how to test for an HTTP Exploit, as HTTP Verb, HTTP Splitting, HTTP Smuggling.


4.8.17 Testing for HTTP Incoming Requests (OTG-INPVAL-017)

Describes how to monitor all incoming/outgoing http requests on both client or web server side. This is in order to verify if there are unnecessary or suspicious HTTP requests being sent in the background.


In every pattern shown, the data should be validated by the application before it's trusted and processed. The goal of testing is to verify if the application actually performs validation and does not trust its input.