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-2017 A1-Injection"

From OWASP
Jump to: navigation, search
m (Updated PrevLink and NextLink)
(Prepare OWASP Top 10-2017 Release (Content))
Line 1: Line 1:
 
{{Top_10_2013:TopTemplate
 
{{Top_10_2013:TopTemplate
 +
    |useprev=2017PrevLink
 +
    |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}}
 
     |usenext=2017NextLink
 
     |usenext=2017NextLink
 
     |next=A2-{{Top_10_2010:ByTheNumbers
 
     |next=A2-{{Top_10_2010:ByTheNumbers
              |2
+
        |2
              |year=2017
+
        |year=2017
              |language=en}}
+
        |language=en
     |useprev=2017PrevLink
+
     }}
    |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}}
 
 
     |year=2017
 
     |year=2017
 
     |language=en
 
     |language=en
 
}}
 
}}
 
+
<!--- 2017 Injection --->
 
{{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2017|language=en}}
 
{{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2017|language=en}}
{{Top_10:SummaryTableTemplate|exploitability=1|prevalence=2|detectability=2|impact=1|year=2017|language=en}}
+
{{Top_10-2017:SummaryTableTemplate|exploitability=3 |prevalence=2 |detectability=3 |impact=3 |year=2017|language=en}}
 
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2017}}
 
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2017}}
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2017}}>Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators.
+
    <td colspan=2 {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 
+
<!--- Threat Agent: --->
</td>
+
Almost any source of data can be an injection vector, environment variables, parameters, external and internal web services, and all types of users. <u>[[Injection_Flaws|Injection flaws]]</u> occur when an attacker can send hostile data to an interpreter. </td>
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2017}}>Attackers send 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 colspan=2  {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 
+
<!--- Security Weakness: --->
</td>
+
Injection flaws are very prevalent, particularly in legacy code. Injection vulnerabilities are often found in SQL, LDAP, XPath, or NoSQL queries, OS commands, XML parsers, SMTP headers, expression languages, and ORM queries. Injection flaws are easy to discover when examining code. Scanners and fuzzers can help attackers find injection flaws. </td>
    <td colspan=2  {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2017}}><u>[[Injection_Flaws | Injection flaws]]</u> 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, expression languages, 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 colspan=2  {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 
+
<!--- Impacts: --->
</td>
+
Injection can result in data loss, corruption, or disclosure to unauthorized parties, loss of accountability, or denial of access. Injection can sometimes lead to complete host takeover. The business impact depends on the needs of the application and data.</td>
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate|year=2017}}>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=2017}}>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=2017}}
 
{{Top_10_2010:SummaryTableEndTemplate|year=2017}}
  
{{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=1|year=2017|language=en}}
+
{{Top_10:SubsectionTableBeginTemplate|type=main}}
The best way to find out if an application is vulnerable to injection is to verify that <u>all</u> use of interpreters clearly separates untrusted data from the command or query. In many cases, it is recommended to avoid the interpreter, or disable it (e.g., XXE), if possible. For SQL calls, use bind variables in all prepared statements and stored procedures, or avoid dynamic queries.
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=isTheApplicationVulnerable|position=firstLeft|year=2017|language=en}}
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 use of interpreters and trace data flow through the application. Penetration testers can validate these issues by crafting exploits that confirm the vulnerability.
+
An application is vulnerable to attack when:
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.
+
* User-supplied data is not validated, filtered, or sanitized by the application.
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=1|year=2017|language=en}}
+
* Dynamic queries or non-parameterized calls without context-aware escaping are used directly in the interpreter.
Preventing injection requires keeping untrusted data separate from commands and queries.
+
* Hostile data is used within object-relational mapping (ORM) search parameters to extract additional, sensitive records.
# 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.
+
* Hostile data is directly used or concatenated, such that the SQL or command contains both structure and hostile data in dynamic queries, commands, or stored procedures.
# If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. <u>[[OWASP_Java_Encoder_Project|OWASP’s Java Encoder]]</u> and similar libraries provide such escaping routines.
+
* Some of the more common injections are SQL, NoSQL, OS command, Object Relational Mapping (ORM), LDAP, and Expression Language (EL) or Object Graph Navigation Library (OGNL) injection. The concept is identical among all interpreters. Source code review is the best method of detecting if applications are vulnerable to injections, closely followed by thorough automated testing of all parameters, headers, URL, cookies, JSON, SOAP, and XML data inputs. Organizations can include static source (<u>[[Source_Code_Analysis_Tools|SAST]]</u>) and dynamic application test (<u>[[:Category:Vulnerability_Scanning_Tools|DAST]]</u>) tools into the CI/CD pipeline to identify newly introduced injection flaws prior to production deployment.
# Positive or “white list” input validation is also recommended, but is <u>not</u> a complete defense as many situations require special characters be allowed. If special characters are required, only approaches (1) and (2) above will make their use safe. <u>[[ESAPI|OWASP’s ESAPI]]</u> has an extensible library of <u>[https://static.javadoc.io/org.owasp.esapi/esapi/2.1.0.1/org/owasp/esapi/Validator.html white list input validation routines]</u>.  
 
  
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=1|year=2017|language=en}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howToPrevent|position=right|year=2017|language=en}}
<u>'''Scenario #1:'''</u> An application uses untrusted data in the construction of the following '''vulnerable''' SQL call:
+
Preventing injection requires keeping 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, or migrate to use Object Relational Mapping Tools (ORMs).<br/><b>Note</b>: Even when parameterized, stored procedures can still introduce SQL injection if PL/SQL or T-SQL concatenates queries and data, or executes hostile data with EXECUTE IMMEDIATE or exec().
 +
