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 "Top 10 2010-A1-Injection"

From OWASP
Jump to: navigation, search
Line 8: Line 8:
 
Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection problems exist. Scanners cannot always reach interpreters and can have difficulty detecting whether an attack was successful.
 
Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection problems exist. Scanners cannot always reach interpreters and can have difficulty detecting whether an attack was successful.
 
}}
 
}}
== Example Attack Scenario ==
+
{{Top_10_2010:SubsectionExampleTemplate|Injection|
 +
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.
  
== How Do I Prevent XSS? ==
+
http://example.com/app/accountView?id=' or '1'='1
  
== References ==
+
In the worst case, the attacker uses this weakness to invoke special stored procedures in the database, allowing a  complete takeover of the database host.
 +
{{Top_10_2010:SubsectionPreventionTemplate|Injection|
 +
Preventing injection requires keeping untrusted data separate from commands and queries.
  
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4899 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4899]
+
The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface. Beware of APIs, such as stored procedures, that appear parameterized, but may still allow injection under the hood.
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3389 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3389]
 
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0580 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0580]
 
  
== Related Articles  ==
+
If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. [http://www.owasp.org/index.php/ESAPI OWASP's ESAPI] has some of these !!escaping routines!!.
 
 
*[[Error Handling]]
 
*[[:Category:Sensitive Data Protection Vulnerability]]
 
 
 
== References  ==
 
 
 
*CWE: CWE-200 (Information Leak), CWE-203 (Discrepancy Information Leak), CWE-215 (Information Leak Through Debug Information), CWE-209 (Error Message Information Leak), others.  
 
*WASC Threat Classification:
 
**[http://www.webappsec.org/projects/threat/classes/information_leakage.shtml http://www.webappsec.org/projects/threat/classes/information_leakage.shtml]
 
  
 +
Positive or "whitelist" input validation with appropriate canonicalization also helps protect against injection, but  is not a complete defense as many applications require  special characters in their input. [http://www.owasp.org/index.php/ESAPI OWASP's ESAPI] has an  extensible library of white list input validation routines!!.
 +
}}
 +
{{Top_10_2010:SubsectionReferencesTemplate|Injection|
 +
*[https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet OWASP SQL Injection Prevention Cheat Sheet]
 +
*[http://www.owasp.org/index.php/Command_Injection OWASP Injection Flaws Article]
 +
*[http://www.owasp.org/index.php/Command_Injection OWASP Injection Flaws Article]
 +
|
 +
*[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]
 +
}}
 
<br> {{Top_10_2010:BottomTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}
 
<br> {{Top_10_2010:BottomTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}

Revision as of 22:27, 13 April 2010

NOTE: THIS IS NOT THE LATEST VERSION. Please visit the OWASP Top 10 project page to find the latest edition.

««««
Top 10 Introduction
Top 10 Risks
»»»»

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. Manual penetration testers can confirm these issues by crafting exploits that confirm the vulnerability.

Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection problems exist. Scanners cannot always reach interpreters and can have difficulty detecting whether an attack was successful.

{{Top_10_2010:SubsectionExampleTemplate|Injection| 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, allowing a complete takeover of the database host.

How Do I Prevent Injection?

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

The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface. Beware of APIs, such as stored procedures, that appear parameterized, but may still allow injection under the hood.

If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. OWASP's ESAPI has some of these !!escaping routines!!.

Positive or "whitelist" input validation with appropriate canonicalization also helps protect against injection, 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!!.

References


««««
Top 10 Introduction
Top 10 Risks
»»»»

© 2002-2010 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