Difference between revisions of "Top 10 2013-A1-Injection"

From OWASP
Jump to: navigation, search
(Changed use of Template 'Top_10_2010:SubsectionAdvancedTemplate': Replace Parameter 'number' by 'subsection' and 'position')
(16 intermediate revisions by one user not shown)
Line 1: Line 1:
= TEMPORARY PLACEHOLDER for 2013 T10 =
 
 
{{Top_10_2013:TopTemplate
 
{{Top_10_2013:TopTemplate
 
     |usenext=2013NextLink
 
     |usenext=2013NextLink
 
     |next={{Top_10_2010:ByTheNumbers
 
     |next={{Top_10_2010:ByTheNumbers
               |2
+
               |3
 
               |year=2013}}
 
               |year=2013}}
 
     |useprev=2013PrevLink
 
     |useprev=2013PrevLink
     |prev=Main
+
     |prev=T10
 
}}
 
}}
  
{{Top_10_2010:SummaryTableHeaderBeginTemplate}}
+
{{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2013}}
{{Top_10_2010:SummaryTableValue-1-Template|Exploitability|EASY}}
+
{{Top_10_2010:SummaryTableValue-1-Template|Exploitability|EASY|year=2013}}
{{Top_10_2010:SummaryTableValue-2-Template|Prevalence|COMMON}}
+
{{Top_10_2010:SummaryTableValue-2-Template|Prevalence|COMMON|year=2013}}
{{Top_10_2010:SummaryTableValue-2-Template|Detectability|AVERAGE}}
+
{{Top_10_2010:SummaryTableValue-2-Template|Detectability|AVERAGE|year=2013}}
{{Top_10_2010:SummaryTableValue-1-Template|Impact|SEVERE}}
+
{{Top_10_2010:SummaryTableValue-1-Template|Impact|SEVERE|year=2013}}
{{Top_10_2010:SummaryTableHeaderEndTemplate}}
+
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2013}}
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>blank.</td>
+
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators.
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>blank</td>
+
</td>
     <td colspan=2  {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>blank</td>
+
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>Attacker sends simple text-based attacks that exploit the syntax of the targeted interpreter. Almost any source of data can be an injection vector, including internal sources.
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>blank</td>
+
</td>
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>blank</td>
+
     <td colspan=2  {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>[http://www.owasp.org/index.php/Injection_Flaws Injection flaws] occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code.  They are often found in SQL, LDAP, or XPath queries, OS commands, XML parsers, program arguments, etc. Injection flaws are easy to discover when examining code, but more difficult via testing. Scanners and fuzzers can help attackers find them.
{{Top_10_2010:SummaryTableEndTemplate}}
+
</td>
 +
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>Injection can result in data loss or corruption, lack of accountability, or denial of access. Injection can sometimes lead to complete host takeover.
 +
</td>
 +
     <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>Consider the business value of the affected data and the platform running the interpreter. All data could be stolen, modified, or deleted.  Could your reputation be harmed?
 +
</td>
 +
{{Top_10_2010:SummaryTableEndTemplate|year=2013}}
  
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=1|risk=1|year=2013}}
+
{{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=1|year=2013}}
blank
+
The best way to find out if an application is vulnerable to injection is to verify that all use of interpreters clearly separates untrusted data from the command or query. For SQL calls, this means using bind variables in all prepared statements and stored procedures, and avoiding dynamic queries.
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=2|risk=1|year=2013}}
+
Checking the code is a fast and accurate way to see if the application uses interpreters safely. Code analysis tools can help a security analyst find the use of interpreters and trace the data flow through the application. Penetration testers can validate these issues by crafting exploits that confirm the vulnerability.
blank
+
Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection flaws exist. Scanners cannot always reach interpreters and have difficulty detecting whether an attack was successful. Poor error handling makes injection flaws easier to discover.
#blankBullet1
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=1|year=2013}}
#blankBullet2
+
Preventing injection requires keeping untrusted data separate from commands and queries.
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=3|risk=1|year=2013}}
+
# The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface.  Be careful of APIs, such as stored procedures, that are parameterized, but can still introduce injection under the hood.
blank
+
# If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. [https://www.owasp.org/index.php/ESAPI OWASP’s ESAPI] provides many of these [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html escaping routines].
{{Top_10_2010:ExampleBeginTemplate}}<span style="color:red;">blank code</span>{{Top_10_2010:ExampleEndTemplate}}
+
# Positive or “white list” input validation with appropriate canonicalization is also recommended, but is not a complete defense as many applications require special characters in their input. [https://www.owasp.org/index.php/ESAPI OWASP’s ESAPI] has an extensible library of [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Validator.html |white list input validation routines].
blank
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=1|year=2013}}
{{Top_10_2010:ExampleBeginTemplate}}<nowiki>http://example.com/app/accountView?id=</nowiki><span style="color: red;">' or '1'='1</span>{{Top_10_2010:ExampleEndTemplate}}
+
The application uses untrusted data in the construction of the following vulnerable SQL call:
blank
+
{{Top_10_2010:ExampleBeginTemplate}}<span style="color:red;">
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=4|risk=1|year=2013}}
+
String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") +"'";
 +
</span>{{Top_10_2010:ExampleEndTemplate}}
 +
The attacker modifies the ‘id’ parameter in their browser to send: ' or '1'='1. This changes the meaning of the query to return all the records from the accounts database, instead of only the intended customer’s.
 +
{{Top_10_2010:ExampleBeginTemplate}}<span style="color:red;"><nowiki>
 +
http://example.com/app/accountView?id=' or '1'='1  
 +