* Use positive or "whitelist" server-side input validation. This is not a complete defense as many applications require special characters, such as text areas or APIs for mobile applications.
 +
* For any residual dynamic queries, escape special characters using the specific escape syntax for that interpreter.<br/><b>Note</b>: SQL structure such as table names, column names, and so on cannot be escaped, and thus user-supplied structure names are dangerous. This is a common issue in report-writing software.
 +
* Use LIMIT and other SQL controls within queries to prevent mass disclosure of records in case of SQL injection.
  
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=exampleAttackScenarios|position=left|year=2017|language=en}}
 +
<b>Scenario #1</b>: An application uses untrusted data in the construction of the following vulnerable SQL call:
 
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;">
 
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><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></b>{{Top_10_2010:ExampleEndTemplate}}<br/>
</span></b>{{Top_10_2010:ExampleEndTemplate}}
+
<b>Scenario #2</b>: Similarly, an application’s blind trust in frameworks may result in queries that are still vulnerable, (e.g. Hibernate Query Language (HQL)):
 
 
 
 
<u>'''Scenario #2:'''</u> 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=2017}}<b><span style="color:red;">
 
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;">
 
Query HQLQuery = session.createQuery("FROM accounts
 
Query HQLQuery = session.createQuery("FROM accounts
 
WHERE custID='" + request.getParameter("id") + "'");'''
 
WHERE custID='" + request.getParameter("id") + "'");'''
 
 
</span></b>{{Top_10_2010:ExampleEndTemplate}}
 
</span></b>{{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:  
+
In both cases, the attacker modifies the ‘id’ parameter value in their browser to send: ' or '1'='1. For example:
 
 
 
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"><nowiki>
 
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><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></b>{{Top_10_2010:ExampleEndTemplate}}
 
</nowiki></span></b>{{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.
+
This changes the meaning of both queries to return all the records from the accounts table. More dangerous attacks could modify or delete data, or even invoke stored procedures.
  
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=1|year=2017|language=en}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|year=2017|language=en}}
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
+
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate|year=2017|language=en}}
* <u>[[SQL_Injection_Prevention_Cheat_Sheet | OWASP SQL Injection Prevention Cheat Sheet]]</u>
+
* <u>[[OWASP_Proactive_Controls#2:_Parameterize_Queries|OWASP Proactive Controls: Parameterize Queries]]</u>
* <u>[[Query_Parameterization_Cheat_Sheet | OWASP Query Parameterization Cheat Sheet]]</u>
+
* <u>[[ASVS_V5_Input_validation_and_output_encoding|OWASP ASVS: V5 Input Validation and Encoding]]</u>
* <u>[[Command_Injection | OWASP Command Injection Article]]</u>
+
* <u>[[Testing_for_SQL_Injection_(OTG-INPVAL-005)|OWASP Testing Guide: SQL Injection]]</u>, <u>[[Testing_for_Command_Injection_(OTG-INPVAL-013)|Command Injection]]</u>, <u>[[Testing_for_ORM_Injection_(OTG-INPVAL-007)|ORM injection]]</u>
* <u>[[XML_External_Entity_(XXE)_Prevention_Cheat_Sheet| OWASP XXE Prevention Cheat Sheet]]</u>
+
* <u>[[Injection_Prevention_Cheat_Sheet|OWASP Cheat Sheet: Injection Prevention]]</u>
* <u>[[Testing_for_SQL_Injection_(OTG-INPVAL-005)|OWASP Testing Guide: Chapter on SQL Injection Testing]]</u>
+
* <u>[[SQL_Injection_Prevention_Cheat_Sheet|OWASP Cheat Sheet: SQL Injection Prevention]]</u>
 +
* <u>[[Injection_Prevention_Cheat_Sheet_in_Java|OWASP Cheat Sheet: Injection Prevention in Java]]</u>
 +
* <u>[[Query_Parameterization_Cheat_Sheet|OWASP Cheat Sheet: Query Parameterization]]</u>
 +
* <u>[[OWASP_Automated_Threats_to_Web_Applications|OWASP Automated Threats to Web Applications – OAT-014]]</u>
  
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
+
{{Top_10_2010:SubSubsectionExternalReferencesTemplate|year=2017|language=en}}
* <u>[http://cwe.mitre.org/data/definitions/77.html CWE Entry 77 on Command Injection]</u>
+
* <u>[https://cwe.mitre.org/data/definitions/77.html CWE-77: Command Injection]</u>
* <u>[http://cwe.mitre.org/data/definitions/89.html CWE Entry 89 on SQL Injection]</u>
+
* <u>[https://cwe.mitre.org/data/definitions/89.html CWE-89: SQL Injection]</u>
* <u>[http://cwe.mitre.org/data/definitions/564.html CWE Entry 564 on Hibernate Injection]</u>
+
* <u>[https://cwe.mitre.org/data/definitions/564.html CWE-564: Hibernate Injection]</u>
* <u>[http://cwe.mitre.org/data/definitions/611.html CWE Entry 611 on Improper Restriction of XXE]</u>
+
* <u>[https://cwe.mitre.org/data/definitions/917.html CWE-917: Expression Language Injection]</u>
* <u>[http://cwe.mitre.org/data/definitions/917.html|CWE Entry 917 on Expression Language Injection]</u>
+
* <u>[https://portswigger.net/kb/issues/00101080_serversidetemplateinjection PortSwigger: Server-side template injection]</u>
  
 
{{Top_10_2013:BottomAdvancedTemplate
 
{{Top_10_2013:BottomAdvancedTemplate
     |type={{Top_10_2010:StyleTemplate}}
+
     |type=box
 +
    |useprev=2017PrevLink
 +
    |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}}
 
     |usenext=2017NextLink
 
     |usenext=2017NextLink
 
     |next=A2-{{Top_10_2010:ByTheNumbers
 
     |next=A2-{{Top_10_2010:ByTheNumbers
              |2
+
        |2
              |year=2017
+
        |year=2017
              |language=en}}
+
        |language=en
     |useprev=2017PrevLink
+
     }}
    |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}}
 
 
     |year=2017
 
     |year=2017
 
     |language=en
 
     |language=en
 
}}
 
}}
 +
 +
<!-- [[Category:OWASP Top Ten Project]] -->

Revision as of 23:37, 15 December 2017

← Top 10
2017 Table of Contents

PDF version

A2-Broken Authentication →
Threat Agents / Attack Vectors Security Weakness Impacts
App Specific Exploitability: 3
Prevalence: 2
Detectability: 3
Technical: 3
Business ?
Almost any source of data can be an injection vector, environment variables, parameters, external and internal web services, and all types of users. Injection flaws occur when an attacker can send hostile data to an interpreter. Injection flaws are very prevalent, particularly in legacy code. Injection vulnerabilities are often found in SQL, LDAP, XPath, or NoSQL queries, OS commands, XML parsers, SMTP headers, expression languages, and ORM queries. Injection flaws are easy to discover when examining code. Scanners and fuzzers can help attackers find injection flaws. Injection can result in data loss, corruption, or disclosure to unauthorized parties, loss of accountability, or denial of access. Injection can sometimes lead to complete host takeover. The business impact depends on the needs of the application and data.
Is the Application Vulnerable?

An application is vulnerable to attack when:

  • User-supplied data is not validated, filtered, or sanitized by the application.
  • Dynamic queries or non-parameterized calls without context-aware escaping are used directly in the interpreter.
  • Hostile data is used within object-relational mapping (ORM) search parameters to extract additional, sensitive records.
  • Hostile data is directly used or concatenated, such that the SQL or command contains both structure and hostile data in dynamic queries, commands, or stored procedures.
  • Some of the more common injections are SQL, NoSQL, OS command, Object Relational Mapping (ORM), LDAP, and Expression Language (EL) or Object Graph Navigation Library (OGNL) injection. The concept is identical among all interpreters. Source code review is the best method of detecting if applications are vulnerable to injections, closely followed by thorough automated testing of all parameters, headers, URL, cookies, JSON, SOAP, and XML data inputs. Organizations can include static source (SAST) and dynamic application test (DAST) tools into the CI/CD pipeline to identify newly introduced injection flaws prior to production deployment.
How to Prevent

Preventing injection requires keeping 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, or migrate to use Object Relational Mapping Tools (ORMs).
    Note: Even when parameterized, stored procedures can still introduce SQL injection if PL/SQL or T-SQL concatenates queries and data, or executes hostile data with EXECUTE IMMEDIATE or exec().
  • Use positive or "whitelist" server-side input validation. This is not a complete defense as many applications require special characters, such as text areas or APIs for mobile applications.
  • For any residual dynamic queries, escape special characters using the specific escape syntax for that interpreter.
    Note: SQL structure such as table names, column names, and so on cannot be escaped, and thus user-supplied structure names are dangerous. This is a common issue in report-writing software.
  • Use LIMIT and other SQL controls within queries to prevent mass disclosure of records in case of SQL injection.
Example Attack Scenarios

Scenario #1: An 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 their 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 or delete data, or even invoke stored procedures.

References

OWASP

External

← Top 10
2017 Table of Contents

PDF version

A2-Broken Authentication →

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