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

From OWASP
Jump to: navigation, search
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Top_10_2010:TopTemplate|usenext=NextLink|next=-Cross Site Scritping (XSS)|useprev=PrevLink|prev=-Main|usemain=MainLink|main=Main}}  
+
{{Top_10_2010:TopTemplate|usenext=2010NextLink|next=A2-Cross-Site Scripting (XSS)|useprev=2010PrevLink|prev=Main}}
  
<center>
+
{{Top_10_2010:SummaryTableHeaderBeginTemplate}}
{| style="align:center; text-align:center; border:2px solid #4F81BD; background-color:#F2F2F2; padding=2;"
+
{{Top_10_2010:SummaryTableValue-1-Template|Exploitability|EASY}}
|- style="background-color: #4F81Bd; color: #FFFFFF;"
+
{{Top_10_2010:SummaryTableValue-2-Template|Prevalence|COMMON}}
! Threat Agents !! Attack Vectors
+
{{Top_10_2010:SummaryTableValue-2-Template|Detectability|AVERAGE}}
! colspan="2" | Security Weakness
+
{{Top_10_2010:SummaryTableValue-1-Template|Impact|SEVERE}}
! Technical Impact
+
{{Top_10_2010:SummaryTableHeaderEndTemplate}}
! Business Impacts
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators.</td>
|-  
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>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>
| style="background-color: #D9D9D9; color: #000000;" | ______
+
    <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Injection flaws occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code, often found in SQL queries, LDAP queries, XPath queries, OS commands, 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.</td>
| style="background-color: #FF0000; color: #000000;" | Exploitability<br>EASY
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Injection can result in data loss or corruption, lack of accountability, or denial of access. Injection can sometimes lead to complete host takeover.</td>
| style="background-color: #FFB200; color: #000000;" | Prevalence<br>COMMON
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>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>
| style="background-color: #FFB200; color: #000000;" | Detectability<br>AVERAGE
+
{{Top_10_2010:SummaryTableEndTemplate}}
| style="background-color: #FF0000; color: #000000;" | Impact<br>SIMPLE
+
| style="background-color: #D9D9D9; color: #000000;" | ______
+
|-
+
| style="text-align: left; border: 2px solid #FFFFFF;" |Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators.
+
| style="text-align: left; border: 2px solid #FFFFFF;" | 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.
+
| colspan="2" style="text-align: left;border: 2px solid #FFFFFF;" | Injection flaws occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code, often found in SQL queries, LDAP queries, XPath queries, OS commands, 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.
+
| style="text-align: left; border: 2px solid #FFFFFF;" | Injection can result in data loss or corruption, lack of accountability, or denial of access. Injection can sometimes lead to complete host takeover.
+
| style="text-align: left; border: 2px solid #FFFFFF;" | 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?
+
|}
+
</center>
+
  
{{Top_10_2010:SubsectionVulnerableTemplate|Injection|
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=1|risk=1}}
 
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.
 
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.
  
Line 30: Line 20:
  
 
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.
}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=2|risk=1}}
 
+
{{Top_10_2010:SubsectionPreventionTemplate|Injection|
+
 
Preventing injection requires keeping untrusted data separate from commands and queries.
 
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.
+
#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. [http://www.owasp.org/index.php/ESAPI OWASP's ESAPI] has some of these [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html escaping routines].
+
#If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. [[ESAPI | OWASP's ESAPI]] has some of these [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html 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. [http://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]3
+
#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. [[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].
}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=3|risk=1}}
 
+
The application uses untrusted data in the construction of the following vulnerable SQL call:
{{Top_10_2010:SubsectionExampleTemplate|Injection|}}
+
{{Top_10_2010:ExampleBeginTemplate}}<span style="color:red;">String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") +"'";</span>{{Top_10_2010:ExampleEndTemplate}}
The application uses untrusted data in the construction of the following vulnerable SQL call:
+
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.
:<b><span style="color:red;">String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") +"'";</span></b>
+
{{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 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.
+
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.
:<b><nowiki>http://example.com/app/accountView?id='</nowiki> or <span style="color: red;">1'='1</span></b>
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=4|risk=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.
+
}}
+
 
+
{{Top_10_2010:SubsectionReferencesTemplate|Injection}}
+
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
* [https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet OWASP SQL Injection Prevention Cheat Sheet]
+
* [[SQL_Injection_Prevention_Cheat_Sheet | OWASP SQL Injection Prevention Cheat Sheet]]
* [http://www.owasp.org/index.php/Command_Injection OWASP Injection Flaws Article]
+
* [[Command_Injection | OWASP Injection Flaws Article]]
 
* [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html ESAPI Encoder API]
 
* [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html ESAPI Encoder API]
 
* [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Validator.html ESAPI Input Validation API]
 
* [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Validator.html ESAPI Input Validation API]
* [http://www.owasp.org/index.php/ASVS#tab=Download ASVS: Output Encoding/Escaping Requirements (V6)]
+
* [http://www.owasp.org/index.php/ASVS#tab=Downloads ASVS: Output Encoding/Escaping Requirements (V6)]
* [http://www.owasp.org/index.php/Testing_for_SQL_Injection_(OWASP-DV-005) OWASP Testing Guide: Chapter on SQL Injection Testing]
+
* [[Testing_for_SQL_Injection_(OWASP-DV-005) | OWASP Testing Guide: Chapter on SQL Injection Testing]]
* [http://www.owasp.org/index.php/Reviewing_Code_for_SQL_Injection OWASP Code Review Guide: Chapter on SQL Injection]
+
* [[Reviewing_Code_for_SQL_Injection | OWASP Code Review Guide: Chapter on SQL Injection]]
* [http://www.owasp.org/index.php/Reviewing_Code_for_OS_Injection OWASP Code Review Guide: Command Injection]
+
* [[Reviewing_Code_for_OS_Injection | OWASP Code Review Guide: Command Injection]]
 
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
 
* [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]
 +
{{Top_10_2010:BottomAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|usenext=2010NextLink|next=A2-Cross-Site Scripting (XSS)|useprev=2010PrevLink|prev=Main}}
  
 
+
[[Category:OWASP Top Ten Project]]
<br> {{Top_10_2010:BottomTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}
+

Latest revision as of 08:19, 14 June 2011

← Main
Top 10 Introduction
Top 10 Risks
A2-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, often found in SQL queries, LDAP queries, XPath queries, OS commands, 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. 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.

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. Beware of APIs, such as stored procedures, that appear parameterized, but may still allow 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 has some of these escaping routines.
  3. 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.
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, allowing a complete takeover of the database host.

References

OWASP

External

← Main
Top 10 Introduction
Top 10 Risks
A2-Cross-Site Scripting (XSS) →

© 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