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 2013-A1-Injection"
m (brighter background for 'Top_10_2010:ExampleBeginTemplate' => added '|year=2013'; added some '|language=en') |
m |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Top_10_2013:TopTemplate | {{Top_10_2013:TopTemplate | ||
|usenext=2013NextLink | |usenext=2013NextLink | ||
− | |next={{Top_10_2010:ByTheNumbers | + | |next=A2-{{Top_10_2010:ByTheNumbers |
|2 | |2 | ||
|year=2013 | |year=2013 | ||
|language=en}} | |language=en}} | ||
|useprev=2013PrevLink | |useprev=2013PrevLink | ||
− | |prev= | + | |prev={{Top_10:LanguageFile|text=top10|year=2013|language=en}} |
+ | |year=2013 | ||
+ | |language=en | ||
}} | }} | ||
Line 13: | Line 15: | ||
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2013}} | {{Top_10_2010:SummaryTableHeaderEndTemplate|year=2013}} | ||
<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|year=2013}}>Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators. | ||
+ | |||
</td> | </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|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> | </td> | ||
− | <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>[ | + | <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2013}}>[[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, Xpath, or NoSQL queries; OS commands; XML parsers, SMTP Headers, program arguments, etc. Injection flaws are easy to discover when examining code, but frequently hard to discover via testing. Scanners and fuzzers can help attackers find injection flaws. |
+ | |||
</td> | </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 {{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> | ||
<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 {{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> | </td> | ||
{{Top_10_2010:SummaryTableEndTemplate|year=2013}} | {{Top_10_2010:SummaryTableEndTemplate|year=2013}} | ||
Line 26: | Line 33: | ||
{{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=1|year=2013|language=en}} | {{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=1|year=2013|language=en}} | ||
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. | ||
+ | |||
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. | 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 | + | |
+ | 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 | ||
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=1|year=2013|language=en}} | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=1|year=2013|language=en}} | ||
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. Be careful | + | # The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface. Be careful with APIs, such as stored procedures, that are parameterized, but can still introduce 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. [ | + | # 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]] provides many of these [https://static.javadoc.io/org.owasp.esapi/esapi/2.1.0.1/org/owasp/esapi/Encoder.html escaping routines]. |
− | # Positive or “white list” input validation | + | # Positive or “white list” input validation is also recommended, but is not a complete defense as many applications require special characters in their input. If special characters are required, only approaches 1. and 2. above will make their use safe. [[ESAPI | OWASP’s ESAPI]] has an extensible library of [https://static.javadoc.io/org.owasp.esapi/esapi/2.1.0.1/org/owasp/esapi/Validator.html white list input validation routines]. |
+ | |||
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=1|year=2013|language=en}} | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=1|year=2013|language=en}} | ||
− | The application uses untrusted data in the construction of the following vulnerable SQL call: | + | '''Scenario #1:''' The application uses untrusted data in the construction of the following '''vulnerable''' SQL call: |
+ | |||
{{Top_10_2010:ExampleBeginTemplate|year=2013}}<span style="color:red;"> | {{Top_10_2010:ExampleBeginTemplate|year=2013}}<span style="color:red;"> | ||
− | String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") +"'"; | + | String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") + "'"; |
+ | |||
</span>{{Top_10_2010:ExampleEndTemplate}} | </span>{{Top_10_2010:ExampleEndTemplate}} | ||
− | + | '''Scenario #2:''' Similarly, an application’s blind trust in frameworks may result in queries that are still vulnerable, (e.g., Hibernate Query Language (HQL)): | |
+ | {{Top_10_2010:ExampleBeginTemplate|year=2013}}<span style="color:red;"> | ||
+ | Query HQLQuery = session.createQuery(“FROM accounts | ||
+ | WHERE custID='“ + request.getParameter("id") + "'");''' | ||
+ | |||
+ | </span>{{Top_10_2010:ExampleEndTemplate}} | ||
+ | In both cases, the attacker modifies the ‘id’ parameter value in her browser to send: <span style="color:red;">' or '1'='1</span>. For example: | ||
+ | |||
{{Top_10_2010:ExampleBeginTemplate|year=2013}}<span style="color:red;"><nowiki> | {{Top_10_2010:ExampleBeginTemplate|year=2013}}<span style="color:red;"><nowiki> | ||
http://example.com/app/accountView?id=' or '1'='1 | http://example.com/app/accountView?id=' or '1'='1 | ||
</nowiki></span>{{Top_10_2010:ExampleEndTemplate}} | </nowiki></span>{{Top_10_2010:ExampleEndTemplate}} | ||
− | + | This changes the meaning of both queries to return all the records from the accounts table. More dangerous attacks could modify data or even invoke stored procedures. | |
+ | |||
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=1|year=2013|language=en}} | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=1|year=2013|language=en}} | ||
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}} | {{Top_10_2010:SubSubsectionOWASPReferencesTemplate}} | ||
− | * [ | + | * [[SQL_Injection_Prevention_Cheat_Sheet | OWASP SQL Injection Prevention Cheat Sheet]] |
− | * [ | + | * [[Query_Parameterization_Cheat_Sheet | OWASP Query Parameterization Cheat Sheet]] |
− | * [ | + | * [[Command_Injection | OWASP Command Injection Article]] |
− | * [ | + | * [[XXE | OWASP XML eXternal Entity (XXE) Reference Article]] |
− | * [ | + | * [[ASVS | ASVS: Output Encoding/Escaping Requirements (V6)]] |
− | * [ | + | * [[Testing_for_SQL_Injection_(OTG-INPVAL-005) | OWASP Testing Guide: Chapter on SQL Injection Testing]] |
+ | {{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] | ||
Line 58: | Line 79: | ||
|type={{Top_10_2010:StyleTemplate}} | |type={{Top_10_2010:StyleTemplate}} | ||
|usenext=2013NextLink | |usenext=2013NextLink | ||
− | |next={{Top_10_2010:ByTheNumbers | + | |next=A2-{{Top_10_2010:ByTheNumbers |
|2 | |2 | ||
|year=2013 | |year=2013 | ||
|language=en}} | |language=en}} | ||
|useprev=2013PrevLink | |useprev=2013PrevLink | ||
− | |prev= | + | |prev={{Top_10:LanguageFile|text=top10|year=2013|language=en}} |
+ | |year=2013 | ||
+ | |language=en | ||
}} | }} |
Latest revision as of 18:16, 19 March 2017
NOTE: THIS IS NOT THE LATEST VERSION. Please visit the OWASP Top 10 project page to find the latest edition.
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, Xpath, or NoSQL queries; OS commands; XML parsers, SMTP Headers, program arguments, etc. Injection flaws are easy to discover when examining code, but frequently hard to discover via testing. Scanners and fuzzers can help attackers find injection flaws. | 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.
|
Example Attack Scenarios
Scenario #1: The application uses untrusted data in the construction of the following vulnerable SQL call: String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") + "'"; Scenario #2: Similarly, an application’s blind trust in frameworks may result in queries that are still vulnerable, (e.g., Hibernate Query Language (HQL)): Query HQLQuery = session.createQuery(“FROM accounts WHERE custID='“ + request.getParameter("id") + "'"); In both cases, the attacker modifies the ‘id’ parameter value in her browser to send: ' or '1'='1. For example:
http://example.com/app/accountView?id=' or '1'='1
This changes the meaning of both queries to return all the records from the accounts table. More dangerous attacks could modify data or even invoke stored procedures. |
References
OWASP
External |
![CC-by-sa-3 0-88x31.png](/images/6/64/CC-by-sa-3_0-88x31.png)