</nowiki></span>{{Top_10_2010:ExampleEndTemplate}}
 +
In the worst case, the attacker uses this weakness to invoke special stored procedures in the database that enable a complete takeover of the database and possibly even the server hosting the database.
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=1|year=2013}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
* [[SQL_Injection_Prevention_Cheat_Sheet | OWASP SQL Injection Prevention Cheat Sheet]]
+
* [https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet OWASP SQL Injection Prevention Cheat Sheet]
* [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html ESAPI Encoder API]
+
* [https://www.owasp.org/index.php/Query_Parameterization_Cheat_Sheet OWASP Query Parameterization Cheat Sheet]
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
+
* [https://www.owasp.org/index.php/Command_Injection OWASP Command Injection Article]
 +
* [https://www.owasp.org/index.php/XXE OWASP XML eXternal Entity (XXE) Reference Article]
 +
* [https://www.owasp.org/index.php/ASVS ASVS: Output Encoding/Escaping Requirements (V6)]
 +
* [https://www.owasp.org/index.php/Testing_for_SQL_Injection_(OWASP-DV-005) OWASP Testing Guide: Chapter on SQL Injection Testing]
 
* [http://cwe.mitre.org/data/definitions/77.html CWE Entry 77 on Command Injection]
 
* [http://cwe.mitre.org/data/definitions/77.html CWE Entry 77 on Command Injection]
 
* [http://cwe.mitre.org/data/definitions/89.html CWE Entry 89 on SQL Injection]
 
* [http://cwe.mitre.org/data/definitions/89.html CWE Entry 89 on SQL Injection]
 +
* [http://cwe.mitre.org/data/definitions/564.html CWE Entry 564 on Hibernate Injection]
  
 
{{Top_10_2013:BottomAdvancedTemplate
 
{{Top_10_2013:BottomAdvancedTemplate
Line 46: Line 61:
 
     |usenext=2013NextLink
 
     |usenext=2013NextLink
 
     |next={{Top_10_2010:ByTheNumbers
 
     |next={{Top_10_2010:ByTheNumbers
               |2
+
               |3
 
               |year=2013}}
 
               |year=2013}}
 
     |useprev=2013PrevLink
 
     |useprev=2013PrevLink
     |prev=Main
+
     |prev=T10
 
}}
 
}}
 
[[Category:OWASP Top Ten Project]]
 

Revision as of 17:38, 13 April 2013

[[Top 10 {{{year}}}-T10|← T10]]
2013 Table of Contents

2013 Top 10 List

[[Top 10 {{{year}}}-Cross-Site Scripting (XSS)|Cross-Site Scripting (XSS) →]]
Threat Agents Attack Vectors Security Weakness Technical Impacts Business Impacts
Application Specific Exploitability
EASY
Prevalence
COMMON
Detectability
AVERAGE
Impact
SEVERE
Application / Business Specific
Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators. Attacker sends simple text-based attacks that exploit the syntax of the targeted interpreter. Almost any source of data can be an injection vector, including internal sources. Injection flaws occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code. They are often found in SQL, LDAP, or XPath queries, OS commands, XML parsers, program arguments, etc. Injection flaws are easy to discover when examining code, but more difficult via testing. Scanners and fuzzers can help attackers find them. Injection can result in data loss or corruption, lack of accountability, or denial of access. Injection can sometimes lead to complete host takeover. Consider the business value of the affected data and the platform running the interpreter. All data could be stolen, modified, or deleted. Could your reputation be harmed?
Am I Vulnerable To 'Injection'?

The best way to find out if an application is vulnerable to injection is to verify that all use of interpreters clearly separates untrusted data from the command or query. For SQL calls, this means using bind variables in all prepared statements and stored procedures, and avoiding dynamic queries. Checking the code is a fast and accurate way to see if the application uses interpreters safely. Code analysis tools can help a security analyst find the use of interpreters and trace the data flow through the application. Penetration testers can validate these issues by crafting exploits that confirm the vulnerability. Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection flaws exist. Scanners cannot always reach interpreters and have difficulty detecting whether an attack was successful. Poor error handling makes injection flaws easier to discover.

How Do I Prevent 'Injection'?

Preventing injection requires keeping untrusted data separate from commands and queries.

  1. The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface. Be careful of APIs, such as stored procedures, that are parameterized, but can still introduce injection under the hood.
  2. If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. OWASP’s ESAPI provides many of these escaping routines.
  3. Positive or “white list” input validation with appropriate canonicalization is also recommended, but is not a complete defense as many applications require special characters in their input. OWASP’s ESAPI has an extensible library of |white list input validation routines.
Example Attack Scenarios

The application uses untrusted data in the construction of the following vulnerable SQL call:

String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") +"'";

The attacker modifies the ‘id’ parameter in their browser to send: ' or '1'='1. This changes the meaning of the query to return all the records from the accounts database, instead of only the intended customer’s.

http://example.com/app/accountView?id=' or '1'='1

In the worst case, the attacker uses this weakness to invoke special stored procedures in the database that enable a complete takeover of the database and possibly even the server hosting the database.

References

OWASP

[[Top 10 {{{year}}}-T10|← T10]]
2013 Table of Contents

2013 Top 10 List

[[Top 10 {{{year}}}-Cross-Site Scripting (XSS)|Cross-Site Scripting (XSS) →]]

© 2002-2013 OWASP Foundation This document is licensed under the Creative Commons Attribution-ShareAlike 3.0 license. Some rights reserved. CC-by-sa-3 0-88x31.png
[[Category:OWASP Top Ten {{{year}}} Project]]